[JSR308] Simple question regarding jsr308 compiler forlocalvariable annotation processing

Chester Chen CChen at ascentmedia.com
Wed Dec 17 15:01:35 EST 2008


>>  Actually, so far I only check on Annoation Declaration, but this can expand later.
should be 

Actually, so far I only check ONE Annoation Declaration, but that can be expanded later.


-----Original Message-----
From: jsr308-bounces at lists.csail.mit.edu
[mailto:jsr308-bounces at lists.csail.mit.edu]On Behalf Of Chester Chen
Sent: Wednesday, December 17, 2008 12:00 PM
To: Mahmood Ali
Cc: jsr308 at lists.csail.mit.edu
Subject: Re: [JSR308] Simple question regarding jsr308 compiler
forlocalvariable annotation processing


Hi, Mahmood, 

   Thanks for the prototype Code, that's exactly what I need. 

>>I assume that your checker will check that ErrorMessage string is  
>>consistent across multiple declarations.

  Actually, so far I only check on Annoation Declaration, but this can expand later. 

>>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.

  Here what I mean "no improvement" simply states that I still couldn't process 
  local variables with Javac. 

  At one point, I was going to use LAPT-JAVAC  compiler, but it only works for JDK5 and I already 
  switch to JDK 6 compiler already.


>>1. To be able to process local variables, then the processor  
>>SupportedAnnotationTypes should be set to "*".
   I did that already when I switched to JDK 6 Javac . 

>>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.

   That's what I learnt too.
>>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  
>>SourceChecker).

  Here is what I am bit fuzzy about. 

 But I was studing Checker Framework and now your prototype code, I should getting clear. 

 Thanks a lot. 

 Hay, may be you and Mike (or may be togeter with others) can write a book about JSR 308/Java 7 Annotation Processing, a short one, like  those
 developer note book series by O'reily. That would help a lot more developers. 

Regards,

Chester Chen



  
 


-----Original Message-----
From: Mahmood Ali [mailto:mahmood at MIT.EDU]
Sent: Wednesday, December 17, 2008 11:14 AM
To: Chester Chen
Cc: jsr308 at lists.csail.mit.edu
Subject: Re: [JSR308] Simple question regarding jsr308 compiler for
localvariable annotation processing


Greetings Chester,

Thank you very much for your clarification.  I have a greater  
appreciation to what the project and how you should address the issue  
now.

> 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  
SourceChecker).
    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.

Regards,
Mahmood



_______________________________________________
JSR308 mailing list
JSR308 at lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/jsr308




More information about the JSR308 mailing list