public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingType) {
   TypeBinding memberType = this.resolvedType = scope.getMemberType(this.token, enclosingType);
   boolean hasError = false;
   if (!memberType.isValidBinding()) {
     hasError = true;
     scope.problemReporter().invalidEnclosingType(this, memberType, enclosingType);
     memberType = ((ReferenceBinding) memberType).closestMatch();
     if (memberType == null) {
       return null;
     }
   }
   if (isTypeUseDeprecated(memberType, scope)) reportDeprecatedType(memberType, scope);
   memberType =
       scope
           .environment()
           .convertToRawType(memberType, false /*do not force conversion of enclosing types*/);
   if (memberType.isRawType()
       && (this.bits & IgnoreRawTypeCheck) == 0
       && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference)
           != ProblemSeverities.Ignore) {
     scope.problemReporter().rawTypeReference(this, memberType);
   }
   if (hasError) {
     // do not store the computed type, keep the problem type instead
     return memberType;
   }
   return this.resolvedType = memberType;
 }
 /**
  * @see
  *     org.eclipse.che.ide.ext.java.jdt.internal.compiler.ast.Expression#computeConversion(org.eclipse.che.ide.ext.java.jdt.internal.compiler.lookup.Scope,
  *     org.eclipse.che.ide.ext.java.jdt.internal.compiler.lookup.TypeBinding,
  *     org.eclipse.che.ide.ext.java.jdt.internal.compiler.lookup .TypeBinding)
  */
 public void computeConversion(
     Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) {
   if (runtimeTimeType == null || compileTimeType == null) return;
   if ((this.bits & Binding.FIELD) != 0 && this.binding != null && this.binding.isValidBinding()) {
     // set the generic cast after the fact, once the type expectation is fully known (no need for
     // strict cast)
     FieldBinding field = (FieldBinding) this.binding;
     FieldBinding originalBinding = field.original();
     TypeBinding originalType = originalBinding.type;
     // extra cast needed if field type is type variable
     if (originalType.leafComponentType().isTypeVariable()) {
       TypeBinding targetType =
           (!compileTimeType.isBaseType() && runtimeTimeType.isBaseType())
               ? compileTimeType
               // unboxing: checkcast before conversion
               : runtimeTimeType;
       this.genericCast = originalType.genericCast(scope.boxing(targetType));
       if (this.genericCast instanceof ReferenceBinding) {
         ReferenceBinding referenceCast = (ReferenceBinding) this.genericCast;
         if (!referenceCast.canBeSeenBy(scope)) {
           scope
               .problemReporter()
               .invalidType(
                   this,
                   new ProblemReferenceBinding(
                       CharOperation.splitOn('.', referenceCast.shortReadableName()),
                       referenceCast,
                       ProblemReasons.NotVisible));
         }
       }
     }
   }
   super.computeConversion(scope, runtimeTimeType, compileTimeType);
 }
Example #3
0
 public TypeBinding resolveType(BlockScope scope) {
   this.constant = Constant.NotAConstant;
   if (this.receiver instanceof CastExpression // no cast check for ((type[])null)[0]
       && ((CastExpression) this.receiver).innermostCastedExpression() instanceof NullLiteral) {
     this.receiver.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on
   }
   TypeBinding arrayType = this.receiver.resolveType(scope);
   if (arrayType != null) {
     this.receiver.computeConversion(scope, arrayType, arrayType);
     if (arrayType.isArrayType()) {
       TypeBinding elementType = ((ArrayBinding) arrayType).elementsType();
       this.resolvedType =
           ((this.bits & ASTNode.IsStrictlyAssigned) == 0)
               ? elementType.capture(scope, this.sourceEnd)
               : elementType;
     } else {
       scope.problemReporter().referenceMustBeArrayTypeAt(arrayType, this);
     }
   }
   TypeBinding positionType = this.position.resolveTypeExpecting(scope, TypeBinding.INT);
   if (positionType != null) {
     this.position.computeConversion(scope, TypeBinding.INT, positionType);
   }
   return this.resolvedType;
 }
Example #4
0
  public TypeBinding resolveForCatch(BlockScope scope) {
    // resolution on an argument of a catch clause
    // provide the scope with a side effect : insertion of a LOCAL
    // that represents the argument. The type must be from JavaThrowable

    TypeBinding exceptionType = this.type.resolveType(scope, true /* check bounds*/);
    boolean hasError;
    if (exceptionType == null) {
      hasError = true;
    } else {
      hasError = false;
      switch (exceptionType.kind()) {
        case Binding.PARAMETERIZED_TYPE:
          if (exceptionType.isBoundParameterizedType()) {
            hasError = true;
            scope.problemReporter().invalidParameterizedExceptionType(exceptionType, this);
            // fall thru to create the variable - avoids additional errors because the variable is
            // missing
          }
          break;
        case Binding.TYPE_PARAMETER:
          scope.problemReporter().invalidTypeVariableAsException(exceptionType, this);
          hasError = true;
          // fall thru to create the variable - avoids additional errors because the variable is
          // missing
          break;
      }
      if (exceptionType.findSuperTypeOriginatingFrom(TypeIds.T_JavaLangThrowable, true) == null
          && exceptionType.isValidBinding()) {
        scope.problemReporter().cannotThrowType(this.type, exceptionType);
        hasError = true;
        // fall thru to create the variable - avoids additional errors because the variable is
        // missing
      }
    }
    Binding existingVariable =
        scope.getBinding(this.name, Binding.VARIABLE, this, false /*do not resolve hidden field*/);
    if (existingVariable != null && existingVariable.isValidBinding()) {
      if (existingVariable instanceof LocalVariableBinding && this.hiddenVariableDepth == 0) {
        scope.problemReporter().redefineArgument(this);
      } else {
        scope.problemReporter().localVariableHiding(this, existingVariable, false);
      }
    }

    if ((this.type.bits & ASTNode.IsUnionType) != 0) {
      this.binding =
          new CatchParameterBinding(
              this,
              exceptionType,
              this.modifiers | ClassFileConstants.AccFinal,
              false); // argument decl, but local var  (where isArgument = false)
      this.binding.tagBits |= TagBits.MultiCatchParameter;
    } else {
      this.binding =
          new CatchParameterBinding(
              this,
              exceptionType,
              this.modifiers,
              false); // argument decl, but local var  (where isArgument = false)
    }
    resolveAnnotations(scope, this.annotations, this.binding);

    scope.addLocalVariable(this.binding);
    this.binding.setConstant(Constant.NotAConstant);
    if (hasError) return null;
    return exceptionType;
  }
  @Override
  public TypeBinding resolveType(BlockScope scope) {
    boolean expressionIsCast;
    if ((expressionIsCast = this.expression instanceof CastExpression) == true) {
      this.expression.bits |= DisableUnnecessaryCastCheck; // will check later on
    }
    TypeBinding expressionType = this.expression.resolveType(scope);
    if (expressionType == null) {
      this.constant = Constant.NotAConstant;
      return null;
    }
    int expressionTypeID = expressionType.id;
    // autoboxing support
    boolean use15specifics = scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5;
    if (use15specifics) {
      if (!expressionType.isBaseType()) {
        expressionTypeID = scope.environment().computeBoxingType(expressionType).id;
      }
    }
    if (expressionTypeID > 15) {
      this.constant = Constant.NotAConstant;
      scope.problemReporter().invalidOperator(this, expressionType);
      return null;
    }

    int tableId;
    switch ((this.bits & OperatorMASK) >> OperatorSHIFT) {
      case NOT:
        tableId = AND_AND;
        break;
      case TWIDDLE:
        tableId = LEFT_SHIFT;
        break;
      default:
        tableId = MINUS;
    } // + and - cases

    // the code is an int
    // (cast)  left   Op (cast)  rigth --> result
    //  0000   0000       0000   0000      0000
    //  <<16   <<12       <<8    <<4       <<0
    int operatorSignature = OperatorSignatures[tableId][(expressionTypeID << 4) + expressionTypeID];
    this.expression.computeConversion(
        scope,
        TypeBinding.wellKnownType(scope, (operatorSignature >>> 16) & 0x0000F),
        expressionType);
    this.bits |= operatorSignature & 0xF;
    switch (operatorSignature & 0xF) { // only switch on possible result type.....
      case T_boolean:
        this.resolvedType = TypeBinding.BOOLEAN;
        break;
      case T_byte:
        this.resolvedType = TypeBinding.BYTE;
        break;
      case T_char:
        this.resolvedType = TypeBinding.CHAR;
        break;
      case T_double:
        this.resolvedType = TypeBinding.DOUBLE;
        break;
      case T_float:
        this.resolvedType = TypeBinding.FLOAT;
        break;
      case T_int:
        this.resolvedType = TypeBinding.INT;
        break;
      case T_long:
        this.resolvedType = TypeBinding.LONG;
        break;
      default: // error........
        this.constant = Constant.NotAConstant;
        if (expressionTypeID != T_undefined) {
          scope.problemReporter().invalidOperator(this, expressionType);
        }
        return null;
    }
    // compute the constant when valid
    if (this.expression.constant != Constant.NotAConstant) {
      this.constant =
          Constant.computeConstantOperation(
              this.expression.constant,
              expressionTypeID,
              (this.bits & OperatorMASK) >> OperatorSHIFT);
    } else {
      this.constant = Constant.NotAConstant;
      if (((this.bits & OperatorMASK) >> OperatorSHIFT) == NOT) {
        Constant cst = this.expression.optimizedBooleanConstant();
        if (cst != Constant.NotAConstant) {
          this.optimizedBooleanConstant = BooleanConstant.fromValue(!cst.booleanValue());
        }
      }
    }
    if (expressionIsCast) {
      // check need for operand cast
      CastExpression.checkNeedForArgumentCast(
          scope, tableId, operatorSignature, this.expression, expressionTypeID);
    }
    return this.resolvedType;
  }
  public TypeBinding resolveType(BlockScope scope) {
    // for code gen, harm the restrictiveFlag

    if (this.actualReceiverType != null) {
      this.binding = scope.getField(this.actualReceiverType, this.token, this);
    } else {
      this.actualReceiverType = scope.enclosingSourceType();
      this.binding =
          scope.getBinding(
              this.token, this.bits & ASTNode.RestrictiveFlagMASK, this, true /*resolve*/);
    }
    if (this.binding.isValidBinding()) {
      switch (this.bits & ASTNode.RestrictiveFlagMASK) {
        case Binding.VARIABLE: // =========only variable============
        case Binding.VARIABLE | Binding.TYPE: // ====both variable and type============
          if (this.binding instanceof VariableBinding) {
            VariableBinding variable = (VariableBinding) this.binding;
            TypeBinding variableType;
            if (this.binding instanceof LocalVariableBinding) {
              this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
              this.bits |= Binding.LOCAL;
              if (!variable.isFinal() && (this.bits & ASTNode.DepthMASK) != 0) {
                scope
                    .problemReporter()
                    .cannotReferToNonFinalOuterLocal((LocalVariableBinding) variable, this);
              }
              variableType = variable.type;
              this.constant =
                  (this.bits & ASTNode.IsStrictlyAssigned) == 0
                      ? variable.constant()
                      : Constant.NotAConstant;
            } else {
              // a field
              variableType = checkFieldAccess(scope);
            }
            // perform capture conversion if read access
            if (variableType != null) {
              this.resolvedType =
                  variableType =
                      (((this.bits & ASTNode.IsStrictlyAssigned) == 0)
                          ? variableType.capture(scope, this.sourceEnd)
                          : variableType);
              if ((variableType.tagBits & TagBits.HasMissingType) != 0) {
                if ((this.bits & Binding.LOCAL) == 0) {
                  // only complain if field reference (for local, its type got flagged already)
                  scope.problemReporter().invalidType(this, variableType);
                }
                return null;
              }
            }
            return variableType;
          }

          // thus it was a type
          this.bits &= ~ASTNode.RestrictiveFlagMASK; // clear bits
          this.bits |= Binding.TYPE;
          // $FALL-THROUGH$
        case Binding.TYPE: // ========only type==============
          this.constant = Constant.NotAConstant;
          // deprecated test
          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;
      }
    }
    // error scenarii
    return this.resolvedType = reportError(scope);
  }