Search in sources :

Example 41 with BinaryExpr

use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.

the class DrlxParseUtil method trasformHalfBinaryToBinary.

public static Expression trasformHalfBinaryToBinary(Expression drlxExpr) {
    final Optional<Node> parent = drlxExpr.getParentNode();
    if (drlxExpr instanceof HalfBinaryExpr && parent.isPresent()) {
        HalfBinaryExpr halfBinaryExpr = (HalfBinaryExpr) drlxExpr;
        Expression parentLeft = findLeftLeafOfNameExprTraversingParent(halfBinaryExpr);
        Operator operator = toBinaryExprOperator(halfBinaryExpr.getOperator());
        return new BinaryExpr(parentLeft, halfBinaryExpr.getRight(), operator);
    }
    return drlxExpr;
}
Also used : Operator(com.github.javaparser.ast.expr.BinaryExpr.Operator) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Expression(com.github.javaparser.ast.expr.Expression) ListCreationLiteralExpression(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) MapCreationLiteralExpression(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression) Node(com.github.javaparser.ast.Node) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr)

Example 42 with BinaryExpr

use of com.github.javaparser.ast.expr.BinaryExpr in project checker-framework by typetools.

the class DoubleJavaParserVisitor method visit.

@Override
public void visit(final BinaryExpr node1, final Node other) {
    BinaryExpr node2 = (BinaryExpr) other;
    defaultAction(node1, node2);
    node1.getLeft().accept(this, node2.getLeft());
    node1.getRight().accept(this, node2.getRight());
}
Also used : BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr)

Example 43 with BinaryExpr

use of com.github.javaparser.ast.expr.BinaryExpr in project vue-gwt by Axellience.

the class TemplateParser method getTypeFromCast.

/**
 * Get the type of an expression from the cast at the beginning.
 * (int) 12 -> 12 of type int
 * (int) 15 + 5 -> 15 + 5 of type int
 * (float) (12 + 3) -> 12 + 3 of type float
 * ((int) 12) + 3 -> ((int) 12) + 3 of type Any
 * ((JsArray) myArray).getAt(0) -> ((JsArray) myArray).getAt(0) of type Any
 * @param expression The expression to process
 * @return The modified expression (where cast has been removed if necessary)
 */
private Expression getTypeFromCast(Expression expression) {
    if (expression instanceof BinaryExpr) {
        Expression mostLeft = getLeftmostExpression(expression);
        if (mostLeft instanceof CastExpr) {
            CastExpr castExpr = (CastExpr) mostLeft;
            currentExpressionReturnType = stringTypeToTypeName(castExpr.getType().toString());
            BinaryExpr parent = (BinaryExpr) mostLeft.getParentNode().get();
            parent.setLeft(castExpr.getExpression());
        }
    } else if (expression instanceof CastExpr) {
        CastExpr castExpr = (CastExpr) expression;
        currentExpressionReturnType = stringTypeToTypeName(castExpr.getType().toString());
        expression = castExpr.getExpression();
    }
    return expression;
}
Also used : TemplateExpression(com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression) Expression(com.github.javaparser.ast.expr.Expression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) CastExpr(com.github.javaparser.ast.expr.CastExpr)

Aggregations

BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)43 Expression (com.github.javaparser.ast.expr.Expression)37 HalfBinaryExpr (org.drools.mvel.parser.ast.expr.HalfBinaryExpr)33 DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)30 DrlxParser.parseExpression (org.drools.mvel.parser.DrlxParser.parseExpression)20 Test (org.junit.Test)20 EnclosedExpr (com.github.javaparser.ast.expr.EnclosedExpr)12 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)10 NameExpr (com.github.javaparser.ast.expr.NameExpr)9 SimpleName (com.github.javaparser.ast.expr.SimpleName)9 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)8 DrlNameExpr (org.drools.mvel.parser.ast.expr.DrlNameExpr)8 FieldAccessExpr (com.github.javaparser.ast.expr.FieldAccessExpr)7 ArrayList (java.util.ArrayList)7 Node (com.github.javaparser.ast.Node)6 UnaryExpr (com.github.javaparser.ast.expr.UnaryExpr)6 NodeList (com.github.javaparser.ast.NodeList)5 LiteralExpr (com.github.javaparser.ast.expr.LiteralExpr)5 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)5 ListCreationLiteralExpression (org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression)5