@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class BoundAnnotationChecker extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
final Types types = processingEnv.getTypeUtils();
final Elements elements = processingEnv.getElementUtils();
final TypeMirror gwtWidgetType = elements.getTypeElement(TypeNames.GWT_WIDGET).asType();
final TypeMirror gwtElementType = elements.getTypeElement(TypeNames.GWT_ELEMENT).asType();
Map<TypeElement, List<Element>> classesWithBoundThings = new HashMap<TypeElement, List<Element>>();
for (TypeElement annotation : annotations) {
for (Element target : roundEnv.getElementsAnnotatedWith(annotation)) {
TypeMirror targetType;
if (target.getKind() == ElementKind.METHOD) {
targetType = ((ExecutableElement) target).getReturnType();
}
else {
targetType = target.asType();
}
if (!types.isAssignable(targetType, gwtWidgetType) && !types.isAssignable(targetType, gwtElementType)) {
processingEnv.getMessager().printMessage(
Kind.ERROR, "@Bound must target a type assignable to Widget or Element", target);
}
TypeElement enclosingClass = getEnclosingTypeElement(target);