DomElementsAnnotator vs Annotator

Answered

My plugin is for our special XML configuration, so my first try is to implement the DomElementsAnnotator and register it inside my DomFileDescription's createAnnotator(). It basically works but again we have run order problem, when user opens the XML file, our error annotation shows up in short time then get overridden by other annotators, which turn the validation to green...

I try to debug and found out that inside the DefaultHighlightVisitor.runAnnotators() my Annotator is not registered, it's actually triggered by the DefaultDomAnnotator. 

I think I should use the standard Annotator and register it in plugin.xml directly. But in general, when should we use DomElementsAnnotator and when should not?

Thanks.

0
3 comments
Avatar
Permanently deleted user

Some more details about the issue:

To test i changed my Annotator like this:

    @Override
public void annotate(DomElement element, DomElementAnnotationHolder holder) {
holder.createProblem(element, HighlightSeverity.ERROR, "BAD");
}

So it makes all DomElements as error. When I open new XML file, it works fine. But if I keep the XML file open and close IDEA and reopen IDEA so the file is open by default, the annotations show up at beginning then they all gone, even I close the file and reopen it, it still no error annotations, I have to change the file content to see them again.

I tried with different XML files, the XML content has no influence, only the file which is opened and get focus when IDEA starts, has this issue.

Btw, the default XSD annotation doesn't have this issue. So it's a problem only for my annotator...

0

DomElementAnnotator name is a bit misleading: it can now be run either from some default annotator, or from a special inspection (extending BasicDomElementsInspection). Do you have such inspection for your DOM files? If not, then DefaultDomAnnotator should kick in. It's hard to tell what's happening with your highlighting, but you could try debugging it by setting breakpoints in the described places.

0
Avatar
Permanently deleted user

Hi Peter,

Thank you for your answer!

I solved the problem by creating my own annotator which extends from Annotator directly and register it in plugin.xml.

I copied some code from DefaultDomAnnotator in order to convert PsiElement to DomElement, then I can do my check almost as same as in DomElementAnnotator.

I still don't know the reason of above issue, but I think the new solution is more clear, so I will move on.

Thanks!

0

Please sign in to leave a comment.