Extending the editor [message #1064359] |
Tue, 18 June 2013 21:00 |
Kevin Regan Messages: 33 Registered: May 2013 |
Member |
|
|
I need to extend the Java Editor in eclipse, via plugin, to syntax highlight a particular pattern and also be capable of taking text that fits this pattern and puts it into a custom view - basically, the java code will have variables in it for example:
public class {{^className^}}
and the view, having two columns, would contain a row:
className MyClass
I want to highlight that pattern in the source code (like a yellow background or something) and build in some integration between the custom view and the editor. Also, I will need to, at compile time, do a replace to put the actual value in palce of the variable in order for the compilation to use the value instead of the variable (while still displaying the variable in the editor).
I have read quite a bit now about markers, annotations and also about damage/repair reconciler type things but I'm not really sure which of these is appropriate for what I'm trying to do. I'm also not really sure how to hook them into the plugin via extension points.
If anyone can give me some starting pointers or point me to some decent documentation on all this (I have been googling quite a bit) I'd appreciate it.
|
|
|
Re: Extending the editor [message #1064410 is a reply to message #1064359] |
Wed, 19 June 2013 06:54 |
|
To start you can extends the Java Editor as follows:
public class MyOwnEditor extends CompilationUnitEditor {
public MyOwnEditor() {
javaTextTools = JavaPlugin.getDefault().getJavaTextTools();
JavaSourceViewerConfiguration sourceViewerConfiguration =
new JavaSourceViewerConfiguration(javaTextTools.getColorManager(),
JavaPlugin.getDefault().getCombinedPreferenceStore(),
this, IJavaPartitions.JAVA_PARTITIONING);
setSourceViewerConfiguration(sourceViewerConfiguration);
}
public void createPartControl(Composite composite) {
super.createPartControl(composite);
/* Put your listeners here like this
getSourceViewer().getTextWidget().addLineBackgroundListener(new LineBackgroundListener() {
public void lineGetBackground(LineBackgroundEvent event) {
}
}
... etc
*/
}
}
To extract class, methods and other you can use a java parser (https://code.google.com/p/javaparser/).
I hope this can help.
|
|
|
Re: Extending the editor [message #1064509 is a reply to message #1064410] |
Wed, 19 June 2013 14:54 |
Kevin Regan Messages: 33 Registered: May 2013 |
Member |
|
|
That example does allow me to create a custom editor that gets the syntax highlighting of the usual java editor - but the auto-indenting doesn't work. I'm worried about this approach because I do not want to have to reinvent the wheel and get the custom editor working like the default java editor. Since the goal is to make some small changes to a java editor for java files - I am hoping to be able to simply hook into the existing default java editor instead of creating my own custom editor via the editors extension point.
It seems like some combination of markers, annotations, or reconciler is where I want to go but my problem is how do I hook into some default java editor evnets in order to create them? Also, recognizing my pattern to highlight it seems to require me adding in a new "scanner" and hooking that scanner to the reconciler.
I want to avoid creating a custom editor since the default java editor has most of what we need I just need to add this bit of functionality to it.
Would greatly appreciate if anybody has any advice - I seem to be stuck at the moment.
[Updated on: Wed, 19 June 2013 20:51] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04308 seconds