Skip to main content

Easier Apt

No replies
Joined: 2003-06-20

I think Apt is great, but it is still a tad cumbersome to use (perhaps because it is a new feature).

Rather than generating java code by hand, I'd kind of like to be able to tag methods with @CompileTime. These methods would (optionally) take an argument of AnnotationProcessorEnvironment, and possibly a set of primitive or String args, and would return some kind of Object or primitive. The idea is that they would be evaluated at compile time

If used like this:

class Foo {
@CompileTime final public static
Date COMPILE_TIME = new Date();
@CompileTime final public static
Field[] sourceOrderdFields = initSourceOrderedFields(AnnotationProcessorEnvironment e);

The idea is that the call to new Date() would not happen when COMPILE_TIME was accessed. Instead, it would have the value that was generated and saved during the compilation of the code.

The second example would also be evaluated at compile time, but it would get the annotation processor environment passed to it.

Under the hood this would wind up being some kind of Apt re-write of the class file.