Proposal for plugin to help with device specific code (e.g for J2ME) - preprocessor like


We are doing J2ME development that includes quite a bit of device specific
code. The way we handle this currently is by using Velocity macros to
substitute the appropriate Java source during an intermediate Ant build
step. Obviously, having Velocity code in the source makes working in Idea
with the marked up files quite painful since they can no longer be parsed as
valid Java. You can no longer navigate the source, do usage searches, etc. -
this file, and any others that depend on it are pretty much useless.

Since I can't think of another solution to handling the device specific code
(outside of having a lot of code duplication), I was thinking that I might
be able to write a plugin to help out. What I had in mind is to have the
plugin step in just before the point where the source is parsed, do the
Velocity substitution and present the substituted code to Idea to create its
internal model. In the reverse direction, once Idea has created any feedback
for the source (highlights, error markings, etc), I'd like to intercept this
and apply it to the marked up source (at least for the part presented to
Idea), avoiding the Velocity keywords in the process. Basically, any time
Idea wants to access the source it should do this through the plugin which
would maintain a mapping between the actual source and what Idea works with.

I would also like to have two views of the source available - one with the
substituted source and one showing the Velocity markup. I'm hoping that by
being able to place the plugin in the middle like this, I'll be able to have
my cake and eat it too.

Note that the intent (at least initially) of this plugin wouldn't be to have
a Velocity (or other similar language) processor for Idea that would do
syntax coloring, auto-completion for the template language or other nice
things. Rather, it would just try to make the markup invisible to Idea so
that the file would look like regular Java source.

Would anyone (Jetbrains, the PsiViewer guys?) have any idea if something
like this would be possible?

TIA to anyone that has any suggestions or advice words of encouragement,


Please sign in to leave a comment.