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

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

Introduction

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

Prototype

public Expression getElseExpression() 

Source Link

Document

Returns the "else" part of this conditional expression.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(ConditionalExpression node) {
    node.getExpression().accept(this);
    this.fBuffer.append("?");//$NON-NLS-1$
    node.getThenExpression().accept(this);
    this.fBuffer.append(":");//$NON-NLS-1$
    node.getElseExpression().accept(this);
    return false;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(ConditionalExpression node) {
    boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder();
    //      b.setPosition(pos.build());
    b.setKind(boa.types.Ast.Expression.ExpressionKind.CONDITIONAL);
    node.getExpression().accept(this);
    b.addExpressions(expressions.pop());
    node.getThenExpression().accept(this);
    b.addExpressions(expressions.pop());
    node.getElseExpression().accept(this);
    b.addExpressions(expressions.pop());
    expressions.push(b.build());// w  ww . ja v a  2 s. c  o  m
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(ConditionalExpression node) {
    node.getExpression().accept(this);
    this.buffer.append(" ? ");//$NON-NLS-1$
    node.getThenExpression().accept(this);
    this.buffer.append(" : ");//$NON-NLS-1$
    node.getElseExpression().accept(this);
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(ConditionalExpression node) {
    handleTokenBefore(node.getThenExpression(), TokenNameQUESTION,
            this.options.insert_space_before_question_in_conditional,
            this.options.insert_space_after_question_in_conditional);
    handleTokenBefore(node.getElseExpression(), TokenNameCOLON,
            this.options.insert_space_before_colon_in_conditional,
            this.options.insert_space_after_colon_in_conditional);
    return true;/*w ww .ja  v a2s. c o  m*/
}

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.ConditionalExpression node) {
    return done(conditionalExpression(translateExpression(node.getExpression()),
            translateExpression(node.getThenExpression()), translateExpression(node.getElseExpression())));
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@Override
public boolean visit(ConditionalExpression node) {
    boolean castNeeded = false;
    boolean castPrinted = false;
    ITypeBinding nodeType = Types.getTypeBinding(node);
    ITypeBinding thenType = Types.getTypeBinding(node.getThenExpression());
    ITypeBinding elseType = Types.getTypeBinding(node.getElseExpression());

    if (!thenType.equals(elseType) && !(node.getThenExpression() instanceof NullLiteral)
            && !(node.getElseExpression() instanceof NullLiteral)) {
        // gcc fails to compile a conditional expression where the two clauses of
        // the expression have differnt type. So cast the expressions to the type
        // of the node, which is guaranteed to be a valid cast.
        castNeeded = true;/*from  w  w  w.  j av a2s  .c om*/
    }

    node.getExpression().accept(this);

    buffer.append(" ? ");
    if (castNeeded) {
        castPrinted = printCast(nodeType);
    }
    node.getThenExpression().accept(this);
    if (castPrinted) {
        buffer.append(')');
    }

    buffer.append(" : ");
    if (castNeeded) {
        castPrinted = printCast(nodeType);
    }
    node.getElseExpression().accept(this);
    if (castPrinted) {
        buffer.append(')');
    }

    return false;
}

From source file:com.google.devtools.j2cpp.translate.Autoboxer.java

License:Open Source License

@Override
public void endVisit(ConditionalExpression node) {
    ITypeBinding nodeType = getBoxType(node);

    Expression thenExpr = node.getThenExpression();
    ITypeBinding thenType = getBoxType(thenExpr);

    Expression elseExpr = node.getElseExpression();
    ITypeBinding elseType = getBoxType(elseExpr);

    if (thenType.isPrimitive() && !nodeType.isPrimitive()) {
        node.setThenExpression(box(thenExpr));
    } else if (!thenType.isPrimitive() && nodeType.isPrimitive()) {
        node.setThenExpression(unbox(thenExpr));
    }/*ww  w .  j av a2 s . c  o  m*/

    if (elseType.isPrimitive() && !nodeType.isPrimitive()) {
        node.setElseExpression(box(elseExpr));
    } else if (!elseType.isPrimitive() && nodeType.isPrimitive()) {
        node.setElseExpression(unbox(elseExpr));
    }
}

From source file:com.google.devtools.j2cpp.translate.GwtConverter.java

License:Open Source License

@Override
public boolean visit(ConditionalExpression node) {
    if (isGwtTest(node.getExpression())) {
        // Replace this node with the else expression, removing this conditional.
        ClassConverter.setProperty(node, NodeCopier.copySubtree(node.getAST(), node.getElseExpression()));
    }//from w  w  w  . j av  a 2 s . c  o m
    node.getElseExpression().accept(this);
    return false;
}

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(ConditionalExpression node) {
    node.getExpression().accept(this);
    sb.print(" ? ");
    node.getThenExpression().accept(this);
    sb.print(" : ");
    node.getElseExpression().accept(this);
    return false;
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link ConditionalExpression}s. */
@Override/*from  w  w w  . j  av  a2s.  c  o  m*/
public boolean visit(ConditionalExpression node) {
    sync(node);
    builder.open(plusFour);
    node.getExpression().accept(this);
    builder.breakOp(" ");
    token("?");
    builder.space();
    node.getThenExpression().accept(this);
    builder.breakOp(" ");
    token(":");
    builder.space();
    node.getElseExpression().accept(this);
    builder.close();
    return false;
}