Example usage for org.eclipse.jdt.core.dom ConditionalExpression THEN_EXPRESSION_PROPERTY

List of usage examples for org.eclipse.jdt.core.dom ConditionalExpression THEN_EXPRESSION_PROPERTY

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ConditionalExpression THEN_EXPRESSION_PROPERTY.

Prototype

ChildPropertyDescriptor THEN_EXPRESSION_PROPERTY

To view the source code for org.eclipse.jdt.core.dom ConditionalExpression THEN_EXPRESSION_PROPERTY.

Click Source Link

Document

The "thenExpression" structural property of this node type (child type: Expression ).

Usage

From source file:org.moe.natjgen.FieldEditor.java

License:Apache License

public void setInitializer(Type type, long const64, long const32) throws NotEditableException {
    editLock();/*from w ww  .ja va 2 s  .  c om*/

    Expression v64 = getExpressionForConstantValue(type.getKind(), const64);
    Expression v32;
    if (type.getDowngradeAnnotation() == null) {
        v32 = getExpressionForConstantValue(type.getKind(), const32);
    } else if (Constants.NIntAnnotationFQ.equals(type.getDowngradeAnnotation())) {
        v32 = getExpressionForConstantValue(type.getKind(), const32);
    } else if (Constants.NUIntAnnotationFQ.equals(type.getDowngradeAnnotation())) {
        v32 = getExpressionForConstantValue(type.getKind(), const32);
    } else if (Constants.NFloatAnnotationFQ.equals(type.getDowngradeAnnotation())) {
        v32 = getExpressionForConstantValue(Type.Float, const32);
    } else {
        throw new IllegalStateException();
    }

    /**
     * <NatJFQ>
     */
    Name objc_runtime = getAST().newName(Constants.NatJFQ);

    /**
     * <NatJFQ>.is64Bit()
     */
    MethodInvocation assoc_inv = getAST().newMethodInvocation();
    getRewrite().set(assoc_inv, MethodInvocation.EXPRESSION_PROPERTY, objc_runtime, getEditGroup());
    getRewrite().set(assoc_inv, MethodInvocation.NAME_PROPERTY, getAST().newName("is64Bit"), getEditGroup());

    /**
     * <NatJFQ>.is64Bit() ? <v64> : <v32>
     */
    ConditionalExpression cond = getAST().newConditionalExpression();
    getRewrite().set(cond, ConditionalExpression.EXPRESSION_PROPERTY, assoc_inv, getEditGroup());
    getRewrite().set(cond, ConditionalExpression.THEN_EXPRESSION_PROPERTY, v64, getEditGroup());
    getRewrite().set(cond, ConditionalExpression.ELSE_EXPRESSION_PROPERTY, v32, getEditGroup());

    /**
     * Add additional casting required by byte, short and char
     */
    if (type.getKind() == Type.Byte || type.getKind() == Type.Short || type.getKind() == Type.Char) {
        CastExpression cast = getAST().newCastExpression();
        if (type.getKind() == Type.Byte) {
            cast.setType(getAST().newPrimitiveType(PrimitiveType.BYTE));
        } else if (type.getKind() == Type.Short) {
            cast.setType(getAST().newPrimitiveType(PrimitiveType.SHORT));
        } else if (type.getKind() == Type.Char) {
            cast.setType(getAST().newPrimitiveType(PrimitiveType.CHAR));
        } else {
            throw new IllegalStateException();
        }
        ParenthesizedExpression parenthesized = getAST().newParenthesizedExpression();
        parenthesized.setExpression(cond);
        cast.setExpression(parenthesized);
        getRewrite().set(getFirstFragment(), VariableDeclarationFragment.INITIALIZER_PROPERTY, cast,
                getEditGroup());
    } else {
        getRewrite().set(getFirstFragment(), VariableDeclarationFragment.INITIALIZER_PROPERTY, cond,
                getEditGroup());
    }
}