4

I am an eclipse newbie. I have a long term goal which is to add my own annotations to the java editor: a bit like FindBugs. I want my own static code analysers, and to be able to add markers/annotations to resources.

So I have read a lot of excellent documentation, and undertaken a load of tutorials. The most helpful was probably http://www.ibm.com/developerworks/opensource/tutorials/os-ecl-commplgin2/section9.html. A lot of the Lars Vogel documents have been useful too. I can now make TextEditors with syntax highlighters. I am however struggling with the best approach for adding annotations.

I understand roughly how to do this: the text editor has a DocumentProvider. The DocumentProvider has an AnnotationModel. It is possible to add annotations to the annotation model.

My question is "where do I put this code" specifically the code that scans the text in the editor and updates the annotation model. It seems clear that this should be in response to a listener...but which one?

I have tried a ResourceChangeListener. This seems to only fire on a save option, rather than when text is typed. In addition I don't know how to get the editor from the resource. ("The" editor is probably a misnomer as presumably the resource can be open in multiple editors). I can find the current editor via IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor(), but this seems the wrong approach, as I want to update all relevant annotation models.

I have tried adding an ElementStateListener to the text editor. None of the events seem to be the one I want.

I've looked at DamageRepairers...these seem to nearly be what I want, except that long term I want to tie into the JavaEditor, so I don't want to change the default DamageRepair.

Thanks for all the help

Stave Escura
  • 2,058
  • 1
  • 19
  • 24
  • that's a very specific question, and I guess your chances of getting a good answer are better if you open a thread in the corresponding eclipse forum: [Link](http://www.eclipse.org/forums/index.php/). I would try `Eclipse Projects` -> `Rich Client Platform`, but perhaps you find a better suiting subforum. People there helped me a lot when I created a custom editor... – moeTi Mar 15 '13 at 15:12
  • I opened a question at http://www.eclipse.org/forums/index.php/t/459621/ – Stave Escura Mar 21 '13 at 11:02

1 Answers1

0

I found that this question can be answered, by mentioning the following resource: www.ibm.com/developerworks/opensource/tutorials/os-eclipse-plugin-guide/index.html

The question author also mentions here:

I add the annotations to the resource, and the annotations are auto-magically added to the editor.

So when my plugin starts I run through the active resources, add annotations to them if needed, then add a resource changed listener which adds them as the resource is opened.

Blaise
  • 7,230
  • 6
  • 43
  • 53