@Override
  public void handle(
      final AnnotationValues<ListenerSupport> annotation,
      final JCAnnotation source,
      final JavacNode annotationNode) {
    deleteAnnotationIfNeccessary(annotationNode, ListenerSupport.class);

    JavacType type = JavacType.typeOf(annotationNode, source);
    if (type.isAnnotation() || type.isInterface()) {
      annotationNode.addError(canBeUsedOnClassAndEnumOnly(ListenerSupport.class));
      return;
    }

    List<Object> listenerInterfaces = annotation.getActualExpressions("value");
    if (listenerInterfaces.isEmpty()) {
      annotationNode.addError(
          String.format(
              "@%s has no effect since no interface types were specified.",
              ListenerSupport.class.getName()));
      return;
    }
    List<TypeSymbol> resolvedInterfaces =
        resolveInterfaces(annotationNode, ListenerSupport.class, listenerInterfaces);
    for (TypeSymbol interfaze : resolvedInterfaces) {
      handler.addListenerField(type, interfaze);
      handler.addAddListenerMethod(type, interfaze);
      handler.addRemoveListenerMethod(type, interfaze);
      addFireListenerMethods(type, interfaze);
    }

    type.editor().rebuild();
  }
Ejemplo n.º 2
0
 static List<Extension> getApplicableExtensionMethods(
     EclipseNode typeNode, Annotation ann, TypeBinding receiverType) {
   List<Extension> extensions = new ArrayList<Extension>();
   if ((typeNode != null) && (ann != null) && (receiverType != null)) {
     BlockScope blockScope = ((TypeDeclaration) typeNode.get()).initializerScope;
     EclipseNode annotationNode = typeNode.getNodeFor(ann);
     AnnotationValues<ExtensionMethod> annotation =
         createAnnotation(ExtensionMethod.class, annotationNode);
     boolean suppressBaseMethods = false;
     try {
       suppressBaseMethods = annotation.getInstance().suppressBaseMethods();
     } catch (AnnotationValueDecodeFail fail) {
       fail.owner.setError(fail.getMessage(), fail.idx);
     }
     for (Object extensionMethodProvider : annotation.getActualExpressions("value")) {
       if (extensionMethodProvider instanceof ClassLiteralAccess) {
         TypeBinding binding =
             ((ClassLiteralAccess) extensionMethodProvider).type.resolveType(blockScope);
         if (binding == null) continue;
         if (!binding.isClass() && !binding.isEnum()) continue;
         Extension e = new Extension();
         e.extensionMethods =
             getApplicableExtensionMethodsDefinedInProvider(
                 typeNode, (ReferenceBinding) binding, receiverType);
         e.suppressBaseMethods = suppressBaseMethods;
         extensions.add(e);
       }
     }
   }
   return extensions;
 }