2015-09-07 11:44:36 -06:00
|
|
|
// annotations/simplest/SimpleProcessor.java
|
2021-01-31 15:42:31 -07:00
|
|
|
// (c)2021 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2016-01-25 18:05:55 -08:00
|
|
|
// A bare-bones annotation processor
|
2015-06-15 17:47:35 -07:00
|
|
|
package annotations.simplest;
|
|
|
|
import javax.annotation.processing.*;
|
|
|
|
import javax.lang.model.SourceVersion;
|
|
|
|
import javax.lang.model.element.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@SupportedAnnotationTypes(
|
|
|
|
"annotations.simplest.Simple")
|
|
|
|
@SupportedSourceVersion(SourceVersion.RELEASE_8)
|
|
|
|
public class SimpleProcessor
|
|
|
|
extends AbstractProcessor {
|
2021-01-31 15:42:31 -07:00
|
|
|
@Override public boolean process(
|
2017-01-22 16:48:11 -08:00
|
|
|
Set<? extends TypeElement> annotations,
|
|
|
|
RoundEnvironment env) {
|
2015-06-15 17:47:35 -07:00
|
|
|
for(TypeElement t : annotations)
|
|
|
|
System.out.println(t);
|
|
|
|
for(Element el :
|
|
|
|
env.getElementsAnnotatedWith(Simple.class))
|
|
|
|
display(el);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
private void display(Element el) {
|
|
|
|
System.out.println("==== " + el + " ====");
|
|
|
|
System.out.println(el.getKind() +
|
|
|
|
" : " + el.getModifiers() +
|
|
|
|
" : " + el.getSimpleName() +
|
|
|
|
" : " + el.asType());
|
|
|
|
if(el.getKind().equals(ElementKind.CLASS)) {
|
|
|
|
TypeElement te = (TypeElement)el;
|
|
|
|
System.out.println(te.getQualifiedName());
|
|
|
|
System.out.println(te.getSuperclass());
|
|
|
|
System.out.println(te.getEnclosedElements());
|
|
|
|
}
|
|
|
|
if(el.getKind().equals(ElementKind.METHOD)) {
|
|
|
|
ExecutableElement ex = (ExecutableElement)el;
|
|
|
|
System.out.print(ex.getReturnType() + " ");
|
|
|
|
System.out.print(ex.getSimpleName() + "(");
|
|
|
|
System.out.println(ex.getParameters() + ")");
|
|
|
|
}
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|