I'm doing a project which in essence is a way for a user to create macros for very long/repetitive code so they can then put these macros into a their code to increase readability and encourage re-usability.
The project is split up into two areas: an RCP application where the user constructs their macros and saves them to file, and a plugin-in in eclipse where a user can insert a macro.
The RCP application has come along nicely, but now I'm getting to the real bit where I want java to look at a piece of code and at compile time go 'Oh, that piece of code means this'.
For example a user could have created a macro with an identifier macro1
that represents the code System.out.println("Hello World");
. They want to use it in their class foo
which will look like:
class foo{
//lots of java....
macro1
//lots more java
}
I want the user to run their class, and when Java compiles it replace macro1
with it's value.
I have been looking into this for a while and read up a little bit on JavaCC and looked into Ants Replace Task but I feel I want to go down the road of creating a custom annotation to inform Java that this string below the annotation should be transformed into/replaced by a piece of java code located in a specific text file. Hopefully ending up with something like:
@ExpandMacro
macro1
To me it seems like it could be possible but I don't know if I'm just being too optimistic! :)
Also one of my concerns is how deployable would it be as a plugin? If I create a custom annotation how would I make it available to the user to use?
Any advice/insights would be very helpful!
Edit: I have also looked into Project Lombok which is looks extremely insteresting. But again I'm concerned about deployability because of the amount of setup required for a lombok project.