Custom DomElementsAnnotator isn't invoked

Hi,

I'm having some trouble with a DomElementsAnnotator I wrote to support a custom XML language. The problem is that this annotator never seems to be invoked:

public class MyDomAnnotator implements DomElementsAnnotator {
     @Override
     public void annotate(DomElement domElement, DomElementAnnotationHolder domElementProblemDescriptors) {
               ...
        }
}


The annotator is declared in the DomFileDescription class:

public class MyDOMFileDescription extends DomFileDescription<TopLevelDomElement> {
     public MyDOMFileDescription() {
          super(TopLevelDomElement.class, "topLevelXMLTag");
     }

     @Nullable
     @Override
     public DomElementsAnnotator createAnnotator() {
          return new MyDomAnnotator();
     }
}


I set a breakpoint in the createAnnotator() method, but it is never hit.
The DomFileDescription is declared in plugin.xml:

  <extensions defaultExtensionNs="com.intellij">
      <fileTypeFactory implementation="MyFileTypeFactory" />
      <lang.parserDefinition language="MyLanguage" implementationClass="MyParserDefinition"/>
      <lang.syntaxHighlighterFactory key="MyLanguage" implementationClass="MyXmlSyntaxHighlighterFactory"/>
      <dom.fileDescription implementation="MyDOMFileDescription"/>
  </extensions>


As soon as I change my parserDefinition to com.intellij.lang.xml.XMLParserDefinition, the annotator does get invoked. However, now I run into other problems (exceptions like 'refused to parse text with Language: XML'), which is why I wrote the ParserDefinition in the first place:

public class MyParserDefinition extends XMLParserDefinition {

     public IFileElementType getFileNodeType() {
          return MyTypes.FILE;
     }

     public PsiFile createFile(FileViewProvider viewProvider) {
          return new MyXmlFileImpl(viewProvider);
     }

}


I think the reason why the annotator isn't invoked could be that the FileType returned by getFileNodeType() at some point doesn't match the filetype of the xml files of my custom language. Probably I need to implement some more interfaces for this to work, but I'm not sure which one(s).
Tried debugging the IntelliJ code to see why the annotator was called with the regular XMLParserDefinition but to no avail.

Perhaps somebody here can point me in the right direction?

Thanks,
Guno

4 comments

The DOM is intended to work only with standard XML files. You have to choose: either you use a custom language with its own file type, parser definition etc. or you use the DOM APIs.

0

I see. Thanks.

And if I were to go for the DOM APIs, would I be able to implement 'custom language like' features (such as are discussed here)?
If not, then the choice is an easy one ;-)


Guno

0

If you share your exact use case with us, we could help decide on the best plan of action for your plugin :)

Also, the Dom API is extremely powerful, you can check out the documentation here http://confluence.jetbrains.com/display/IDEADEV/Accessing+XML+through+IntelliJ+IDEA+DOM

Alan

0

Thanks. I've created a new thread for this: http://devnet.jetbrains.com/thread/447550

I'll mark this thread as answered.

0

Please sign in to leave a comment.