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

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

Introduction

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

Prototype

public Expression getExpression() 

Source Link

Document

Returns the condition 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 w w.j  av  a2  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.linewrap.WrapPreparator.java

License:Open Source License

@Override
public boolean visit(ConditionalExpression node) {
    this.wrapIndexes.add(this.tm.firstIndexAfter(node.getExpression(), TokenNameQUESTION));
    this.wrapIndexes.add(this.tm.firstIndexAfter(node.getThenExpression(), TokenNameCOLON));
    this.wrapParentIndex = this.tm.lastIndexIn(node.getExpression(), -1);
    this.wrapGroupEnd = this.tm.lastIndexIn(node, -1);
    handleWrap(this.options.alignment_for_conditional_expression);
    return true;//ww  w .  j a  v  a  2s  .  c om
}

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;/*ww  w  .  j av a 2  s . c  o m*/
    }

    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.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  .  java 2  s .  co 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 ww  w .  j av a 2s  .  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;
}

From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java

License:Open Source License

private CAstNode visit(ConditionalExpression n, WalkContext context) {
    return makeNode(context, fFactory, n, CAstNode.IF_EXPR, visitNode(n.getExpression(), context),
            visitNode(n.getThenExpression(), context), visitNode(n.getElseExpression(), context));
}