Custom DomElementsAnnotator isn't invoked


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 {
     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");

     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"/>

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?



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.


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 ;-)



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



Thanks. I've created a new thread for this:

I'll mark this thread as answered.


Please sign in to leave a comment.