The Artima Developer Community
Sponsored Link

Java Buzz Forum
JAM -- single layer for processing JSR175 and XDoclet annotations.

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adam Kruszewski

Posts: 90
Nickname: phantomik
Registered: Jan, 2005

Adam Kruszewski is (mostly) Java developer and linux system administrator.
JAM -- single layer for processing JSR175 and XDoclet annotations. Posted: Jan 1, 2005 9:34 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Adam Kruszewski.
Original Post: JAM -- single layer for processing JSR175 and XDoclet annotations.
Feed Title: Adam Kruszewski :: WebLog();
Feed URL: http://adam.kruszewski.name/blojsom/blog/adam.kruszewski/?flavor=rss2
Feed Description: Thoughts about linux, open source, programming, ...
Latest Java Buzz Posts
Latest Java Buzz Posts by Adam Kruszewski
Latest Posts From Adam Kruszewski :: WebLog();

Advertisement
For a while I was playing with J2SE5.0 APT tool (Brian Oxley have written how to create annotation processor for APT) -- this tool mimics behaviour of javac adding additional annotation processing abilities. I was wondering how could I run it to allow multiple passes of different annotation processors (with few ant tasks launched sequentially or something like that), but in mean time I have found JAM. It is Annogen component and it abstracts JSR175 and XDoclet annotations and provide single layer for processing them in a easy way:


 
public static void main (String[] args ) throws IOException {

   
JamServiceFactory factory = JamServiceFactory.getInstance ();
    JamServiceParams params = factory.createServiceParams
();

   
// search in source files.
   
params.includeSourcePattern (new File[] { new File (
       
"src/sandbox/jam/test/" ) }, "*.java" );

    JamService service = factory.createService
(params );

    JamClassIterator jClassIter = service.getClasses
();
   
while (jClassIter.hasNext ()) {
     
JClass elem = (JClass ) jClassIter.next ();
      System.out.println
("Class name:" + elem.getSimpleName ());
      JAnnotation
[] annotations = elem.getAnnotations ();
      dumpAnnotations
(annotations );

     
for (JField field : elem.getFields ()) {
       
System.out.println (" f> " + field.getSimpleName () + ":"
           
+ field.getType ().getSimpleName ());
        annotations = field.getAnnotations
();
        dumpAnnotations
(annotations );
     
}

     
for (JMethod method : elem.getMethods ()) {
       
System.out.println (" m> " + method.getSimpleName ());
        annotations = method.getAnnotations
();
        dumpAnnotations
(annotations );
     
}
    }
  }

 
private static void dumpAnnotations (JAnnotation[] annotations ) {
   
for (JAnnotation ann : annotations ) {
     
System.out.println ("    a> " + ann.getSimpleName ());
     
for (JAnnotationValue annVal : ann.getValues ()) {
       
System.out.println ("       v> " + annVal.getName () + ":"
           
+ annVal.asString ());
     
}
    }
  }

I'll stick with JAM for a while ;) Maybe it is not a complete tool like APT but I think it gives more power and is XDoclet annotations 'backward-compatible'.

Above code with simple annotated class can be downloaded here as Eclipse compressed project (just import it into workspace; Eclipse 3.1M4 is required and you'll need to fix path for tools.jar pointing to your JDK's copy).

update:
  • 01-jan: colorized source code with java2html.

Read: JAM -- single layer for processing JSR175 and XDoclet annotations.

Topic: Watch out for permissions in Fedora Core 3 with Subversion behind Apache Previous Topic   Next Topic Topic: Guido's Beard

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use