[JSR308] Simple question regarding jsr308 compiler for localvariable annotation processing
mahmood at MIT.EDU
Wed Dec 17 14:14:11 EST 2008
Thank you very much for your clarification. I have a greater
appreciation to what the project and how you should address the issue
> I have to put annotations on static fields. [...]
> Even though I gaim some type-safty, but developer still has to go to
> another file to edit the error message.
> I was hoping to be able put the error message annotation right at
> where developer wants to throw exception.
I assume that your checker will check that ErrorMessage string is
consistent across multiple declarations.
> Then earlier this year, I switched to JDK 6 using Javac, hoping I
> could get lucky with JDK 6. Beside I have to change to the new
> syntax and classes with JDK 6 javac, I did not get any improvement
> (except I have to develop a custome Ant task to expand Apache Ant
> Javac in order to process annotation).
Umm... this is odd. Java Annotation processing (for all versions,
including java 7) deals with local variables differently than fields,
methods. However, it should still be possible.
The two main differences are the following:
1. To be able to process local variables, then the processor
SupportedAnnotationTypes should be set to "*".
The processor checks for presence of supported annotation types
only in fields/methods/type declarations and not local variables, and
if it doesn't find it the processor wouldn't process the source file.
2. During the annotation processing phase, fields/methods/type-
declarations are type checked and you can access their type
information but not for method bodies.
The proper solution to write the processor wouldn't dependance on
type information or by invoking a phase of attribution (i.e. type-
checking the source file) within Processor.process (like in
Side-effect: If the ErrorMessage value is a reference to a compile-
time constant string (e.g. File.pathSeperator), the processor would
not know its value.
I made a buggy and limited prototype available in http://people.csail.mit.edu/mali/ErrorMsgAggregate.zip
. The prototype works in java 6 but requires tools.jar.
Hope that helps.
More information about the JSR308