CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES 199
200 CHAPTER 10 PLUGGABLE ANNOTATION PROCESSING UPDATES Now compile this with the -processor option to javac: > javac -processor Dump6Processor Dump6Processor.java javax.annotation.processing.SupportedSourceVersion(TOP_LEVEL) javax.annotation.processing.SupportedAnnotationTypes(TOP_LEVEL) warning: No annotation processors claimed present annotation types: [javax.annotation.processing.SupportedSourceVersion, javax.annotation.processing.SupportedAnnotationTypes] Note The javac command-line tool is getting more like java in Java SE 6.0 through the addition of command-line options. In fact, some are even nonstandard. Try out the -Xprint option with javac to get information similar to what you get from javap and -XprintRounds or -XprintProcessorInfo to monitor processing tasks. Options like -Xmaxerrs and -Xmaxwarns (which limit the maximum number of errors and warnings, respectively) are not new to Java SE 6.0. The processingOver() check in process() is necessary, as a processor could be called multiple times in one javac execution. More typically, a processor would actually do something with the annotation, such as generate a file. As far as generating the file, the old AnnotationProcessorEnvironment interface of the com.sun.mirror.apt package is now the new ProcessingEnvironment interface of the javax.annotation.processing package. In both cases, you get a Filer to hold the generated output. Writer out = env.getFiler().createTextFile( Filer.Location.SOURCE_TREE, package, path, charset) Summary Most people aren t going to create their own annotation processors. They re more apt to use annotations created by others, like for JDBC queries. If you only use them, you don t need to know anything in this chapter. If you need to process annotations, however, you need to know how the processing model has changed from J2SE 5.0 to Java SE 6.0. It s not that different just slightly with classes moving between packages and slightly different interfaces. Use them with care, and don t go overboard. Defining your own annotations really has not changed from J2SE 5.0. Appendix A wraps up the book with information about acquiring the weekly releases.
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services