Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend the Eclipse Java Editor to add coloured overlays

I have an idea for an Eclipse plugin which I've been toying with. I need to be able to extend the Eclipse Java Editor component and add coloured overlays to the code based on pluggable external metrics. Unfortunately there doesn't appear to be any kind of syntax highlighting extension point.

Does anyone know how I might be able to extend the exisitng eclipse Java Editor to add custom highlighting rules?

Bear in mind I'm new to Eclipse plugin programming so please give as much detail as possible.

like image 394
Gavin Clarke Avatar asked Jun 06 '10 18:06

Gavin Clarke


People also ask

How do I import a color theme into Eclipse?

Go to Window | Preferences | General | Appearance | Color Theme. The list of available Eclipse color themes is displayed.

How do I customize colors and Fonts in Eclipse preferences?

More color and font options can be configured by opening the preferences page, accessed from Window | Preferences, and selecting: General | Appearance | Colors and Fonts. General | Editors | Text Editors | Annotation.

What are Eclipse extensions?

Eclipse provides the concept of extensions to contribute functionality to a certain type of API. The type of API is defined by a plug-in via an extension point. Extensions can be contribute by one or more plug-ins. These extensions and extension points are defined via the plugin.


1 Answers

The base class of the Eclipse 3.5 Java editor is org.eclipse.jdt.internal.ui.text.java

Note the "internal" in the class name. That means it's an internal Eclipse class, and not meant to be extended.

There is an Eclipse extension point org.eclipse.ui.editors.markerUpdaters I've not worked with this extension point, but it appears that it might allow you to do what you wish.

Here's the description from Eclipse help:

This extension point is used for registering marker update strategies with marker annotation models. A resource that is opened in a text editor is associated with a marker annotation model. For each marker attached to the resource this model manages a position that is updated with each change applied to the text in the editor. If the resource is saved, the text in the editor and the position managed for a marker are passed over to the registered marker update strategies. These strategies can then update the marker's attributes based on the text and the position. Marker update strategies are requested to implement the interface org.eclipse.ui.texteditor.IMarkerUpdater. The update strategies can be registered either for a particular marker type or all marker types. The latter by omitting any marker type in the extension.

Here's an example from the Eclipse help:

<extension point= "org.eclipse.ui.editors.markerUpdaters"> 
    <updater 
        id="org.eclipse.jdt.ui.markerUpdaters.JavaSearchMarkerUpdater" 
        class="org.eclipse.jdt.internal.ui.search.JavaSearchMarkerUpdater" 
        markerType="org.eclipse.search.searchmarker"> 
    </updater> 
</extension> 

I couldn't find more of an explanation on the Internet.

like image 114
Gilbert Le Blanc Avatar answered Oct 06 '22 10:10

Gilbert Le Blanc