CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES 199
CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES 199 Beyond the annotations, all the processor does is loop through each annotation and print its name and nesting kind (level of declaration). More typically, if the annotation was something to be processed, you would use the accept() method on the TypeElement and visit it. Listing 10-7. Java SE 6.0 Annotation Processor import javax.annotation.processing.*; import javax.lang.model.*; import javax.lang.model.element.*; import java.util.*; // Source version @SupportedSourceVersion(SourceVersion.RELEASE_6) // Process all annotations @SupportedAnnotationTypes(”*”) // No options support // Empty set when not annotated with @SupportedOptions public class Dump6Processor extends AbstractProcessor { public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!roundEnv.processingOver()) { for (TypeElement element : annotations) { System.out.println(element.getQualifiedName() + “(” + element.getNestingKind() + “)”); } } return false; // No annotations claimed } } Again, compilation requires the tools.jar file, as follows: javac -cp c:jdk1.6.0libtools.jar Dump6Processor.java
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services