// interpreting 'type' as a provided type, compute the provide null bits
  // we inspect the main type plus bounds of type variables and wildcards
  static long providedNullTagBits(TypeBinding type) {

    long tagBits = type.tagBits & TagBits.AnnotationNullMASK;
    if (tagBits != 0) return validNullTagBits(tagBits);

    if (type.isWildcard()) { // wildcard can be 'provided' during inheritance checks
      WildcardBinding wildcard = (WildcardBinding) type;
      if (wildcard.boundKind == Wildcard.UNBOUND) return 0;
      tagBits = wildcard.bound.tagBits & TagBits.AnnotationNullMASK;
      if (tagBits == 0) return 0;
      switch (wildcard.boundKind) {
        case Wildcard.EXTENDS:
          if (tagBits == TagBits.AnnotationNonNull) return TagBits.AnnotationNonNull;
          return TagBits.AnnotationNullMASK; // @Nullable or better
        case Wildcard.SUPER:
          if (tagBits == TagBits.AnnotationNullable) return TagBits.AnnotationNullable;
          return TagBits.AnnotationNullMASK; // @NonNull or worse
      }
      return 0;
    }

    if (type.isTypeVariable()) { // incl. captures
      TypeVariableBinding typeVariable = (TypeVariableBinding) type;
      boolean haveNullBits = false;
      if (typeVariable.isCapture()) {
        TypeBinding lowerBound = ((CaptureBinding) typeVariable).lowerBound;
        if (lowerBound != null) {
          tagBits = lowerBound.tagBits & TagBits.AnnotationNullMASK;
          if (tagBits == TagBits.AnnotationNullable)
            return TagBits.AnnotationNullable; // cannot be @NonNull
          haveNullBits |= (tagBits != 0);
        }
      }
      if (typeVariable.firstBound != null) {
        long boundBits = typeVariable.firstBound.tagBits & TagBits.AnnotationNullMASK;
        if (boundBits == TagBits.AnnotationNonNull)
          return TagBits.AnnotationNonNull; // cannot be @Nullable
        haveNullBits |= (boundBits != 0);
      }
      if (haveNullBits)
        return TagBits
            .AnnotationNullMASK; // could be either, can only match to a wildcard accepting both
    }

    return 0;
  }
Exemplo n.º 2
0
 /*
  * @see ITypeBinding#getDeclaringClass()
  */
 public synchronized ITypeBinding getDeclaringClass() {
   if (isClass() || isInterface() || isEnum()) {
     ReferenceBinding referenceBinding = (ReferenceBinding) this.binding;
     if (referenceBinding.isNestedType()) {
       try {
         return this.resolver.getTypeBinding(referenceBinding.enclosingType());
       } catch (RuntimeException e) {
         /* in case a method cannot be resolvable due to missing jars on the classpath
          * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=57871
          * https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
          * https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
          */
         org.eclipse.jdt.internal.core.util.Util.log(
             e, "Could not retrieve declaring class"); // $NON-NLS-1$
       }
     }
   } else if (this.binding.isTypeVariable()) {
     TypeVariableBinding typeVariableBinding = (TypeVariableBinding) this.binding;
     Binding declaringElement =
         typeVariableBinding.isCapture()
             ? ((CaptureBinding) typeVariableBinding).sourceType
             : typeVariableBinding.declaringElement;
     if (declaringElement instanceof ReferenceBinding) {
       try {
         return this.resolver.getTypeBinding((ReferenceBinding) declaringElement);
       } catch (RuntimeException e) {
         /* in case a method cannot be resolvable due to missing jars on the classpath
          * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=57871
          * https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
          * https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
          */
         org.eclipse.jdt.internal.core.util.Util.log(
             e, "Could not retrieve declaring class"); // $NON-NLS-1$
       }
     }
   }
   return null;
 }