boolean denotesRelevantSuperClass(TypeBinding type) {
   if (!type.isTypeVariable() && !type.isInterface() && type.id != TypeIds.T_JavaLangObject)
     return true;
   ReferenceBinding aSuperClass = type.superclass();
   return aSuperClass != null
       && aSuperClass.id != TypeIds.T_JavaLangObject
       && !aSuperClass.isTypeVariable();
 }
 /** Detect when we are equating an inference variable against a free type variable. */
 boolean checkIVFreeTVmatch(TypeBinding one, TypeBinding two) {
   if (one instanceof InferenceVariable
       && two.isTypeVariable()
       && (two.tagBits & TagBits.AnnotationNullMASK) == 0) {
     // found match => avoid inferring any null annotation (by marking as contradiction):
     ((InferenceVariable) one).nullHints = TagBits.AnnotationNullMASK;
     return true;
   }
   return false;
 }
Пример #3
0
  protected boolean isBoxingCompatible(
      TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope) {
    if (scope.isBoxingCompatibleWith(expressionType, targetType)) return true;

    return expressionType
            .isBaseType() // narrowing then boxing ? Only allowed for some target types see 362279
        && !targetType.isBaseType()
        && !targetType.isTypeVariable()
        && scope.compilerOptions().sourceLevel
            >= org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5 // autoboxing
        && (targetType.id == TypeIds.T_JavaLangByte
            || targetType.id == TypeIds.T_JavaLangShort
            || targetType.id == TypeIds.T_JavaLangCharacter)
        && expression.isConstantValueOfTypeAssignableToType(
            expressionType, scope.environment().computeBoxingType(targetType));
  }
Пример #4
0
  public TypeBinding resolveSuperType(ClassScope scope) {
    // assumes the implementation of resolveType(ClassScope) will call back to detect cycles
    TypeBinding superType = resolveType(scope);
    if (superType == null) return null;

    if (superType.isTypeVariable()) {
      if (this.resolvedType.isValidBinding()) {
        this.resolvedType =
            new ProblemReferenceBinding(
                getTypeName(),
                (ReferenceBinding) this.resolvedType,
                ProblemReasons.IllegalSuperTypeVariable);
        reportInvalidType(scope);
      }
      return null;
    }
    return superType;
  }
Пример #5
0
  public final boolean canBeSeenBy(
      TypeBinding receiverType, InvocationSite invocationSite, Scope scope) {
    if (isPublic()) return true;

    SourceTypeBinding invocationType = scope.enclosingSourceType();
    if (invocationType == this.declaringClass && invocationType == receiverType) return true;

    if (invocationType == null) // static import call
    return !isPrivate() && scope.getCurrentPackage() == this.declaringClass.fPackage;

    if (isProtected()) {
      // answer true if the invocationType is the declaringClass or they are in the same package
      // OR the invocationType is a subclass of the declaringClass
      //    AND the receiverType is the invocationType or its subclass
      //    OR the method is a static method accessed directly through a type
      //    OR previous assertions are true for one of the enclosing type
      if (invocationType == this.declaringClass) return true;
      if (invocationType.fPackage == this.declaringClass.fPackage) return true;

      ReferenceBinding currentType = invocationType;
      int depth = 0;
      ReferenceBinding receiverErasure = (ReferenceBinding) receiverType.erasure();
      ReferenceBinding declaringErasure = (ReferenceBinding) this.declaringClass.erasure();
      do {
        if (currentType.findSuperTypeOriginatingFrom(declaringErasure) != null) {
          if (invocationSite.isSuperAccess()) return true;
          // receiverType can be an array binding in one case... see if you can change it
          if (receiverType instanceof ArrayBinding) return false;
          if (isStatic()) {
            if (depth > 0) invocationSite.setDepth(depth);
            return true; // see 1FMEPDL - return invocationSite.isTypeAccess();
          }
          if (currentType == receiverErasure
              || receiverErasure.findSuperTypeOriginatingFrom(currentType) != null) {
            if (depth > 0) invocationSite.setDepth(depth);
            return true;
          }
        }
        depth++;
        currentType = currentType.enclosingType();
      } while (currentType != null);
      return false;
    }

    if (isPrivate()) {
      // answer true if the receiverType is the declaringClass
      // AND the invocationType and the declaringClass have a common enclosingType
      receiverCheck:
      {
        if (receiverType != this.declaringClass) {
          // special tolerance for type variable direct bounds
          if (receiverType.isTypeVariable()
              && ((TypeVariableBinding) receiverType)
                  .isErasureBoundTo(this.declaringClass.erasure())) break receiverCheck;
          return false;
        }
      }

      if (invocationType != this.declaringClass) {
        ReferenceBinding outerInvocationType = invocationType;
        ReferenceBinding temp = outerInvocationType.enclosingType();
        while (temp != null) {
          outerInvocationType = temp;
          temp = temp.enclosingType();
        }

        ReferenceBinding outerDeclaringClass = (ReferenceBinding) this.declaringClass.erasure();
        temp = outerDeclaringClass.enclosingType();
        while (temp != null) {
          outerDeclaringClass = temp;
          temp = temp.enclosingType();
        }
        if (outerInvocationType != outerDeclaringClass) return false;
      }
      return true;
    }

    // isDefault()
    PackageBinding declaringPackage = this.declaringClass.fPackage;
    if (invocationType.fPackage != declaringPackage) return false;

    // receiverType can be an array binding in one case... see if you can change it
    if (receiverType instanceof ArrayBinding) return false;
    TypeBinding originalDeclaringClass = this.declaringClass.original();
    ReferenceBinding currentType = (ReferenceBinding) receiverType;
    do {
      if (originalDeclaringClass == currentType.original()) return true;
      PackageBinding currentPackage = currentType.fPackage;
      // package could be null for wildcards/intersection types, ignore and recurse in superclass
      if (currentPackage != null && currentPackage != declaringPackage) return false;
    } while ((currentType = currentType.superclass()) != null);
    return false;
  }
Пример #6
0
  public TypeBinding resolveType(BlockScope scope) {

    this.constant = Constant.NotAConstant;
    if ((this.targetType = this.type.resolveType(scope, true /* check bounds*/)) == null)
      return null;

    /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=320463
      https://bugs.eclipse.org/bugs/show_bug.cgi?id=312076
      JLS3 15.8.2 forbids the type named in the class literal expression from being a parameterized type.
      And the grammar in 18.1 disallows (where X and Y are some concrete types) constructs of the form
      Outer<X>.class, Outer<X>.Inner.class, Outer.Inner<X>.class, Outer<X>.Inner<Y>.class etc.
      Corollary wise, we should resolve the type of the class literal expression to be a raw type as
      class literals exist only for the raw underlying type.
    */
    LookupEnvironment environment = scope.environment();
    this.targetType =
        environment.convertToRawType(
            this.targetType, true /* force conversion of enclosing types*/);

    if (this.targetType.isArrayType()) {
      ArrayBinding arrayBinding = (ArrayBinding) this.targetType;
      TypeBinding leafComponentType = arrayBinding.leafComponentType;
      if (leafComponentType == TypeBinding.VOID) {
        scope.problemReporter().cannotAllocateVoidArray(this);
        return null;
      } else if (leafComponentType.isTypeVariable()) {
        scope
            .problemReporter()
            .illegalClassLiteralForTypeVariable((TypeVariableBinding) leafComponentType, this);
      }
    } else if (this.targetType.isTypeVariable()) {
      scope
          .problemReporter()
          .illegalClassLiteralForTypeVariable((TypeVariableBinding) this.targetType, this);
    }
    // {ObjectTeams: do we need a RoleClassLiteralAccess?
    if (this.targetType instanceof ReferenceBinding) {
      ReferenceBinding targetRef = (ReferenceBinding) this.targetType;
      if (targetRef.isRole()) {
        if (this.verbatim) {
          this.targetType =
              RoleTypeCreator.maybeWrapUnqualifiedRoleType(scope, this.targetType, this);
        } else {
          SourceTypeBinding site = scope.enclosingSourceType();
          if (scope.methodScope().isStatic // role class literal needs team instance
              && !site.isRole() // static role method are OK.
              && !RoleTypeBinding.isRoleWithExplicitAnchor(this.targetType)) // t.R.class?
          {
            scope.problemReporter().roleClassLiteralLacksTeamInstance(this, targetRef);
            return null;
          }
          ReferenceBinding teamBinding;
          if (RoleTypeBinding.isRoleWithExplicitAnchor(targetRef))
            teamBinding = targetRef.enclosingType();
          else teamBinding = TeamModel.findEnclosingTeamContainingRole(site, targetRef);
          if (teamBinding == null)
            scope.problemReporter().externalizedRoleClassLiteral(this, targetRef);
          else {
            TypeBinding methodType =
                RoleClassLiteralAccess.ensureGetClassMethod(
                    teamBinding.getTeamModel(),
                    targetRef.roleModel); // not affected by visibility check (for resilience)
            this.roleClassLiteralAccess = new RoleClassLiteralAccess(this, methodType);
            this.resolvedType = this.roleClassLiteralAccess.resolveType(scope);
          }
          return this.resolvedType;
        }
      }
    }
    // SH}
    ReferenceBinding classType = scope.getJavaLangClass();
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=328689
    if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
      // Integer.class --> Class<Integer>, perform boxing of base types (int.class -->
      // Class<Integer>)
      TypeBinding boxedType = null;
      if (this.targetType.id == T_void) {
        boxedType = environment.getResolvedType(JAVA_LANG_VOID, scope);
      } else {
        boxedType = scope.boxing(this.targetType);
      }
      if (environment.usesNullTypeAnnotations())
        boxedType =
            environment.createAnnotatedType(
                boxedType, new AnnotationBinding[] {environment.getNonNullAnnotation()});
      this.resolvedType =
          environment.createParameterizedType(
              classType, new TypeBinding[] {boxedType}, null /*not a member*/);
    } else {
      this.resolvedType = classType;
    }
    return this.resolvedType;
  }