In an eclipse plugin: How can I programmatically highlight lines of codes in the java editor?

给你一囗甜甜゛ 提交于 2019-12-24 07:59:17

问题


I am trying to develop an eclipse plugin that does some documentation check on java code and highlights some lines of code in the editor.

To achieve my goal, I DON'T want to create a new editor in eclipse, I simply want to extend the default java editor to draw a line under (or highlight) the methods that do not satisfy some set of predetermined requirements.

Do I need to create a PresentationReconciler? If yes, how do I make the JDT or workbench use my reconciler.

I have never done plugin development and this is my first attempt.


回答1:


Several starting points for you:

  • Annotations are an UI feature of JFace's text editor that allows you to visually mark some places in an open editor.

  • Markers are a Workbench feature, more high-level. They are generic "objects that may be associated with Workbench resources", and they can display in several places: in text editors (as annotations) or in the Problems view, for example.

Depending on what you want to do, you would plug in your plug-in into extension points related to either of those.




回答2:


The Eclipse Java editor is located in the org.eclipse.jdt.internal.ui.javaeditor.JavaEditor package.

The "internal" in the package name means that the Eclipse development team can change how the Java editor works with new revisions.




回答3:


Try this help page: Juno Help on syntax highlighting

At the end of the page, it describes how to dynamically add a PresentationReconciler, which is used for syntax highlighting. See if that fits the problem that you want to solve.




回答4:


I assume you already have a plugin project.

In your plugin.xml, open the tab Extensions, click Add..., search for org.eclipse.ui.editors, then you should see a template named Editor, which will produce a simple xml editor to experiment and play with. Also, you will be able to see the needed structure to define a custom editor.

Hope this helps...




回答5:


I don't know if you still have a need for this, but you are going to want to use Annotations to keep track of what parts of the editor you need to highlight.

For actually doing the graphical effect of highlighting, you could do syntax highlighting via a PresentationReconciler, but I have no experience with that.

We used a technique we borrowed from http://editbox.sourceforge.net/, replacing the background image of the editor Shell. Its open source, so check it out. (Our code might also help -- its at https://github.com/IDE4edu/EclipseEditorOverlay )



来源:https://stackoverflow.com/questions/13802131/in-an-eclipse-plugin-how-can-i-programmatically-highlight-lines-of-codes-in-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!