use of org.drools.compiler.lang.descr.EvalDescr in project drools by kiegroup.
the class AbstractASMEvalBuilder method build.
public RuleConditionElement build(RuleBuildContext context, BaseDescr descr) {
// it must be an EvalDescr
final EvalDescr evalDescr = (EvalDescr) descr;
Map<String, Declaration> decls = context.getDeclarationResolver().getDeclarations(context.getRule());
AnalysisResult analysis = context.getDialect().analyzeExpression(context, evalDescr, evalDescr.getContent(), new BoundIdentifiers(DeclarationScopeResolver.getDeclarationClasses(decls), context));
List<Declaration> requiredDeclarations = new ArrayList<Declaration>();
for (String usedIdentifier : analysis.getIdentifiers()) {
Declaration usedDec = decls.get(usedIdentifier);
if (usedDec != null) {
requiredDeclarations.add(usedDec);
}
}
final Declaration[] declarations = requiredDeclarations.toArray(new Declaration[requiredDeclarations.size()]);
return buildEval(context, evalDescr, analysis, declarations);
}
use of org.drools.compiler.lang.descr.EvalDescr in project drools by kiegroup.
the class RuleParserTest method testWithEval.
@Test
public void testWithEval() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "with_eval.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(3, rule.getLhs().getDescrs().size());
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
assertEquals("Foo", pattern.getObjectType());
pattern = (PatternDescr) rule.getLhs().getDescrs().get(1);
assertEquals("Bar", pattern.getObjectType());
final EvalDescr eval = (EvalDescr) rule.getLhs().getDescrs().get(2);
assertEqualsIgnoreWhitespace("abc(\"foo\")", (String) eval.getContent());
assertEqualsIgnoreWhitespace("Kapow", (String) rule.getConsequence());
}
Aggregations