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

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


        return true; // identity conversion
      }
      switch (castType.kind()) {
        case Binding.ARRAY_TYPE :
          // ( ARRAY ) ARRAY
          TypeBinding castElementType = ((ArrayBinding) castType).elementsType();
          TypeBinding exprElementType = ((ArrayBinding) expressionType).elementsType();
          if (exprElementType.isBaseType() || castElementType.isBaseType()) {
            if (castElementType == exprElementType) {
              tagAsNeedCheckCast();
              return true;
            }
            return false;
          }
          // recurse on array type elements
          return checkCastTypesCompatibility(scope, castElementType, exprElementType, expression);

        case Binding.TYPE_PARAMETER :
          // ( TYPE_PARAMETER ) ARRAY
          TypeBinding match = expressionType.findSuperTypeOriginatingFrom(castType);
          if (match == null) {
            checkUnsafeCast(scope, castType, expressionType, null /*no match*/, true);
          }
          // recurse on the type variable upper bound
          return checkCastTypesCompatibility(scope, ((TypeVariableBinding)castType).upperBound(), expressionType, expression);

        default:
          // ( CLASS/INTERFACE ) ARRAY
          switch (castType.id) {
            case T_JavaLangCloneable :
            case T_JavaIoSerializable :
              tagAsNeedCheckCast();
              return true;
            case T_JavaLangObject :
              tagAsUnnecessaryCast(scope, castType);
              return true;
            default :
              return false;
          }
      }

    case Binding.TYPE_PARAMETER :
      TypeBinding match = expressionType.findSuperTypeOriginatingFrom(castType);
      if (match != null) {
        return checkUnsafeCast(scope, castType, expressionType, match, false);
      }
      // recursively on the type variable upper bound
      return checkCastTypesCompatibility(scope, castType, ((TypeVariableBinding)expressionType).upperBound(), expression);
View Full Code Here


  // it is possible for a Byte to be unboxed to a byte & then converted to an int
  // but it is not possible for a byte to become Byte & then assigned to an Integer,
  // or to become an int before boxed into an Integer
  if (runtimeType != TypeBinding.NULL && runtimeType.isBaseType()) {
    if (!compileTimeType.isBaseType()) {
      TypeBinding unboxedType = scope.environment().computeBoxingType(compileTimeType);
      this.implicitConversion = TypeIds.UNBOXING;
      scope.problemReporter().autoboxing(this, compileTimeType, runtimeType);
      compileTimeType = unboxedType;
    }
  } else if (compileTimeType != TypeBinding.NULL && compileTimeType.isBaseType()) {
    TypeBinding boxedType = scope.environment().computeBoxingType(runtimeType);
    if (boxedType == runtimeType) // Object o = 12;
      boxedType = compileTimeType;
    this.implicitConversion = TypeIds.BOXING | (boxedType.id << 4) + compileTimeType.id;
    scope.problemReporter().autoboxing(this, compileTimeType, scope.environment().computeBoxingType(boxedType));
    return;
View Full Code Here

* or inserted a generic cast, the converted type will differ from the resolved type (surface side-effects from
* #computeConversion(...)).
* @return the type after implicit conversion
*/
public TypeBinding postConversionType(Scope scope) {
  TypeBinding convertedType = this.resolvedType;
  int runtimeType = (this.implicitConversion & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4;
  switch (runtimeType) {
    case T_boolean :
      convertedType = TypeBinding.BOOLEAN;
      break;
View Full Code Here

  return null;
}

public TypeBinding resolveTypeExpecting(BlockScope scope, TypeBinding expectedType) {
  setExpectedType(expectedType); // needed in case of generic method invocation
  TypeBinding expressionType = this.resolveType(scope);
  if (expressionType == null) return null;
  if (expressionType == expectedType) return expressionType;

  if (!expressionType.isCompatibleWith(expectedType)) {
    if (scope.isBoxingCompatibleWith(expressionType, expectedType)) {
      computeConversion(scope, expectedType, expressionType);
    } else {
      scope.problemReporter().typeMismatchError(expressionType, expectedType, this, null);
      return null;
View Full Code Here

      return (JavaElement)this.nodesWithProblemsToHandles.get(node);
    }
  }

  private TypeBinding getTypeFromSignature(String typeSignature, Scope scope) {
    TypeBinding assignableTypeBinding = null;

    TypeVariableBinding[] typeVariables = Binding.NO_TYPE_VARIABLES;
    ReferenceContext referenceContext = scope.referenceContext();
    if (referenceContext instanceof AbstractMethodDeclaration) {
      AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
View Full Code Here

    if (!this.hasComputedVisibleElementBindings) {
      computeVisibleElementBindings();
    }

    TypeBinding assignableTypeBinding = null;
    if (typeSignature != null) {
      assignableTypeBinding = getTypeFromSignature(typeSignature, this.assistScope);
      if (assignableTypeBinding == null) return new IJavaElement[0];
    }
View Full Code Here

      }
    }
  }

  public boolean canUseDiamond(String[] parameterTypes, char[] fullyQualifiedTypeName) {
    TypeBinding guessedType = null;
    char[][] cn = CharOperation.splitOn('.', fullyQualifiedTypeName);
    Scope scope = this.assistScope;
    if (scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_7) return false;
    // If no LHS or return type expected, then we can safely use diamond
    char[][] expectedTypekeys= this.completionContext.getExpectedTypesKeys();
    if (expectedTypekeys == null || expectedTypekeys.length == 0)
      return true;
    // Next, find out whether any of the constructor parameters are the same as one of the
    // class type variables. If yes, diamond cannot be used.
    TypeReference ref;
    if (cn.length == 1) {
      ref = new SingleTypeReference(cn[0], 0);
    } else {
      ref = new QualifiedTypeReference(cn,new long[cn.length]);
    }
    switch (scope.kind) {
      case Scope.METHOD_SCOPE :
      case Scope.BLOCK_SCOPE :
        guessedType = ref.resolveType((BlockScope)scope);
        break;
      case Scope.CLASS_SCOPE :
        guessedType = ref.resolveType((ClassScope)scope);
        break;
    }
    if (guessedType != null && guessedType.isValidBinding()) {
      // the erasure must be used because guessedType can be a RawTypeBinding
      guessedType = guessedType.erasure();
      TypeVariableBinding[] typeVars = guessedType.typeVariables();
      for (int i = 0; i < parameterTypes.length; i++) {
        for (int j = 0; j < typeVars.length; j++) {
          if (CharOperation.equals(parameterTypes[i].toCharArray(), typeVars[j].sourceName))
            return false;
        }
View Full Code Here

    // Propagate the type checking to the arguments, and checks if the constructor is defined.
    // ClassInstanceCreationExpression ::= Primary '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt
    // ClassInstanceCreationExpression ::= Name '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt

    this.constant = Constant.NotAConstant;
    TypeBinding enclosingInstanceType = null;
    ReferenceBinding enclosingInstanceReference = null;
    TypeBinding receiverType = null;
    boolean hasError = false;
    boolean enclosingInstanceContainsCast = false;
    boolean argsContainCast = false;

    if (this.enclosingInstance != null) {
      if (this.enclosingInstance instanceof CastExpression) {
        this.enclosingInstance.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
        enclosingInstanceContainsCast = true;
      }
      if ((enclosingInstanceType = this.enclosingInstance.resolveType(scope)) == null){
        hasError = true;
      } else if (enclosingInstanceType.isBaseType() || enclosingInstanceType.isArrayType()) {
        scope.problemReporter().illegalPrimitiveOrArrayTypeForEnclosingInstance(
          enclosingInstanceType,
          this.enclosingInstance);
        hasError = true;
      } else if (this.type instanceof QualifiedTypeReference) {
        scope.problemReporter().illegalUsageOfQualifiedTypeReference((QualifiedTypeReference)this.type);
        hasError = true;
      } else if (!(enclosingInstanceReference = (ReferenceBinding) enclosingInstanceType).canBeSeenBy(scope)) {
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=317212
        enclosingInstanceType = new ProblemReferenceBinding(
              enclosingInstanceReference.compoundName,
              enclosingInstanceReference,
              ProblemReasons.NotVisible);
        scope.problemReporter().invalidType(this.enclosingInstance, enclosingInstanceType);
        hasError = true;
      } else {
        receiverType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingInstanceType);
        if (receiverType != null && enclosingInstanceContainsCast) {
          CastExpression.checkNeedForEnclosingInstanceCast(scope, this.enclosingInstance, enclosingInstanceType, receiverType);
        }
      }
    } else {
      if (this.type == null) {
        // initialization of an enum constant
        receiverType = scope.enclosingSourceType();
      } else {
        receiverType = this.type.resolveType(scope, true /* check bounds*/);
        checkParameterizedAllocation: {
          if (receiverType == null || !receiverType.isValidBinding()) break checkParameterizedAllocation;
          if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
            ReferenceBinding currentType = (ReferenceBinding)receiverType;
            do {
              // isStatic() is answering true for toplevel types
              if ((currentType.modifiers & ClassFileConstants.AccStatic) != 0) break checkParameterizedAllocation;
              if (currentType.isRawType()) break checkParameterizedAllocation;
            } while ((currentType = currentType.enclosingType())!= null);
            ParameterizedQualifiedTypeReference qRef = (ParameterizedQualifiedTypeReference) this.type;
            for (int i = qRef.typeArguments.length - 2; i >= 0; i--) {
              if (qRef.typeArguments[i] != null) {
                scope.problemReporter().illegalQualifiedParameterizedTypeAllocation(this.type, receiverType);
                break;
              }
            }
          }
        }
      }
    }
    if (receiverType == null || !receiverType.isValidBinding()) {
      hasError = true;
    }

    // resolve type arguments (for generic constructor call)
    final boolean isDiamond = this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0;
    if (this.typeArguments != null) {
      int length = this.typeArguments.length;
      boolean argHasError = scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_5;
      this.genericTypeArguments = new TypeBinding[length];
      for (int i = 0; i < length; i++) {
        TypeReference typeReference = this.typeArguments[i];
        if ((this.genericTypeArguments[i] = typeReference.resolveType(scope, true /* check bounds*/)) == null) {
          argHasError = true;
        }
        if (argHasError && typeReference instanceof Wildcard) {
          scope.problemReporter().illegalUsageOfWildcard(typeReference);
        }
      }
      if (isDiamond) {
        scope.problemReporter().diamondNotWithExplicitTypeArguments(this.typeArguments);
        return null;
      }
      if (argHasError) {
        if (this.arguments != null) { // still attempt to resolve arguments
          for (int i = 0, max = this.arguments.length; i < max; i++) {
            this.arguments[i].resolveType(scope);
          }
        }
        return null;
      }
    }

    // will check for null after args are resolved
    TypeBinding[] argumentTypes = Binding.NO_PARAMETERS;
    if (this.arguments != null) {
      int length = this.arguments.length;
      argumentTypes = new TypeBinding[length];
      for (int i = 0; i < length; i++) {
        Expression argument = this.arguments[i];
        if (argument instanceof CastExpression) {
          argument.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
          argsContainCast = true;
        }
        if ((argumentTypes[i] = argument.resolveType(scope)) == null){
          hasError = true;
        }
      }
    }

    // limit of fault-tolerance
    if (hasError) {
      /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=345359, if arguments have errors, completely bail out in the <> case.
         No meaningful type resolution is possible since inference of the elided types is fully tied to argument types. Do
         not return the partially resolved type.
       */
      if (isDiamond) {
        return null; // not the partially cooked this.resolvedType
      }
      if (receiverType instanceof ReferenceBinding) {
        ReferenceBinding referenceReceiver = (ReferenceBinding) receiverType;
        if (receiverType.isValidBinding()) {
          // record a best guess, for clients who need hint about possible contructor match
          int length = this.arguments  == null ? 0 : this.arguments.length;
          TypeBinding[] pseudoArgs = new TypeBinding[length];
          for (int i = length; --i >= 0;) {
            pseudoArgs[i] = argumentTypes[i] == null ? TypeBinding.NULL : argumentTypes[i]; // replace args with errors with null type
          }
          this.binding = scope.findMethod(referenceReceiver, TypeConstants.INIT, pseudoArgs, this);
          if (this.binding != null && !this.binding.isValidBinding()) {
            MethodBinding closestMatch = ((ProblemMethodBinding)this.binding).closestMatch;
            // record the closest match, for clients who may still need hint about possible method match
            if (closestMatch != null) {
              if (closestMatch.original().typeVariables != Binding.NO_TYPE_VARIABLES) { // generic method
                // shouldn't return generic method outside its context, rather convert it to raw method (175409)
                closestMatch = scope.environment().createParameterizedGenericMethod(closestMatch.original(), (RawTypeBinding)null);
              }
              this.binding = closestMatch;
              MethodBinding closestMatchOriginal = closestMatch.original();
              if (closestMatchOriginal.isOrEnclosedByPrivateType() && !scope.isDefinedInMethod(closestMatchOriginal)) {
                // ignore cases where method is used from within inside itself (e.g. direct recursions)
                closestMatchOriginal.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
              }
            }
          }
        }
        if (this.anonymousType != null) {
          // insert anonymous type in scope (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=210070)
          scope.addAnonymousType(this.anonymousType, referenceReceiver);
          this.anonymousType.resolve(scope);
          return this.resolvedType = this.anonymousType.binding;
        }
      }
      return this.resolvedType = receiverType;
    }
    if (this.anonymousType == null) {
      // qualified allocation with no anonymous type
      if (!receiverType.canBeInstantiated()) {
        scope.problemReporter().cannotInstantiate(this.type, receiverType);
        return this.resolvedType = receiverType;
      }
      if (isDiamond) {
        TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) receiverType).genericType(), receiverType.enclosingType(), argumentTypes, scope);
        if (inferredTypes == null) {
          scope.problemReporter().cannotInferElidedTypes(this);
          return this.resolvedType = null;
        }
        receiverType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) receiverType).genericType(), inferredTypes, ((ParameterizedTypeBinding) receiverType).enclosingType());
      }
      ReferenceBinding allocationType = (ReferenceBinding) receiverType;
      if ((this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) {
        if (isMethodUseDeprecated(this.binding, scope, true)) {
          scope.problemReporter().deprecatedMethod(this.binding, this);
        }
        if (checkInvocationArguments(scope, null, allocationType, this.binding, this.arguments, argumentTypes, argsContainCast, this)) {
          this.bits |= ASTNode.Unchecked;
        }
        if (this.typeArguments != null && this.binding.original().typeVariables == Binding.NO_TYPE_VARIABLES) {
          scope.problemReporter().unnecessaryTypeArgumentsForMethodInvocation(this.binding, this.genericTypeArguments, this.typeArguments);
        }
      } else {
        if (this.binding.declaringClass == null) {
          this.binding.declaringClass = allocationType;
        }
        if (this.type != null && !this.type.resolvedType.isValidBinding()) {
          // problem already got signaled on type reference, do not report secondary problem
          return null;
        }
        scope.problemReporter().invalidConstructor(this, this.binding);
        return this.resolvedType = receiverType;
      }
      if ((this.binding.tagBits & TagBits.HasMissingType) != 0) {
        scope.problemReporter().missingTypeInConstructor(this, this.binding);
      }
      if (!isDiamond && receiverType.isParameterizedTypeWithActualArguments()) {
         checkTypeArgumentRedundancy((ParameterizedTypeBinding)receiverType, receiverType.enclosingType(), argumentTypes , scope);
       }
      // The enclosing instance must be compatible with the innermost enclosing type
      ReferenceBinding expectedType = this.binding.declaringClass.enclosingType();
      if (expectedType != enclosingInstanceType) // must call before computeConversion() and typeMismatchError()
        scope.compilationUnitScope().recordTypeConversion(expectedType, enclosingInstanceType);
View Full Code Here

  if (runtimeTimeType == null || compileTimeType == null)
    return;
  // set the generic cast after the fact, once the type expectation is fully known (no need for strict cast)
  if (this.binding != null && this.binding.isValidBinding()) {
    MethodBinding originalBinding = this.binding.original();
    TypeBinding originalType = originalBinding.returnType;
      // extra cast needed if method return type is type variable
    if (originalType.leafComponentType().isTypeVariable()) {
        TypeBinding targetType = (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
          ? compileTimeType  // unboxing: checkcast before conversion
          : runtimeTimeType;
          this.valueCast = originalType.genericCast(targetType);
    }   else if (this.binding == scope.environment().arrayClone
        && runtimeTimeType.id != TypeIds.T_JavaLangObject
View Full Code Here

  // generate arguments
  generateArguments(this.binding, this.arguments, currentScope, codeStream);
  pc = codeStream.position;
  // actual message invocation
  if (this.syntheticAccessor == null){
    TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenBinding, this.actualReceiverType, this.receiver.isImplicitThis());
    if (isStatic){
      codeStream.invoke(Opcodes.OPC_invokestatic, codegenBinding, constantPoolDeclaringClass);
    } else if((this.receiver.isSuper()) || codegenBinding.isPrivate()){
      codeStream.invoke(Opcodes.OPC_invokespecial, codegenBinding, constantPoolDeclaringClass);
    } else if (constantPoolDeclaringClass.isInterface()) { // interface or annotation type
      codeStream.invoke(Opcodes.OPC_invokeinterface, codegenBinding, constantPoolDeclaringClass);
    } else {
      codeStream.invoke(Opcodes.OPC_invokevirtual, codegenBinding, constantPoolDeclaringClass);
    }
  } else {
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.