[JSR308] Simple question regarding jsr308 compiler for localvariable annotation processing

Chester Chen CChen at ascentmedia.com
Wed Dec 17 03:44:01 EST 2008

Ok, after reading the checker framework and browse the archive emails, 
I think I figure out how to do this. 

I should extends the TreeScaner instead of ElementScanner6. TreeScanner 
will allow me to visit Local Variables, and then I can get the annotation
from the AST Tree node (somehow, I still need to figure this part out). 


-----Original Message-----
From: jsr308-bounces at lists.csail.mit.edu
[mailto:jsr308-bounces at lists.csail.mit.edu]On Behalf Of Chester Chen
Sent: Tuesday, December 16, 2008 4:25 PM
To: jsr308 at lists.csail.mit.edu
Subject: [JSR308] Simple question regarding jsr308 compiler for
localvariable annotation processing

   I am interested in using JSR308 compiler to processing my local variable annotations. 
   for example, 

   public void myMethod() {
     String myValue = null;

     if (!testCondition(myTest))  {
         @ErrorMessage(messageFormat="this is annoation on local variable, value = {0} ";
         String errorCode = "EC_101";
         throw new MyException(errorCode, myValue);

   It looks like JSR308 (later Java 7) will be able to do this. With JSR308 compiler, after the installation (replacing tools.jar will toos-jsr308.jar) in JDK 1.6.x; Would I be able to pick local variable annotation ?

   For example overwrite the ElementScanner6 class method

     * {@inheritDoc} This implementation scans the enclosed elements.
     * @param e  the element to visit
     * @param p  a visitor-specified parameter
     * @return the result of scanning
    public R visitVariable(VariableElement e, P p) {
	//print annotation here 

Please advise. 




JSR308 mailing list
JSR308 at lists.csail.mit.edu

More information about the JSR308 mailing list