Choose between custom language and DOM APIs

Hi,

I recently started developing a plugin for a simple XML-based language I use in some of my projects. For this plugin I need to make a choice between defining a new custom language (along with its filetype, parser definition, etc) and using the DOM API's provided by IntelliJ.
As I'm fairly new to plugin development, I'm not sure what would be the best approach. I'm starting this thread in the hope that someone more experienced can help with this choice.

The custom XML language is used to map custom (String) identifiers to classes in the project. It is a fairly simple language, which looks somewhat like this:

<mappings>
<mapping>
  <name>foo</name>
  <class>com.mypackage.Foo</class>
</mapping>

<mapping>
  <name>bar</name>
  <class>com.intellij.Bar</class>
</mapping>
...
</mappings>


Other xml files might overwrite some of these mappings.
Using an API call (getFromMapping()), I can acquire a reference to a one of the mapped classes (which is instantiated via reflection).

Some of the things I would like to do with my plugin:

  • give the mapping files a custom icon
  • have line markers at getFromMapping() call sites which link to the mapping in the XML file.
  • annotate getFromMapping() call sites if the identifier is not found in the mappings
  • annotate <class/> element in the mappings if the class is not found on the classpath
  • fold getFromMapping() call sites into something like /classname/ where the classname is resolved via the mappings
  • add completion to getFromMapping() call sites


Most of these, I actually have already implemented, using a combination of a custom language and the DOM API's. As I've understood, these two should not be mixed, and this might explain some why I'm getting some strange exceptions like 'refused to parse text with Language: XML'. Therefore I'm wondering if I should go with the DOM API's, or define a custom language.

I'm looking forward to any suggestions.

Thanks,
Guno

8 comments

All of this can be easily accomplished with the DOM APIs.

0

The Dom API can certainly be used for this :)

0

Thanks. I'll go for the DOM API then.

Guno

0

Will I also be able to find usages of foo (see XML fragment above) in Java code (getFromMapping() calls)?
It looks like XmlFindUsagesProvider doesn't allow me to find usages for XmlText elements by default. Should I create my own FindUsagesProvider or somehow extend this class to allow for this?

Thanks,
Guno

0

Thanks. But where should I provide this reference resolving to the Java element?

As far as I can tell, the tutorial only describes how to implement references within an XML file. This is easy, as the elements within my XML all have their corresponding DomElement class, where I can add the annotations I need. However, I have no separate class representing the Java element that refers to my XML elements. Should I create such a class, and reference a resolvingconverter there?

0

Exactly, you'll have to provide your custom ResolvingConverter with PsiReference implementation of corresponding resolve logic (unless you're resolving to a "plain" PsiClass)

0

Please sign in to leave a comment.