@Override
  protected void generate(AnnotationTypeDeclaration node) {
    syncLineNumbers(node.getName()); // avoid doc-comment

    String typeName = NameTable.getFullName(node);
    printf("@implementation %s\n", typeName);
    if (BindingUtil.isRuntimeAnnotation(Types.getTypeBinding(node))) {
      List<AnnotationTypeMemberDeclaration> members = Lists.newArrayList();
      for (BodyDeclaration decl : ASTUtil.getBodyDeclarations(node)) {
        if (decl instanceof AnnotationTypeMemberDeclaration) {
          members.add((AnnotationTypeMemberDeclaration) decl);
        }
      }
      printAnnotationProperties(members);
      if (!members.isEmpty()) {
        printAnnotationConstructor(Types.getTypeBinding(node));
      }
      printAnnotationAccessors(members);
    }
    List<FieldDeclaration> fields = ASTUtil.getFieldDeclarations(node);
    List<IVariableBinding> fieldsNeedingAccessors =
        getStaticFieldsNeedingAccessors(fields, /* isInterface */ true);
    printStaticVars(fields, /* isInterface */ true);
    printStaticFieldAccessors(fieldsNeedingAccessors, Collections.<MethodDeclaration>emptyList());
    println("- (IOSClass *)annotationType {");
    printf("  return [IOSClass classWithProtocol:@protocol(%s)];\n", typeName);
    println("}\n");
    if (!Options.stripReflection()) {
      printTypeAnnotationsMethod(node);
      printMetadata(node);
    }
    println("@end\n");
  }
Beispiel #2
0
 /**
  * Returns true if the specified binding is of an annotation that has a runtime retention policy.
  */
 public static boolean isRuntimeAnnotation(ITypeBinding binding) {
   if (binding != null && binding.isAnnotation()) {
     for (IAnnotationBinding ann : binding.getAnnotations()) {
       if (ann.getName().equals("Retention")) {
         IVariableBinding retentionBinding =
             (IVariableBinding) ann.getDeclaredMemberValuePairs()[0].getValue();
         return retentionBinding.getName().equals(RetentionPolicy.RUNTIME.name());
       }
     }
     if (binding.isNested()) {
       return BindingUtil.isRuntimeAnnotation(binding.getDeclaringClass());
     }
   }
   return false;
 }
Beispiel #3
0
 public boolean apply(Annotation annotation) {
   return BindingUtil.isRuntimeAnnotation(annotation.getAnnotationBinding());
 }