use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.
the class FromHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final FromDescr fromDescr = (FromDescr) parser.getCurrent();
Object parent = parser.getParent();
final PatternDescr patternDescr = (PatternDescr) parent;
final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parser.getParent(1);
if (element.getElementsByTagName("expression").getLength() > 0) {
patternDescr.setSource(fromDescr);
}
return fromDescr;
}
use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.
the class ExprConstraintHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final String expression = ((org.w3c.dom.Text) element.getChildNodes().item(0)).getWholeText();
emptyContentCheck(localName, expression, parser);
PatternDescr p = (PatternDescr) parser.getParent();
ExprConstraintDescr descr = new ExprConstraintDescr(expression);
p.getConstraint().addDescr(descr);
return descr;
}
use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.
the class CollectHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final CollectDescr collectDescr = (CollectDescr) parser.getCurrent();
final Object parent = parser.getParent();
if (parent.getClass().getName().equals(FromDescr.class.getName())) {
final PatternDescr resultPattern = (PatternDescr) parser.getParent(1);
resultPattern.setSource(collectDescr);
} else if (parent instanceof ConditionalElementDescr) {
final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent;
parentDescr.addDescr(collectDescr);
}
return collectDescr;
}
use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.
the class RuleBuilder method getLhsForRuleUnit.
private static AndDescr getLhsForRuleUnit(RuleImpl rule, AndDescr lhs) {
if (rule.hasRuleUnit()) {
PatternDescr unitPattern = new PatternDescr(rule.getRuleUnitClassName(), RULE_UNIT_DECLARATION);
unitPattern.setSource(EntryPointDescr.RULE_UNIT_ENTRY_POINT_DESCR);
unitPattern.setResource(rule.getResource());
lhs.getDescrs().add(0, unitPattern);
}
return lhs;
}
use of org.drools.drl.ast.descr.PatternDescr in project drools by kiegroup.
the class AccumulateVisitor method binaryExprParameter.
private Optional<NewBinding> binaryExprParameter(PatternDescr basePattern, AccumulateDescr.AccumulateFunctionCallDescr function, MethodCallExpr functionDSL, String bindingId, String accumulateFunctionParameterStr) {
final DrlxParseResult parseResult = ConstraintParser.defaultConstraintParser(context, packageModel).drlxParse(Object.class, bindingId, accumulateFunctionParameterStr);
Optional<NewBinding> optNewBinding = parseResult.acceptWithReturnValue(new ParseResultVisitor<Optional<NewBinding>>() {
@Override
public Optional<NewBinding> onSuccess(DrlxParseSuccess drlxParseResult) {
SingleDrlxParseSuccess singleResult = (SingleDrlxParseSuccess) drlxParseResult;
Class<?> exprRawClass = singleResult.getExprRawClass();
AccumulateFunction accumulateFunction = getAccumulateFunction(function, exprRawClass);
validateAccFunctionTypeAgainstPatternType(context, basePattern, accumulateFunction);
final String bindExpressionVariable = context.getExprId(accumulateFunction.getResultType(), singleResult.getLeft().toString());
singleResult.setExprBinding(bindExpressionVariable);
context.addDeclarationReplacing(new DeclarationSpec(singleResult.getPatternBinding(), exprRawClass));
context.getExpressions().forEach(expression -> replaceTypeInExprLambda(bindingId, exprRawClass, expression));
functionDSL.addArgument(createAccSupplierExpr(accumulateFunction));
final MethodCallExpr newBindingFromBinary = AccumulateVisitor.this.buildBinding(bindExpressionVariable, singleResult.getUsedDeclarations(), singleResult.getExpr());
context.addDeclarationReplacing(new DeclarationSpec(bindExpressionVariable, exprRawClass));
functionDSL.addArgument(context.getVarExpr(bindExpressionVariable));
return Optional.of(new NewBinding(Collections.emptyList(), newBindingFromBinary));
}
@Override
public Optional<NewBinding> onFail(DrlxParseFail failure) {
return Optional.empty();
}
});
return optNewBinding;
}
Aggregations