Example usage for org.eclipse.jdt.internal.compiler.ast CastExpression CastExpression

List of usage examples for org.eclipse.jdt.internal.compiler.ast CastExpression CastExpression

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast CastExpression CastExpression.

Prototype

public CastExpression(Expression expression, TypeReference type) 

Source Link

Usage

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeCastExpressionLL1() {
    //CastExpression ::= '(' Expression ')' InsideCastExpressionLL1 UnaryExpressionNotPlusMinus
    // Expression is used in order to make the grammar LL1

    //optimize push/pop

    Expression cast;//from   w  w  w . jav a2 s  . c  om
    Expression exp;
    this.expressionPtr--;
    this.expressionStack[this.expressionPtr] = cast = new CastExpression(
            exp = this.expressionStack[this.expressionPtr + 1],
            (TypeReference) this.expressionStack[this.expressionPtr]);
    this.expressionLengthPtr--;
    updateSourcePosition(cast);
    cast.sourceEnd = exp.sourceEnd;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeCastExpressionWithGenericsArray() {
    // CastExpression ::= PushLPAREN Name TypeArguments Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus

    Expression exp;/*w  ww . j  a  v a 2  s  .com*/
    Expression cast;
    TypeReference castType;
    int end = this.intStack[this.intPtr--];

    int dim = this.intStack[this.intPtr--];
    pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);

    this.expressionStack[this.expressionPtr] = cast = new CastExpression(
            exp = this.expressionStack[this.expressionPtr], castType = getTypeReference(dim));
    this.intPtr--;
    castType.sourceEnd = end - 1;
    castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1;
    cast.sourceEnd = exp.sourceEnd;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeCastExpressionWithNameArray() {
    // CastExpression ::= PushLPAREN Name Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus

    Expression exp;//from  w w  w .  j a  v  a 2 s  .com
    Expression cast;
    TypeReference castType;
    int end = this.intStack[this.intPtr--];

    // handle type arguments
    pushOnGenericsLengthStack(0);
    pushOnGenericsIdentifiersLengthStack(this.identifierLengthStack[this.identifierLengthPtr]);

    this.expressionStack[this.expressionPtr] = cast = new CastExpression(
            exp = this.expressionStack[this.expressionPtr],
            castType = getTypeReference(this.intStack[this.intPtr--]));
    castType.sourceEnd = end - 1;
    castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1;
    cast.sourceEnd = exp.sourceEnd;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeCastExpressionWithPrimitiveType() {
    // CastExpression ::= PushLPAREN PrimitiveType Dimsopt PushRPAREN InsideCastExpression UnaryExpression

    //this.intStack : posOfLeftParen dim posOfRightParen

    //optimize the push/pop

    Expression exp;//from w  ww. j  a  va 2s  .c  om
    Expression cast;
    TypeReference castType;
    int end = this.intStack[this.intPtr--];
    this.expressionStack[this.expressionPtr] = cast = new CastExpression(
            exp = this.expressionStack[this.expressionPtr],
            castType = getTypeReference(this.intStack[this.intPtr--]));
    castType.sourceEnd = end - 1;
    castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1;
    cast.sourceEnd = exp.sourceEnd;
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

protected void consumeCastExpressionWithQualifiedGenericsArray() {
    // CastExpression ::= PushLPAREN Name OnlyTypeArguments '.' ClassOrInterfaceType Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus
    Expression exp;/*from   w w w.  java 2  s .c  om*/
    Expression cast;
    TypeReference castType;
    int end = this.intStack[this.intPtr--];

    int dim = this.intStack[this.intPtr--];
    TypeReference rightSide = getTypeReference(0);

    ParameterizedQualifiedTypeReference qualifiedParameterizedTypeReference = computeQualifiedGenericsFromRightSide(
            rightSide, dim);
    this.intPtr--;
    this.expressionStack[this.expressionPtr] = cast = new CastExpression(
            exp = this.expressionStack[this.expressionPtr], castType = qualifiedParameterizedTypeReference);
    castType.sourceEnd = end - 1;
    castType.sourceStart = (cast.sourceStart = this.intStack[this.intPtr--]) + 1;
    cast.sourceEnd = exp.sourceEnd;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PotentialTranslationExpression.java

License:Open Source License

/**
 * Check whether rawType is already compatible perhaps using basic type conversion
 * @param scope//  w w w .jav  a 2 s  .c  o m
 * @param rawType
 * @return the compatible type
 */
protected TypeBinding compatibleType(BlockScope scope, TypeBinding rawType) {
    // save and reset flags:
    Config oldConfig = Config.createOrResetConfig(this);

    try {
        if (areTypesCompatible(rawType, this.expectedType)) {
            if (!Config.requireTypeAdjustment()) {
                // TODO (SH) is conversion of arrays of base type allowed?
                TypeBinding resultType = this.resolvedType; // default
                if (this.resolvedType.isBaseType()) {
                    if (TypeBinding.notEquals(rawType, this.expectedType)) {
                        this.rawExpression = this.expression;
                        this.rawExpression.computeConversion(scope, rawType, rawType); // null conversion.

                        this.expression = new CastExpression(this.expression,
                                TypeReference.baseTypeReference(this.expectedType.id, 0, null));
                        this.expression.constant = Constant.NotAConstant;
                        ((CastExpression) this.expression).checkCastTypesCompatibility(scope, this.expectedType,
                                rawType, this.expression);
                        this.operator = "(convert to " + new String(this.expectedType.readableName()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
                        resultType = this.expectedType;
                    }
                }
                if (BaseTypeBinding.isWidening(this.expectedType.id, rawType.id)
                        && this.expression.constant != Constant.NotAConstant)
                    this.expression.computeConversion(scope, this.expectedType, rawType);
                return resultType;
            }
        }
    } finally {
        // restore on any exit:
        Config.removeOrRestore(oldConfig, this);
    }
    return null;
}