How to write an XML plugin for mavenized Android projects?

Hello!

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:

FunctionProject
`--res
   `--layout
      `--android_layout.xml
   `--values
      `--attrs.xml

ThemeProject
`--res
   `--values
      `--styles.xml
      `--theme.xml

Excerpt from android_layout.xml

<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   
   android:orientation="vertical">


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


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. http://www.jetbrains.org/intellij/sdk/docs/reference_guide/frameworks_and_external_apis/xml_dom_api.html


0

Please sign in to leave a comment.