use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class DroolsMvelParserTest method testBindVariable.
@Test
public void testBindVariable() {
String expr = "$n : name == \"Mark\"";
DrlxExpression drlxExpression = parseExpression(parser, expr);
SimpleName bind = drlxExpression.getBind();
assertEquals("$n", bind.asString());
Expression expression = drlxExpression.getExpr();
BinaryExpr binaryExpr = ((BinaryExpr) expression);
assertEquals("name", toString(binaryExpr.getLeft()));
assertEquals("\"Mark\"", toString(binaryExpr.getRight()));
assertEquals(Operator.EQUALS, binaryExpr.getOperator());
}
use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class DroolsMvelParserTest method testOOPathExprWithDeclaration.
@Test
public void testOOPathExprWithDeclaration() {
String expr = "$toy : /wife/children[age > 10]/toys";
DrlxExpression drlx = parseExpression(parser, expr);
assertEquals("$toy", drlx.getBind().asString());
Expression expression = drlx.getExpr();
assertTrue(expression instanceof OOPathExpr);
assertEquals(expr, printNode(drlx));
}
use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class DroolsMvelParserTest method testMapInitializationEmpty.
@Test
public void testMapInitializationEmpty() {
String expr = "countItems([])";
DrlxExpression drlx = parseExpression(parser, expr);
assertEquals(expr, printNode(drlx));
}
use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class ConstraintPrintVisitor method visit.
@Override
public void visit(OOPathExpr oopathExpr, Void arg) {
printComment(oopathExpr.getComment(), arg);
NodeList<OOPathChunk> chunks = oopathExpr.getChunks();
for (int i = 0; i < chunks.size(); i++) {
final OOPathChunk chunk = chunks.get(i);
printer.print(chunk.isSingleValue() ? "." : "/");
chunk.accept(this, arg);
printer.print(chunk.getField().toString());
if (chunk.getInlineCast() != null) {
printer.print("#");
chunk.getInlineCast().accept(this, arg);
}
List<DrlxExpression> condition = chunk.getConditions();
final Iterator<DrlxExpression> iterator = condition.iterator();
if (!condition.isEmpty()) {
printer.print("[");
DrlxExpression first = iterator.next();
first.accept(this, arg);
while (iterator.hasNext()) {
printer.print(",");
iterator.next().accept(this, arg);
}
printer.print("]");
}
}
}
use of org.drools.mvel.parser.ast.expr.DrlxExpression in project drools by kiegroup.
the class AstUtils method parseBindingAfterAnd.
public static DrlxExpression parseBindingAfterAnd(TokenRange tokenRange, DrlxExpression leftExpr, Expression rightExpr) {
if (leftExpr.getExpr() instanceof BinaryExpr && ((BinaryExpr) leftExpr.getExpr()).getOperator() == BinaryExpr.Operator.AND) {
if (((BinaryExpr) leftExpr.getExpr()).getRight() instanceof NameExpr) {
DrlxExpression newLeft = new DrlxExpression(leftExpr.getBind(), ((BinaryExpr) leftExpr.getExpr()).getLeft());
SimpleName rightName = ((NameExpr) ((BinaryExpr) leftExpr.getExpr()).getRight()).getName();
DrlxExpression newRight = new DrlxExpression(rightName, rightExpr);
return new DrlxExpression(null, new BinaryExpr(tokenRange, newLeft, newRight, BinaryExpr.Operator.AND));
}
if (((BinaryExpr) leftExpr.getExpr()).getRight() instanceof DrlxExpression) {
Expression first = ((BinaryExpr) leftExpr.getExpr()).getLeft();
DrlxExpression innerRight = parseBindingAfterAnd(tokenRange, (DrlxExpression) ((BinaryExpr) leftExpr.getExpr()).getRight(), rightExpr);
Expression second = ((BinaryExpr) innerRight.getExpr()).getLeft();
Expression third = ((BinaryExpr) innerRight.getExpr()).getRight();
return new DrlxExpression(null, new BinaryExpr(tokenRange, new BinaryExpr(tokenRange, first, second, BinaryExpr.Operator.AND), third, BinaryExpr.Operator.AND));
}
}
throw new IllegalStateException();
}
Aggregations