Search in sources :

Example 21 with BinaryExpr

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

the class DroolsMvelParserTest method testComplexEnclosedBindVariable.

@Test
public void testComplexEnclosedBindVariable() {
    String expr = "($n : name == \"Mario\") && (age > 20)";
    DrlxExpression drlxExpression = parseExpression(parser, expr);
    Expression bExpr = drlxExpression.getExpr();
    assertTrue(bExpr instanceof BinaryExpr);
    Node left = ((BinaryExpr) bExpr).getLeft();
    assertTrue(left instanceof EnclosedExpr);
    Expression inner = ((EnclosedExpr) left).getInner();
    assertTrue(inner instanceof DrlxExpression);
    DrlxExpression innerDrlxExpression = (DrlxExpression) inner;
    SimpleName bind = innerDrlxExpression.getBind();
    assertEquals("$n", bind.asString());
    Expression expression = innerDrlxExpression.getExpr();
    BinaryExpr binaryExpr = ((BinaryExpr) expression);
    assertEquals("name", toString(binaryExpr.getLeft()));
    assertEquals("\"Mario\"", toString(binaryExpr.getRight()));
    assertEquals(Operator.EQUALS, binaryExpr.getOperator());
    Node right = ((BinaryExpr) bExpr).getRight();
    assertTrue(right instanceof EnclosedExpr);
    Expression expression2 = ((EnclosedExpr) right).getInner();
    BinaryExpr binaryExpr2 = ((BinaryExpr) expression2);
    assertEquals("age", toString(binaryExpr2.getLeft()));
    assertEquals("20", toString(binaryExpr2.getRight()));
    assertEquals(Operator.GREATER, binaryExpr2.getOperator());
}
Also used : DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) Node(com.github.javaparser.ast.Node) SimpleName(com.github.javaparser.ast.expr.SimpleName) EnclosedExpr(com.github.javaparser.ast.expr.EnclosedExpr) Test(org.junit.Test)

Example 22 with BinaryExpr

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

the class DroolsMvelParserTest method testAndWithImplicitParameter3.

@Test
public void testAndWithImplicitParameter3() {
    String expr = "age == 2 && == 3 || == 4";
    Expression expression = parseExpression(parser, expr).getExpr();
    BinaryExpr comboExpr = ((BinaryExpr) expression);
    assertEquals(Operator.OR, comboExpr.getOperator());
    assertEquals(Operator.AND, ((BinaryExpr) (comboExpr.getLeft())).getOperator());
    BinaryExpr first = ((BinaryExpr) ((BinaryExpr) comboExpr.getLeft()).getLeft());
    assertEquals("age", toString(first.getLeft()));
    assertEquals("2", toString(first.getRight()));
    assertEquals(Operator.EQUALS, first.getOperator());
    HalfBinaryExpr second = (HalfBinaryExpr) ((BinaryExpr) comboExpr.getLeft()).getRight();
    assertEquals("3", toString(second.getRight()));
    assertEquals(HalfBinaryExpr.Operator.EQUALS, second.getOperator());
    HalfBinaryExpr third = (HalfBinaryExpr) comboExpr.getRight();
    assertEquals("4", toString(third.getRight()));
    assertEquals(HalfBinaryExpr.Operator.EQUALS, third.getOperator());
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Test(org.junit.Test)

Example 23 with BinaryExpr

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

the class DroolsMvelParserTest method testAndWithImplicitParameterAndParenthesis.

@Test
public void testAndWithImplicitParameterAndParenthesis() {
    String expr = "value (> 1 && < 2)";
    Expression expression = parseExpression(parser, expr).getExpr();
    BinaryExpr comboExpr = ((BinaryExpr) expression);
    assertEquals(Operator.AND, comboExpr.getOperator());
    BinaryExpr first = (BinaryExpr) comboExpr.getLeft();
    assertEquals("value", toString(first.getLeft()));
    assertEquals("1", toString(first.getRight()));
    assertEquals(Operator.GREATER, first.getOperator());
    HalfBinaryExpr second = (HalfBinaryExpr) comboExpr.getRight();
    assertEquals("2", toString(second.getRight()));
    assertEquals(HalfBinaryExpr.Operator.LESS, second.getOperator());
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Test(org.junit.Test)

Example 24 with BinaryExpr

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

the class DroolsMvelParserTest method testAndWithImplicitParameter.

@Test
public void testAndWithImplicitParameter() {
    String expr = "name == \"Mark\" && == \"Mario\" && == \"Luca\"";
    Expression expression = parseExpression(parser, expr).getExpr();
    BinaryExpr comboExpr = ((BinaryExpr) expression);
    assertEquals(Operator.AND, comboExpr.getOperator());
    BinaryExpr first = ((BinaryExpr) ((BinaryExpr) comboExpr.getLeft()).getLeft());
    assertEquals("name", toString(first.getLeft()));
    assertEquals("\"Mark\"", toString(first.getRight()));
    assertEquals(Operator.EQUALS, first.getOperator());
    HalfBinaryExpr second = (HalfBinaryExpr) ((BinaryExpr) comboExpr.getLeft()).getRight();
    assertEquals("\"Mario\"", toString(second.getRight()));
    assertEquals(HalfBinaryExpr.Operator.EQUALS, second.getOperator());
    HalfBinaryExpr third = (HalfBinaryExpr) comboExpr.getRight();
    assertEquals("\"Luca\"", toString(third.getRight()));
    assertEquals(HalfBinaryExpr.Operator.EQUALS, third.getOperator());
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Test(org.junit.Test)

Example 25 with BinaryExpr

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

the class DroolsMvelParserTest method testAndWithImplicitParameterAndParenthesisOnThis.

@Test
public void testAndWithImplicitParameterAndParenthesisOnThis() {
    String expr = "this (> 1 && < 2)";
    Expression expression = parseExpression(parser, expr).getExpr();
    BinaryExpr comboExpr = ((BinaryExpr) expression);
    assertEquals(Operator.AND, comboExpr.getOperator());
    BinaryExpr first = (BinaryExpr) comboExpr.getLeft();
    assertEquals("this", toString(first.getLeft()));
    assertEquals("1", toString(first.getRight()));
    assertEquals(Operator.GREATER, first.getOperator());
    HalfBinaryExpr second = (HalfBinaryExpr) comboExpr.getRight();
    assertEquals("2", toString(second.getRight()));
    assertEquals(HalfBinaryExpr.Operator.LESS, second.getOperator());
}
Also used : HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) DrlxParser.parseExpression(org.drools.mvel.parser.DrlxParser.parseExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxExpression(org.drools.mvel.parser.ast.expr.DrlxExpression) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Test(org.junit.Test)

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