use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class ConstraintUtil method processExpression.
private static void processExpression(Expression expr) {
if (expr instanceof MethodCallExpr) {
MethodCallExpr mcExpr = (MethodCallExpr) expr;
if (canInverse(mcExpr)) {
inverseMethodCallExpr(mcExpr);
}
} else if (expr instanceof BinaryExpr) {
BinaryExpr bExpr = (BinaryExpr) expr;
if (bExpr.getOperator() == BinaryExpr.Operator.AND || bExpr.getOperator() == BinaryExpr.Operator.OR) {
Expression left = bExpr.getLeft();
processExpression(left);
Expression right = bExpr.getRight();
processExpression(right);
}
} else if (expr instanceof UnaryExpr) {
Expression expression = ((UnaryExpr) expr).getExpression();
processExpression(expression);
} else if (expr instanceof EnclosedExpr) {
Expression inner = ((EnclosedExpr) expr).getInner();
processExpression(inner);
}
}
use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testOOPathExprWithBackReference.
@Test
public void testOOPathExprWithBackReference() {
String expr = "$toy : /wife/children/toys[name.length == ../../name.length]";
DrlxExpression drlx = parseExpression(parser, expr);
assertEquals("$toy", drlx.getBind().asString());
Expression expression = drlx.getExpr();
assertTrue(expression instanceof OOPathExpr);
final OOPathChunk secondChunk = ((OOPathExpr) expression).getChunks().get(2);
final BinaryExpr secondChunkFirstCondition = (BinaryExpr) secondChunk.getConditions().get(0).getExpr();
final DrlNameExpr rightName = (DrlNameExpr) ((FieldAccessExpr) secondChunkFirstCondition.getRight()).getScope();
assertEquals(2, rightName.getBackReferencesCount());
assertEquals(expr, printNode(drlx));
}
use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testAndWithImplicitParameterAndParenthesisMixedLeft.
@Test
public void testAndWithImplicitParameterAndParenthesisMixedLeft() {
String expr = "value ((> 1 && < 2) || > 3)";
Expression expression = parseExpression(parser, expr).getExpr();
BinaryExpr comboExpr = ((BinaryExpr) expression);
assertEquals(Operator.OR, comboExpr.getOperator());
BinaryExpr comboExprLeft = ((BinaryExpr) comboExpr.getLeft());
assertEquals(Operator.AND, comboExprLeft.getOperator());
BinaryExpr first = (BinaryExpr) comboExprLeft.getLeft();
assertEquals("value", toString(first.getLeft()));
assertEquals("1", toString(first.getRight()));
assertEquals(Operator.GREATER, first.getOperator());
HalfBinaryExpr second = (HalfBinaryExpr) comboExprLeft.getRight();
assertEquals("2", toString(second.getRight()));
assertEquals(HalfBinaryExpr.Operator.LESS, second.getOperator());
BinaryExpr third = ((BinaryExpr) comboExpr.getRight());
assertEquals("value", toString(third.getLeft()));
assertEquals("3", toString(third.getRight()));
assertEquals(Operator.GREATER, third.getOperator());
}
use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testAndWithImplicitParameterAndParenthesisComplex.
@Test
public void testAndWithImplicitParameterAndParenthesisComplex() {
String expr = "value ((> 1 && < 2) || (> 3 && < 4))";
Expression expression = parseExpression(parser, expr).getExpr();
BinaryExpr comboExpr = ((BinaryExpr) expression);
assertEquals(Operator.OR, comboExpr.getOperator());
BinaryExpr comboExprLeft = ((BinaryExpr) comboExpr.getLeft());
assertEquals(Operator.AND, comboExprLeft.getOperator());
BinaryExpr first = (BinaryExpr) comboExprLeft.getLeft();
assertEquals("value", toString(first.getLeft()));
assertEquals("1", toString(first.getRight()));
assertEquals(Operator.GREATER, first.getOperator());
HalfBinaryExpr second = (HalfBinaryExpr) comboExprLeft.getRight();
assertEquals("2", toString(second.getRight()));
assertEquals(HalfBinaryExpr.Operator.LESS, second.getOperator());
BinaryExpr comboExprRight = ((BinaryExpr) comboExpr.getRight());
assertEquals(Operator.AND, comboExprRight.getOperator());
BinaryExpr third = (BinaryExpr) comboExprRight.getLeft();
assertEquals("value", toString(third.getLeft()));
assertEquals("3", toString(third.getRight()));
assertEquals(Operator.GREATER, third.getOperator());
HalfBinaryExpr forth = (HalfBinaryExpr) comboExprRight.getRight();
assertEquals("4", toString(forth.getRight()));
assertEquals(HalfBinaryExpr.Operator.LESS, forth.getOperator());
}
use of com.github.javaparser.ast.expr.BinaryExpr in project drools by kiegroup.
the class DroolsMvelParserTest method testBindingOnRight.
@Test
public void testBindingOnRight() {
String expr = "$n : name == \"Mario\" && $a : age > 20";
DrlxExpression drlxExpression = parseExpression(parser, expr);
Expression bExpr = drlxExpression.getExpr();
assertTrue(bExpr instanceof BinaryExpr);
Node left = ((BinaryExpr) bExpr).getLeft();
assertTrue(left instanceof DrlxExpression);
DrlxExpression leftExpr = (DrlxExpression) left;
SimpleName leftBind = leftExpr.getBind();
assertEquals("$n", leftBind.asString());
Expression expression = leftExpr.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 DrlxExpression);
DrlxExpression rightExpr = (DrlxExpression) right;
SimpleName rightBind = rightExpr.getBind();
assertEquals("$a", rightBind.asString());
BinaryExpr binaryExpr2 = ((BinaryExpr) rightExpr.getExpr());
assertEquals("age", toString(binaryExpr2.getLeft()));
assertEquals("20", toString(binaryExpr2.getRight()));
assertEquals(Operator.GREATER, binaryExpr2.getOperator());
}
Aggregations