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

Chester Chen CChen at ascentmedia.com
Wed Dec 17 12:13:46 EST 2008

Hi, Mahmood, 
    Thanks for the replay. 
    Here is my original problem, I am trying to generate resource bundles (.properties or .xml)   
    for easy of i18n. 

    In normal process, developer writes an exception, and then go to .properties to define the key and message, 
    and put the key to locate the mssage via Resource Bundle. 

    This process is not only error prone, but also cumbersom and not very efficient, may be some smart IDE can help, 
    but it still a slow and tidious process. And it breaks the developers thought flow. Usually developer simply don't do it and type
    the message directly into the Exception.

    I was thinking using annotation to automatically generate these properties files, so Developers doesn't need to
    to go to another properties file to edit. Since the key or error code is anther java variable, the chances of 
    put a wrong string are sigificant less than put an string litteral. 

    I started these experiments last year, first with JDK 5 APT, and pretty soon that I realize that I can't process annoation on local variables. 
    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). 

    In both cases, since APT and JAVAC can't process anything inside method body, I have to put annotations on static fields. 
    This works in some degree. 

    Since there are usually a lot error messages, they stack up pretty long.To make the code readable, I have to refactor them into 
    a separate interface. 

    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. 

    That's why I need local variable annoation processing. 

    With help the .XML format, one can even put other informations into xml (as comment), such java file name, line number, method name 
    so one can easily locate the file by looking at the resource .xml files.

   Since @ErrorMessage annotation is only for file generation, it's @Rentation is only on SOURCE.

   public @interface ErrorMessage {
     //rest of code

   Hope I made this clear. If this is not the right way to do, please advice the correct way. 

   I am also pretty fuzzy about when the Annoation becomes an Visible Element, or an AnnotatedTypeTree. 





-----Original Message-----
From: Mahmood Ali [mailto:mahmood at MIT.EDU]
Sent: Wednesday, December 17, 2008 6:25 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,

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

I don't quite understand what the goal of processing the local  
variable annotations and if this is the right way of doing it.  In the  
provided example, at run-time the MyException handler does not have  
access to the error message.

So that the annotation becomes visible at Element level, the  
annotation needs to be meta-annotated with @Retention(CLASS) or  


More information about the JSR308 mailing list