EclipseCon 2007 March 5-8, Santa Clara California

(3618) Writing a Java Annotation Processor for Eclipse

Walter Harley (BEA Systems Inc.), Jess Garms (BEA Systems), Gary Horen (BEA)

· Short Tutorial

Monday, 08:00, 2 hours | Room 207


Jess Garms

A Java annotation processor is a compiler plug-in that can read source code as it is being compiled, generate additional Java types or other resource files, and post warnings and errors. With annotation processors, programming problems that might otherwise require convoluted class hierarchies, code preprocessing with scripts, or other techniques that make for unreadable and undebuggable code may be solved with clean, simple syntax that is now a standard part of the Java language. Wrapper and proxy classes can be generated automatically. Semantic inspections such as checking value ranges can be done at compile time rather than at runtime. Annotation processing was introduced in Eclipse 3.2 and has been substantially enhanced in Eclipse 3.3.

However, writing an annotation processor is not easy. Both the com.sun.mirror.apt API supported in Eclipse 3.2, and the new JSR-269 API introduced in Java 6 and Eclipse 3.3, are broad, complex interfaces requiring a sophisticated understanding of how the compiler views and processes Java types. It's easy to call the wrong method and get something that's almost, but not quite, what you need. Furthermore, to provide a good experience for an Eclipse user editing annotated code, you need to consider some IDE-specific matters in your processor design.

Join the team that wrote the Eclipse annotation processing infrastructure for this in-depth tutorial on how to write an efficient annotation processor. Using examples that highlight the real-world issues we've encountered over two years of supporting and writing processors, we'll lead you through:

To get the most out of this tutorial, you'll need to know how to write Java code, and it will help if you're familiar with Java 5 generics and annotations. You'll leave with an understanding of what problems annotation processors can and cannot solve, and concrete techniques and examples for writing and deploying your own annotation processors to run efficiently in Eclipse.

Walter Harley is a senior software engineer on the BEA Weblogic Workshop Compiler Team, and a committer on the Eclipse APT project. Prior to this, he worked on XML data integration, cryptography, and old-timey things like mainframe terminal emulation and macro assemblers.

Jess Garms is the Eclipse development lead at BEA Systems. Prior to that, he worked on BEA's Java IDE, WebLogic Workshop. Additionally, he has worked extensively with cryptography, and co-authored "Professional Java Security", published by Wrox Press.

Gary Horen is the Program Manager for the BEA Weblogic Workshop Compiler Team. He has been recently focused on the introduction of language technologies into Eclipse, including the Java annotation processing feature.

Floor Plan

Gold sponsors

Ingres logo

BEA logo

IBM logo

Business Objects logo

Klocwork logo

Windriver logo

Red Hat logo

Actuate logo

Silver sponsors

Compuware logo

Sybase logo

Google logo






Code Gear




Innoopract logo

Lynux Works

Media sponsors

Eclipse Magazine logo logo

Methods and Tools logo

Eclipsezone logo

Addison-Wesley logo

Eclipse Magazin logo

Embedded Computing logo

SD Times logo

Enterprise Open Source logo

ACM Queue logo

TheServerSide Java Symposium

Eclipse Review logo

Software Test & Performance logo

Eclipse Developers Journal logo

Eclipse Source logo