What is the default annotation processors discovery process?

The default way to make an annotation processor available to the compiler is to register it in a file in META-INF/services/javax.annotation.processing.Processor. The file can contain a number of processors: each the fully-qualified class name on its own line, with a newline at the end. The compiler will default to using processors found in this way … Read more

Accessing source code from Java Annotation Processor

I had a problem where I had to access some source code (the initializer code for a non-String/non-primitive constant) and got it solved by accessing the source code via the Compiler Tree API. Here’s the general recipe: 1. Create a custom TreePathScanner: private static class CodeAnalyzerTreeScanner extends TreePathScanner<Object, Trees> { private String fieldName; private String … Read more

How to generate the JPA entity Metamodel?

It would be awesome if someone also knows the steps for setting this up in Eclipse (I assume it’s as simple as setting up an annotation processor, but you never know) Yes it is. Here are the implementations and instructions for the various JPA 2.0 implementations: EclipseLink org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor Hibernate org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor http://in.relation.to/2009/11/09/hibernate-static-metamodel-generator-annotation-processor OpenJPA org.apache.openjpa.persistence.meta.AnnotationProcessor6 http://openjpa.apache.org/builds/2.4.1/apache-openjpa/docs/ch13s04.html DataNucleus … Read more