public void traverse(ASTVisitor visitor, ClassScope scope) {
   if (visitor.visit(this, scope)) {
     if (this.annotations != null) {
       Annotation[] typeAnnotations = this.annotations[0];
       for (int i = 0, length = typeAnnotations == null ? 0 : typeAnnotations.length;
           i < length;
           i++) {
         typeAnnotations[i].traverse(visitor, scope);
       }
     }
     if (this.annotationsOnDimensions != null) {
       for (int i = 0, max = this.annotationsOnDimensions.length; i < max; i++) {
         Annotation[] annotations2 = this.annotationsOnDimensions[i];
         for (int j = 0, max2 = annotations2.length; j < max2; j++) {
           Annotation annotation = annotations2[j];
           annotation.traverse(visitor, scope);
         }
       }
     }
     for (int i = 0, max = this.typeArguments.length; i < max; i++) {
       this.typeArguments[i].traverse(visitor, scope);
     }
   }
   visitor.endVisit(this, scope);
 }
示例#2
0
 public void getAllAnnotationContexts(
     int targetType, int info, List allAnnotationContexts, Annotation[] se7Annotations) {
   AnnotationCollector collector =
       new AnnotationCollector(this, targetType, info, allAnnotationContexts);
   for (int i = 0, length = se7Annotations == null ? 0 : se7Annotations.length; i < length; i++) {
     Annotation annotation = se7Annotations[i];
     annotation.traverse(collector, (BlockScope) null);
   }
   this.traverse(collector, (BlockScope) null);
 }
示例#3
0
 private boolean internalVisit(Annotation annotation) {
   AnnotationContext annotationContext = null;
   if (annotation.isRuntimeTypeInvisible()) {
     annotationContext =
         new AnnotationContext(
             annotation, this.typeReference, this.targetType, AnnotationContext.INVISIBLE);
   } else if (annotation.isRuntimeTypeVisible()) {
     annotationContext =
         new AnnotationContext(
             annotation, this.typeReference, this.targetType, AnnotationContext.VISIBLE);
   }
   if (annotationContext != null) {
     annotationContext.wildcard = this.currentWildcard;
     switch (this.targetType) {
       case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER:
       case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER:
       case AnnotationTargetTypeConstants.CLASS_EXTENDS:
       case AnnotationTargetTypeConstants.METHOD_FORMAL_PARAMETER:
       case AnnotationTargetTypeConstants.THROWS:
       case AnnotationTargetTypeConstants.EXCEPTION_PARAMETER:
       case AnnotationTargetTypeConstants.INSTANCEOF:
       case AnnotationTargetTypeConstants.NEW:
       case AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE:
       case AnnotationTargetTypeConstants.METHOD_REFERENCE:
         annotationContext.info = this.info;
         break;
       case AnnotationTargetTypeConstants.LOCAL_VARIABLE:
       case AnnotationTargetTypeConstants.RESOURCE_VARIABLE:
         annotationContext.variableBinding = this.localVariable;
         break;
       case AnnotationTargetTypeConstants.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT:
       case AnnotationTargetTypeConstants.METHOD_INVOCATION_TYPE_ARGUMENT:
       case AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT:
       case AnnotationTargetTypeConstants.METHOD_REFERENCE_TYPE_ARGUMENT:
       case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER_BOUND:
       case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER_BOUND:
       case AnnotationTargetTypeConstants.CAST:
         annotationContext.info2 = this.info2;
         annotationContext.info = this.info;
         break;
       case AnnotationTargetTypeConstants.FIELD:
       case AnnotationTargetTypeConstants.METHOD_RETURN:
       case AnnotationTargetTypeConstants.METHOD_RECEIVER:
         break;
     }
     this.annotationContexts.add(annotationContext);
   }
   return true;
 }
示例#4
0
 /**
  * Resolve annotations, and check duplicates, answers combined tagBits for recognized standard
  * annotations
  */
 public static void resolveAnnotations(
     BlockScope scope, Annotation[] sourceAnnotations, Binding recipient) {
   AnnotationBinding[] annotations = null;
   int length = sourceAnnotations == null ? 0 : sourceAnnotations.length;
   if (recipient != null) {
     switch (recipient.kind()) {
       case Binding.PACKAGE:
         PackageBinding packageBinding = (PackageBinding) recipient;
         if ((packageBinding.tagBits & TagBits.AnnotationResolved) != 0) return;
         packageBinding.tagBits |=
             (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
         break;
       case Binding.TYPE:
       case Binding.GENERIC_TYPE:
         ReferenceBinding type = (ReferenceBinding) recipient;
         if ((type.tagBits & TagBits.AnnotationResolved) != 0) return;
         type.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
         if (length > 0) {
           annotations = new AnnotationBinding[length];
           type.setAnnotations(annotations);
         }
         break;
       case Binding.METHOD:
         MethodBinding method = (MethodBinding) recipient;
         if ((method.tagBits & TagBits.AnnotationResolved) != 0) return;
         method.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
         if (length > 0) {
           annotations = new AnnotationBinding[length];
           method.setAnnotations(annotations);
         }
         break;
       case Binding.FIELD:
         FieldBinding field = (FieldBinding) recipient;
         if ((field.tagBits & TagBits.AnnotationResolved) != 0) return;
         field.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
         if (length > 0) {
           annotations = new AnnotationBinding[length];
           field.setAnnotations(annotations);
         }
         break;
       case Binding.LOCAL:
         LocalVariableBinding local = (LocalVariableBinding) recipient;
         if ((local.tagBits & TagBits.AnnotationResolved) != 0) return;
         local.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
         if (length > 0) {
           annotations = new AnnotationBinding[length];
           local.setAnnotations(annotations);
         }
         break;
       default:
         return;
     }
   }
   if (sourceAnnotations == null) return;
   for (int i = 0; i < length; i++) {
     Annotation annotation = sourceAnnotations[i];
     final Binding annotationRecipient = annotation.recipient;
     if (annotationRecipient != null && recipient != null) {
       // only local and field can share annnotations
       switch (recipient.kind()) {
         case Binding.FIELD:
           FieldBinding field = (FieldBinding) recipient;
           field.tagBits = ((FieldBinding) annotationRecipient).tagBits;
           break;
         case Binding.LOCAL:
           LocalVariableBinding local = (LocalVariableBinding) recipient;
           local.tagBits = ((LocalVariableBinding) annotationRecipient).tagBits;
           break;
       }
       if (annotations != null) {
         // need to fill the instances array
         annotations[0] = annotation.getCompilerAnnotation();
         for (int j = 1; j < length; j++) {
           Annotation annot = sourceAnnotations[j];
           annotations[j] = annot.getCompilerAnnotation();
         }
       }
       return;
     } else {
       annotation.recipient = recipient;
       annotation.resolveType(scope);
       // null if receiver is a package binding
       if (annotations != null) {
         annotations[i] = annotation.getCompilerAnnotation();
       }
     }
   }
   // check duplicate annotations
   if (annotations != null) {
     AnnotationBinding[] distinctAnnotations =
         annotations; // only copy after 1st duplicate is detected
     for (int i = 0; i < length; i++) {
       AnnotationBinding annotation = distinctAnnotations[i];
       if (annotation == null) continue;
       TypeBinding annotationType = annotation.getAnnotationType();
       boolean foundDuplicate = false;
       for (int j = i + 1; j < length; j++) {
         AnnotationBinding otherAnnotation = distinctAnnotations[j];
         if (otherAnnotation == null) continue;
         if (otherAnnotation.getAnnotationType() == annotationType) {
           foundDuplicate = true;
           if (distinctAnnotations == annotations) {
             System.arraycopy(
                 distinctAnnotations,
                 0,
                 distinctAnnotations = new AnnotationBinding[length],
                 0,
                 length);
           }
           distinctAnnotations[j] = null; // report it only once
           scope.problemReporter().duplicateAnnotation(sourceAnnotations[j]);
         }
       }
       if (foundDuplicate) {
         scope.problemReporter().duplicateAnnotation(sourceAnnotations[i]);
       }
     }
   }
 }