/* (non-Javadoc)
  * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.CastExpression)
  */
 public boolean visit(CastExpression node) {
   PTCastExpression ct = InstantiationFactory.eINSTANCE.createPTCastExpression();
   ct.setType(resolver.resolveType(node.getType()));
   ct.setExpression(perform(node.getExpression()));
   expression = ct;
   return false;
 }
 /*
  * @see ASTVisitor#visit(CastExpression)
  */
 @Override
 public boolean visit(CastExpression node) {
   this.fBuffer.append("("); // $NON-NLS-1$
   node.getType().accept(this);
   this.fBuffer.append(")"); // $NON-NLS-1$
   node.getExpression().accept(this);
   return false;
 }
Example #3
0
 public boolean visit(CastExpression s) throws Exception {
   Map<String, String> parameters = createInitialParameters(s);
   parameters.put("type", CastExpression.getCastType(s.getCastType()));
   xmlWriter.startTag("CastExpression", parameters);
   return true;
 }
 private Class<?> jitCastExpression(CastExpression exp) {
   jitExpression(exp.expression, Object.class);
   cast(exp.getType());
   return exp.getType();
 }
  @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 void visitCastExpression(CastExpression expression) {
   expression.getExpression().visit(this);
 }