Package org.eclipse.jdt.internal.compiler.lookup

Examples of org.eclipse.jdt.internal.compiler.lookup.TypeBinding


        // thus it was a type
        this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
        this.bits |= Binding.TYPE;
        //$FALL-THROUGH$
      case Binding.TYPE : //=============only type ==============
          TypeBinding type = (TypeBinding) this.binding;
//          if (isTypeUseDeprecated(type, scope))
//            scope.problemReporter().deprecatedType(type, this);
        type = scope.environment().convertToRawType(type, false /*do not force conversion of enclosing types*/);
        return this.resolvedType = type;
    }
View Full Code Here


* Casting an enclosing instance will considered as useful if removing it would actually bind to a different type
*/
public static void checkNeedForEnclosingInstanceCast(BlockScope scope, Expression enclosingInstance, TypeBinding enclosingInstanceType, TypeBinding memberType) {
  if (scope.compilerOptions().getSeverity(CompilerOptions.UnnecessaryTypeCheck) == ProblemSeverities.Ignore) return;

  TypeBinding castedExpressionType = ((CastExpression)enclosingInstance).expression.resolvedType;
  if (castedExpressionType == null) return; // cannot do better
  // obvious identity cast
  if (castedExpressionType == enclosingInstanceType) {
    scope.problemReporter().unnecessaryCast((CastExpression)enclosingInstance);
  } else if (castedExpressionType == TypeBinding.NULL){
    return; // tolerate null enclosing instance cast
  } else {
    TypeBinding alternateEnclosingInstanceType = castedExpressionType;
    if (castedExpressionType.isBaseType() || castedExpressionType.isArrayType()) return; // error case
    if (memberType == scope.getMemberType(memberType.sourceName(), (ReferenceBinding) alternateEnclosingInstanceType)) {
      scope.problemReporter().unnecessaryCast((CastExpression)enclosingInstance);
    }
  }
View Full Code Here

  // check need for left operand cast
  if ((expression.bits & ASTNode.UnnecessaryCast) == 0 && expression.resolvedType.isBaseType()) {
    // narrowing conversion on base type may change value, thus necessary
    return;
  } else {
    TypeBinding alternateLeftType = ((CastExpression)expression).expression.resolvedType;
    if (alternateLeftType == null) return; // cannot do better
    if (alternateLeftType.id == expressionTypeId) { // obvious identity cast
      scope.problemReporter().unnecessaryCast((CastExpression)expression);
      return;
    }
View Full Code Here

    if (argument instanceof CastExpression) {
      // narrowing conversion on base type may change value, thus necessary
      if ((argument.bits & ASTNode.UnnecessaryCast) == 0 && argument.resolvedType.isBaseType()) {
        continue;
      }
      TypeBinding castedExpressionType = ((CastExpression)argument).expression.resolvedType;
      if (castedExpressionType == null) return; // cannot do better
      // obvious identity cast
      if (castedExpressionType == argumentTypes[i]) {
        scope.problemReporter().unnecessaryCast((CastExpression)argument);
      } else if (castedExpressionType == TypeBinding.NULL){
View Full Code Here

  if (leftIsCast) {
    if ((left.bits & ASTNode.UnnecessaryCast) == 0 && left.resolvedType.isBaseType()) {
      // narrowing conversion on base type may change value, thus necessary
      leftIsCast = false;
    } else  {
      TypeBinding alternateLeftType = ((CastExpression)left).expression.resolvedType;
      if (alternateLeftType == null) return; // cannot do better
      if ((alternateLeftTypeId = alternateLeftType.id) == leftTypeId || scope.environment().computeBoxingType(alternateLeftType).id == leftTypeId) { // obvious identity cast
        scope.problemReporter().unnecessaryCast((CastExpression)left);
        leftIsCast = false;
      } else if (alternateLeftTypeId == TypeIds.T_null) {
        alternateLeftTypeId = leftTypeId;  // tolerate null argument cast
        leftIsCast = false;
      }
    }
  }
  // check need for right operand cast
  int alternateRightTypeId = rightTypeId;
  if (rightIsCast) {
    if ((right.bits & ASTNode.UnnecessaryCast) == 0 && right.resolvedType.isBaseType()) {
      // narrowing conversion on base type may change value, thus necessary
      rightIsCast = false;
    } else {
      TypeBinding alternateRightType = ((CastExpression)right).expression.resolvedType;
      if (alternateRightType == null) return; // cannot do better
      if ((alternateRightTypeId = alternateRightType.id) == rightTypeId || scope.environment().computeBoxingType(alternateRightType).id == rightTypeId) { // obvious identity cast
        scope.problemReporter().unnecessaryCast((CastExpression)right);
        rightIsCast = false;
      } else if (alternateRightTypeId == TypeIds.T_null) {
View Full Code Here

      if (binding.isVarargs()) {
        int paramLength = binding.parameters.length;
        if (paramLength == argumentLength) {
          int varargsIndex = paramLength - 1;
          ArrayBinding varargsType = (ArrayBinding) binding.parameters[varargsIndex];
          TypeBinding lastArgType = alternateArgumentTypes[varargsIndex];
          // originalType may be compatible already, but cast mandated
          // to clarify between varargs/non-varargs call
          if (varargsType.dimensions != lastArgType.dimensions()) {
            return;
          }
          if (lastArgType.isCompatibleWith(varargsType.elementsType())
              && lastArgType.isCompatibleWith(varargsType)) {
            return;
          }
        }
      }
      for (int i = 0; i < argumentLength; i++) {
View Full Code Here

            break;
        }
      }
      break;
    case Binding.ARRAY_TYPE :
      TypeBinding leafType = castType.leafComponentType();
      if (isNarrowing && (!leafType.isReifiable() || leafType.isTypeVariable())) {
        this.bits |= ASTNode.UnsafeCast;
        return true;
      }
      break;
    case Binding.TYPE_PARAMETER :
View Full Code Here

  this.constant = Constant.NotAConstant;
  this.implicitConversion = TypeIds.T_undefined;

  boolean exprContainCast = false;

  TypeBinding castType = this.resolvedType = this.type.resolveType(scope);
  //expression.setExpectedType(this.resolvedType); // needed in case of generic method invocation
  if (this.expression instanceof CastExpression) {
    this.expression.bits |= ASTNode.DisableUnnecessaryCastCheck;
    exprContainCast = true;
  }
  TypeBinding expressionType = this.expression.resolveType(scope);
  if (this.expression instanceof MessageSend) {
    MessageSend messageSend = (MessageSend) this.expression;
    MethodBinding methodBinding = messageSend.binding;
    if (methodBinding != null && methodBinding.isPolymorphic()) {
      messageSend.binding = scope.environment().updatePolymorphicMethodReturnType((PolymorphicMethodBinding) methodBinding, castType);
View Full Code Here

      this.compilerElementPair = new ElementValuePair(this.name, this.value, this.binding);
      return;
    }

    this.value.setExpectedType(requiredType); // needed in case of generic method invocation
    TypeBinding valueType;
    if (this.value instanceof ArrayInitializer) {
      ArrayInitializer initializer = (ArrayInitializer) this.value;
      valueType = initializer.resolveTypeExpecting(scope, this.binding.returnType);
    } else if (this.value instanceof ArrayAllocationExpression) {
      scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass, this.name, this.value);
      this.value.resolveType(scope);
      valueType = null; // no need to pursue
    } else {
      valueType = this.value.resolveType(scope);
      // https://bugs.eclipse.org/bugs/show_bug.cgi?id=248897
      ASTVisitor visitor = new ASTVisitor() {
        public boolean visit(SingleNameReference reference, BlockScope scop) {
          if (reference.binding instanceof LocalVariableBinding) {
            ((LocalVariableBinding) reference.binding).useFlag = LocalVariableBinding.USED;
          }
          return true;
        }
      };
      this.value.traverse(visitor, scope);
    }
    this.compilerElementPair = new ElementValuePair(this.name, this.value, this.binding);
    if (valueType == null)
      return;

    TypeBinding leafType = requiredType.leafComponentType();
    if (!(this.value.isConstantValueOfTypeAssignableToType(valueType, requiredType)
        || valueType.isCompatibleWith(requiredType))) {

      if (!(requiredType.isArrayType()
          && requiredType.dimensions() == 1
          && (this.value.isConstantValueOfTypeAssignableToType(valueType, leafType)
              || valueType.isCompatibleWith(leafType)))) {

        if (leafType.isAnnotationType() && !valueType.isAnnotationType()) {
          scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass, this.name, this.value, leafType);
        } else {
          scope.problemReporter().typeMismatchError(valueType, requiredType, this.value, null);
        }
        return; // may allow to proceed to find more errors at once
      }
    } else {
      scope.compilationUnitScope().recordTypeConversion(requiredType.leafComponentType(), valueType.leafComponentType());
      this.value.computeConversion(scope, requiredType, valueType);
    }

    // annotation methods can only return base types, String, Class, enum type, annotation types and arrays of these
    checkAnnotationMethodType: {
      switch (leafType.erasure().id) {
        case T_byte :
        case T_short :
        case T_char :
        case T_int :
        case T_long :
        case T_float :
        case T_double :
        case T_boolean :
        case T_JavaLangString :
          if (this.value instanceof ArrayInitializer) {
            ArrayInitializer initializer = (ArrayInitializer) this.value;
            final Expression[] expressions = initializer.expressions;
            if (expressions != null) {
              for (int i =0, max = expressions.length; i < max; i++) {
                Expression expression = expressions[i];
                if (expression.resolvedType == null) continue; // fault-tolerance
                if (expression.constant == Constant.NotAConstant) {
                  scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, expressions[i], false);
                }
              }
            }
          } else if (this.value.constant == Constant.NotAConstant) {
            if (valueType.isArrayType()) {
              scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass, this.name, this.value);
            } else {
              scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value, false);
            }
          }
          break checkAnnotationMethodType;
        case T_JavaLangClass :
          if (this.value instanceof ArrayInitializer) {
            ArrayInitializer initializer = (ArrayInitializer) this.value;
            final Expression[] expressions = initializer.expressions;
            if (expressions != null) {
              for (int i =0, max = expressions.length; i < max; i++) {
                Expression currentExpression = expressions[i];
                if (!(currentExpression instanceof ClassLiteralAccess)) {
                  scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass, this.name, currentExpression);
                }
              }
            }
          } else if (!(this.value instanceof ClassLiteralAccess)) {
            scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass, this.name, this.value);
          }
          break checkAnnotationMethodType;
      }
      if (leafType.isEnum()) {
        if (this.value instanceof NullLiteral) {
          scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value, true);
        } else if (this.value instanceof ArrayInitializer) {
          ArrayInitializer initializer = (ArrayInitializer) this.value;
          final Expression[] expressions = initializer.expressions;
          if (expressions != null) {
            for (int i =0, max = expressions.length; i < max; i++) {
              Expression currentExpression = expressions[i];
              if (currentExpression instanceof NullLiteral) {
                scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, currentExpression, true);
              } else if (currentExpression instanceof NameReference) {
                NameReference nameReference = (NameReference) currentExpression;
                final Binding nameReferenceBinding = nameReference.binding;
                if (nameReferenceBinding.kind() == Binding.FIELD) {
                  FieldBinding fieldBinding = (FieldBinding) nameReferenceBinding;
                  if (!fieldBinding.declaringClass.isEnum()) {
                    scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, currentExpression, true);
                  }
                }
              }
            }
          }
        } else if (this.value instanceof NameReference) {
          NameReference nameReference = (NameReference) this.value;
          final Binding nameReferenceBinding = nameReference.binding;
          if (nameReferenceBinding.kind() == Binding.FIELD) {
            FieldBinding fieldBinding = (FieldBinding) nameReferenceBinding;
            if (!fieldBinding.declaringClass.isEnum()) {
              if (!fieldBinding.type.isArrayType()) {
                scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value, true);
              } else {
                scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass, this.name, this.value);
              }
            }
          }
        }  else {
          scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass, this.name, this.value, true);
        }
        break checkAnnotationMethodType;
      }
      if (leafType.isAnnotationType()) {
        if (!valueType.leafComponentType().isAnnotationType()) { // check annotation type and also reject null literal
          scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass, this.name, this.value, leafType);
        } else if (this.value instanceof ArrayInitializer) {
          ArrayInitializer initializer = (ArrayInitializer) this.value;
          final Expression[] expressions = initializer.expressions;
View Full Code Here

    if (numberOfInnerClasses != 0) {
      ReferenceBinding[] innerClasses = new ReferenceBinding[numberOfInnerClasses];
      this.innerClassesBindings.toArray(innerClasses);
      Arrays.sort(innerClasses, new Comparator() {
        public int compare(Object o1, Object o2) {
          TypeBinding binding1 = (TypeBinding) o1;
          TypeBinding binding2 = (TypeBinding) o2;
          return CharOperation.compareTo(binding1.constantPoolName(), binding2.constantPoolName());
        }
      });
      attributesNumber += generateInnerClassAttribute(numberOfInnerClasses, innerClasses);
    }
    if (this.missingTypes != null) {
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.lookup.TypeBinding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.