How do I write a Java inner class with custom properties at compile time using annotations?
For instance, I want this :
@Generate
class Person {
String firstname, lastname;
}
to generate:
class Person {
String firstname, lastname;
public static class $Fields {
public static String firstname = "firstname";
public static String lastname = "lastname";
}
}
How can I write the interface:
@Retention(RetentionPolicy.SOURCE)
public @interface Generate {
// ...
}
I understand I need to do some kind of AST transformation to make this magical.
I am also aware of project lombok, but I want to know what the least common denominator is with a simple example, preferably within one method, and preferably something that a good editor would consider automatically, for instance RetentionPolicy.SOURCE for the javac compiler, which can be used in Intellij IDEA.
Project lombok is a beast code wise and is tough place to start.
It must be simpler than that, is it not?
Any ideas?
javax.annotation.processing
package.javassist