196 CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES
198 CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES > apt -cp c:jdk1.6.0libtools.jar;. -factory DumpFactory DumpFactory.java DumpFactory supportedAnnotationTypes supportedOptions getProcessorFor DumpFactory.DumpProcessor process DumpFactory.DumpProcessor.DumpVisitor visitMethodDeclaration visitClassDeclaration visitInterfaceDeclaration Those are the basics of processing annotations with JDK 5.0. Java SE 6.0 Processing Moving to the Java SE 6.0 world changes a few things. The primary difference is the moving of the annotation processing library into a more standard javax package and doing away with the factory. Secondly, the javac command-line tool now offers a -processor option to run a previously created processor. The removal of the factory is actually an interesting twist and makes total sense. All the factory did was return a single processor. So now the AbstractProcessor class forms the basis of all processors and really just is the processor unlike with 5.0, in which you had to create an extra class. Ignoring the imports and a few other things, your basic processor definition is shown here: public class Dump6Processor extends AbstractProcessor { public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) { return false; // No annotations claimed } } To demonstrate, Listing 10-7 creates a processor that lists the annotations in the classes specified. This is where new the annotations of the javax.annotation.processing package are used: SupportedSourceVersion, SupportedAnnotationTypes, and SupportedOptions. The source version is specified by one of the constants of the SourceVersion enumeration of the java.lang.model package. The SupportedAnnotationTypes annotation is just like the supportedAnnotationTypes() method of the JDK 5.0 processor factory, and the SupportedOptions annotation mirrors supportedOptions(). When not specified, it defaults to returning an empty set.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services