use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DescrDumperTest method testDumpExcludes.
@Test
public void testDumpExcludes() throws Exception {
String input = "list excludes \"b\"";
String expected = "!( list contains \"b\" )";
ConstraintConnectiveDescr descr = parse(input);
String result = dumper.dump(descr);
assertEquals(expected, result);
}
use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DescrDumperTest method testDumpContains.
@Test
public void testDumpContains() throws Exception {
String input = "list contains \"b\"";
String expected = "list contains \"b\"";
ConstraintConnectiveDescr descr = parse(input);
String result = dumper.dump(descr);
assertEquals(expected, result);
}
use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DescrDumperTest method testDumpBindings2.
@Test
public void testDumpBindings2() throws Exception {
String input = "( $a : a > $b : b[10].prop || 10 != 20 ) && $x : someMethod(10) == 20";
String expected = "( a > b[10].prop || 10 != 20 ) && someMethod(10) == 20";
ConstraintConnectiveDescr descr = parse(input);
DumperContext ctx = new DumperContext();
String result = dumper.dump(descr, ctx);
assertEquals(expected, result);
assertEquals(3, ctx.getBindings().size());
BindingDescr bind = ctx.getBindings().get(0);
assertEquals("$a", bind.getVariable());
assertEquals("a", bind.getExpression());
bind = ctx.getBindings().get(1);
assertEquals("$b", bind.getVariable());
assertEquals("b[10].prop", bind.getExpression());
bind = ctx.getBindings().get(2);
assertEquals("$x", bind.getVariable());
assertEquals("someMethod(10)", bind.getExpression());
}
use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DescrDumperTest method parse.
public ConstraintConnectiveDescr parse(final String constraint) {
DrlExprParser parser = new DrlExprParser(LanguageLevelOption.DRL6);
ConstraintConnectiveDescr result = parser.parse(constraint);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
return result;
}
use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class PatternBuilder method rewriteCompositeExpressions.
private String rewriteCompositeExpressions(RuleBuildContext context, Pattern pattern, ConstraintConnectiveDescr d) {
int i = 0;
StringBuilder sb = new StringBuilder();
for (BaseDescr subDescr : d.getDescrs()) {
if (subDescr instanceof BindingDescr) {
continue;
}
if (i++ > 0) {
sb.append(" ").append(d.getConnective().getConnective()).append(" ");
}
String normalizedExpr;
if (subDescr instanceof RelationalExprDescr && isSimpleExpr((RelationalExprDescr) subDescr)) {
RelationalExprDescr relDescr = (RelationalExprDescr) subDescr;
if (relDescr.getExpression() != null) {
normalizedExpr = normalizeExpression(context, pattern, relDescr, relDescr.getExpression());
} else {
i--;
normalizedExpr = "";
}
} else if (subDescr instanceof ConstraintConnectiveDescr) {
String rewrittenExpr = rewriteCompositeExpressions(context, pattern, (ConstraintConnectiveDescr) subDescr);
if (rewrittenExpr == null) {
return null;
}
normalizedExpr = "(" + rewrittenExpr + ")";
} else if (subDescr instanceof AtomicExprDescr) {
normalizedExpr = ((AtomicExprDescr) subDescr).getRewrittenExpression();
} else {
return null;
}
sb.append(normalizedExpr);
}
return sb.toString();
}
Aggregations