private Binding findImport(char[][] compoundName, int length) {
    recordQualifiedReference(compoundName);

    Binding binding = this.environment.getTopLevelPackage(compoundName[0]);
    int i = 1;
    foundNothingOrType:
    if (binding != null) {
      PackageBinding packageBinding = (PackageBinding) binding;
      while (i < length) {
        binding = packageBinding.getTypeOrPackage(compoundName[i++]);
        if (binding == null || !binding.isValidBinding()) {
          binding = null;
          break foundNothingOrType;
        }
        if (!(binding instanceof PackageBinding)) break foundNothingOrType;

        packageBinding = (PackageBinding) binding;
      }
      return packageBinding;
    }

    ReferenceBinding type;
    if (binding == null) {
      if (compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
        return new ProblemReferenceBinding(
            CharOperation.subarray(compoundName, 0, i), null, ProblemReasons.NotFound);
      type =
          findType(
              compoundName[0], this.environment.defaultPackage, this.environment.defaultPackage);
      if (type == null || !type.isValidBinding())
        return new ProblemReferenceBinding(
            CharOperation.subarray(compoundName, 0, i), null, ProblemReasons.NotFound);
      i = 1; // reset to look for member types inside the default package type
    } else {
      type = (ReferenceBinding) binding;
    }

    while (i < length) {
      type =
          (ReferenceBinding)
              this.environment.convertToRawType(
                  type, false /*do not force conversion of enclosing types*/); // type imports are
      // necessarily raw for all
      // except last
      if (!type.canBeSeenBy(this.fPackage))
        return new ProblemReferenceBinding(
            CharOperation.subarray(compoundName, 0, i), type, ProblemReasons.NotVisible);

      char[] name = compoundName[i++];
      // does not look for inherited member types on purpose, only immediate members
      type = type.getMemberType(name);
      if (type == null)
        return new ProblemReferenceBinding(
            CharOperation.subarray(compoundName, 0, i), null, ProblemReasons.NotFound);
    }
    if (!type.canBeSeenBy(this.fPackage))
      return new ProblemReferenceBinding(compoundName, type, ProblemReasons.NotVisible);
    return type;
  }
Пример #2
0
 /** Figures if @Deprecated annotation is specified, do not resolve entire annotations. */
 public static void resolveDeprecatedAnnotations(
     BlockScope scope, Annotation[] annotations, Binding recipient) {
   if (recipient != null) {
     int kind = recipient.kind();
     if (annotations != null) {
       int length;
       if ((length = annotations.length) >= 0) {
         switch (kind) {
           case Binding.PACKAGE:
             PackageBinding packageBinding = (PackageBinding) recipient;
             if ((packageBinding.tagBits & TagBits.DeprecatedAnnotationResolved) != 0) return;
             break;
           case Binding.TYPE:
           case Binding.GENERIC_TYPE:
             ReferenceBinding type = (ReferenceBinding) recipient;
             if ((type.tagBits & TagBits.DeprecatedAnnotationResolved) != 0) return;
             break;
           case Binding.METHOD:
             MethodBinding method = (MethodBinding) recipient;
             if ((method.tagBits & TagBits.DeprecatedAnnotationResolved) != 0) return;
             break;
           case Binding.FIELD:
             FieldBinding field = (FieldBinding) recipient;
             if ((field.tagBits & TagBits.DeprecatedAnnotationResolved) != 0) return;
             break;
           case Binding.LOCAL:
             LocalVariableBinding local = (LocalVariableBinding) recipient;
             if ((local.tagBits & TagBits.DeprecatedAnnotationResolved) != 0) return;
             break;
           default:
             return;
         }
         for (int i = 0; i < length; i++) {
           TypeReference annotationTypeRef = annotations[i].type;
           // only resolve type name if 'Deprecated' last token
           if (!CharOperation.equals(
               TypeConstants.JAVA_LANG_DEPRECATED[2], annotationTypeRef.getLastToken())) return;
           TypeBinding annotationType = annotations[i].type.resolveType(scope);
           if (annotationType != null
               && annotationType.isValidBinding()
               && annotationType.id == TypeIds.T_JavaLangDeprecated) {
             switch (kind) {
               case Binding.PACKAGE:
                 PackageBinding packageBinding = (PackageBinding) recipient;
                 packageBinding.tagBits |=
                     (TagBits.AnnotationDeprecated | TagBits.DeprecatedAnnotationResolved);
                 return;
               case Binding.TYPE:
               case Binding.GENERIC_TYPE:
               case Binding.TYPE_PARAMETER:
                 ReferenceBinding type = (ReferenceBinding) recipient;
                 type.tagBits |=
                     (TagBits.AnnotationDeprecated | TagBits.DeprecatedAnnotationResolved);
                 return;
               case Binding.METHOD:
                 MethodBinding method = (MethodBinding) recipient;
                 method.tagBits |=
                     (TagBits.AnnotationDeprecated | TagBits.DeprecatedAnnotationResolved);
                 return;
               case Binding.FIELD:
                 FieldBinding field = (FieldBinding) recipient;
                 field.tagBits |=
                     (TagBits.AnnotationDeprecated | TagBits.DeprecatedAnnotationResolved);
                 return;
               case Binding.LOCAL:
                 LocalVariableBinding local = (LocalVariableBinding) recipient;
                 local.tagBits |=
                     (TagBits.AnnotationDeprecated | TagBits.DeprecatedAnnotationResolved);
                 return;
               default:
                 return;
             }
           }
         }
       }
     }
     switch (kind) {
       case Binding.PACKAGE:
         PackageBinding packageBinding = (PackageBinding) recipient;
         packageBinding.tagBits |= TagBits.DeprecatedAnnotationResolved;
         return;
       case Binding.TYPE:
       case Binding.GENERIC_TYPE:
       case Binding.TYPE_PARAMETER:
         ReferenceBinding type = (ReferenceBinding) recipient;
         type.tagBits |= TagBits.DeprecatedAnnotationResolved;
         return;
       case Binding.METHOD:
         MethodBinding method = (MethodBinding) recipient;
         method.tagBits |= TagBits.DeprecatedAnnotationResolved;
         return;
       case Binding.FIELD:
         FieldBinding field = (FieldBinding) recipient;
         field.tagBits |= TagBits.DeprecatedAnnotationResolved;
         return;
       case Binding.LOCAL:
         LocalVariableBinding local = (LocalVariableBinding) recipient;
         local.tagBits |= TagBits.DeprecatedAnnotationResolved;
         return;
       default:
         return;
     }
   }
 }
Пример #3
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]);
       }
     }
   }
 }