Custom implementation of Editor/EditorEx

Hi! Heh,Since I am doing my own special syntax highlighting and error annotations for ANTLR related stuff, I figured it would be very convenient to come up with my own subclass of Editor, but of course it's an interface as it should be.  I'm using delegation to Editor(Ex) so that my object looks exactly like an editor but can have extra methods that I need for my special annotation and so on.

/** An impl of Editor that delegates to a wrapped EditorEx so we

*  can add methods w/o having to force Intellij to create a

*  new kind of EditorEx (it uses EditorImpl).


public class SyntaxAwareEditor implements EditorEx {

        public static final int TOKEN_INFO_LAYER = HighlighterLayer.SELECTION; // Show token info over errors

        public static final int ERROR_LAYER = HighlighterLayer.ERROR;

        private EditorEx editor;

        public SyntaxAwareEditor(EditorEx editor) {

                this.editor = editor;



     about 50 methods.


I recognize that it is an interface and therefore likely to be used by plug-ins, but I'm a bit nervous about the number of methods I have to implement for delegation. Naturally, intellij was able to implement all of these methods for me using a nice combination of implement interface methods and replace inheritance with delegation re-factoring (woot!).  You think this is just asking for trouble with future versions?

I am also very nervous about casting from the factory:

 final EditorEx editor = (EditorEx) factory.createEditor(doc, project);

Is there a factory the returns extended editor interfaces? Implementation seems always to be EditorEx.


Comment actions Permalink

Crap. I just saw this cast to EditorImpl in EditorFactoryImpl:

  public void releaseEditor(@NotNull Editor editor) {
    try {

My impl of EditorEx clearly won't work. Extending EditorImpl only to delegate to another Editor makes no sense.

Any ideas how to add methods to an object created by a factory that hides but relies on a specific implementation?

Comment actions Permalink


Editor interface isn't supposed to be implemented by plugins. To implement custom syntax and error highlighting use 'annotator' and 'localInspection'

Nikolay Chashnikov
"Develop with pleasure!"

Comment actions Permalink

Hi. Thanks Nikolay. I'm the ANTLR guy so I prefer to use ANTLR parsing stuff and it was trivial to get my own version of highlighting etc... using intellij's awesome infrastructure.  I was just wondering if I could wrap an Editor to create my own complex widgets.  Looks like the answer is no ;)


Please sign in to leave a comment.