Java Reference
In-Depth Information
public boolean process(Set<? extends
TypeElement>annotations, RoundEnvironment
roundEnv) {
try {
//For each annotated element do ...
for (Element e
:roundEnv.getElementsAnnotatedWith(Unfinished.class))
{
Unfinished unf =
e.getAnnotation(Unfinished.class);
System.out.println("***** Class
:"+e.getEnclosingElement()+", "+ "Annotated
element : " + e.getSimpleName()+", "+ " Kind :
"+e.getKind()+", Message :"+unf.message()+"****
");
}
} catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
}
Once the processor is realized, we must now declare it so that it can be found by
the compiler. The simplest way to do this is to use the Java mechanism for services
declarations using the following steps:
1. Package your annotation in a
JAR
file.
2. Include a
META-INF/services
directory in this
JAR
file.
3. Include a file named
javax.annotation.processing.Processor
in
the
META-INF/services
directory.
4. Specify in this file the fully qualified names of the processors contained in the
JAR
file (one processor per line).
The following screenshot shows the structure of the project that contains the
Un-
finished
annotation. Failing to put the annotation and the processor in the same
project as is the case of our example, you can use one project for annotations and