How to write an XML plugin for mavenized Android projects?


I have got two android modules in a project. One is responsible for ui and functions and the other one contains styles and theme. These are connected via attributes and the theme project is marked as a dependency in pom.xml in the function project. For example:



Excerpt from android_layout.xml


Excerpt from attrs.xml

<attr name="customStyle" format="reference" />

Excerpt from theme.xml

<item name="customStyle">@style/DefaultCustomStyle</item>

Excerpt from styles.xml

<style name="DefaultCustomStyle">
   <item name="android:background">@color/epic_color</item>

So it is a complex architecture but the theme can be swapped easily that way. It is not easy when you have thousand of references and you have to make sure that you have an attribute, an item and a style element to use a custom style in a layout. I would like to make a plugin which makes editing styles easier. This plugin should know these feautres: edits these lines at the same time or generates them somehow, notifies the developer if elements of these reference chain are missing, extends Idea's find usage function for being possible to get references to these elements.

I did some of the tutorials at JetBrains website but it is still not clear for me how to begin to write a plugin like these. Should I make custom PsiElements or can I use Xml specific Psi classes somehow?

Thanks for help!

1 comment
Comment actions Permalink

I'd strongly suggest to use DOM API to work on a higher-level abstraction than "plain" PSI.


Please sign in to leave a comment.