use of org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess in project drools by kiegroup.
the class OOPathExprGenerator method toPatternExpr.
private void toPatternExpr(String bindingId, List<DrlxParseResult> list) {
MethodCallExpr patternExpr = new MethodCallExpr(null, "pattern");
patternExpr.addArgument(toVar(bindingId));
for (DrlxParseResult drlx : list) {
if (drlx instanceof DrlxParseSuccess) {
MethodCallExpr expr = (MethodCallExpr) expressionBuilder.buildExpressionWithIndexing(((DrlxParseSuccess) drlx));
expr.setScope(patternExpr);
patternExpr = expr;
}
}
context.addExpression(patternExpr);
}
use of org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess in project drools by kiegroup.
the class OOPathExprGenerator method toFlowExpr.
private void toFlowExpr(String bindingId, List<DrlxParseResult> list) {
final List<DrlxParseSuccess> value = list.stream().filter(r -> r instanceof DrlxParseSuccess).map(DrlxParseSuccess.class::cast).collect(Collectors.toList());
if (value.size() == 1) {
context.addExpression(expressionBuilder.buildExpressionWithIndexing(value.get(0)));
} else {
final MethodCallExpr andDSL = new MethodCallExpr(null, "and");
value.forEach(e -> {
final Expression expression = expressionBuilder.buildExpressionWithIndexing(e);
andDSL.addArgument(expression);
});
context.addExpression(andDSL);
}
}
use of org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess in project drools by kiegroup.
the class FlowExpressionBuilder method buildExpression.
private MethodCallExpr buildExpression(DrlxParseSuccess drlxParseResult, MethodCallExpr exprDSL) {
final List<String> usedDeclarationsWithUnification = new ArrayList<>();
if (drlxParseResult.isPatternBindingUnification()) {
usedDeclarationsWithUnification.add(drlxParseResult.getPatternBinding());
} else {
if (drlxParseResult.getPatternBinding() != null && !drlxParseResult.getUsedDeclarations().contains(drlxParseResult.getPatternBinding())) {
exprDSL.addArgument(new NameExpr(toVar(drlxParseResult.getPatternBinding())));
}
}
usedDeclarationsWithUnification.addAll(drlxParseResult.getUsedDeclarations());
usedDeclarationsWithUnification.stream().filter(s -> !(drlxParseResult.isSkipThisAsParam() && s.equals(drlxParseResult.getPatternBinding()))).map(x -> QueryGenerator.substituteBindingWithQueryParameter(context, x)).forEach(exprDSL::addArgument);
exprDSL.addArgument(buildConstraintExpression(drlxParseResult, drlxParseResult.getExpr()));
return exprDSL;
}
use of org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess in project drools by kiegroup.
the class PatternExpressionBuilder method buildExpressionWithIndexing.
@Override
public MethodCallExpr buildExpressionWithIndexing(DrlxParseSuccess drlxParseResult) {
if (drlxParseResult instanceof MultipleDrlxParseSuccess) {
MultipleDrlxParseSuccess multi = (MultipleDrlxParseSuccess) drlxParseResult;
MethodCallExpr exprDSL = new MethodCallExpr(null, multi.getOperator() == BinaryExpr.Operator.OR ? EXPR_OR_CALL : EXPR_AND_CALL);
for (DrlxParseSuccess child : multi.getResults()) {
MethodCallExpr childExpr = buildExpressionWithIndexing(child);
childExpr.setScope(exprDSL);
exprDSL = childExpr;
if (child instanceof SingleDrlxParseSuccess && child.getExprBinding() != null) {
SingleDrlxParseSuccess singleDrlxChild = (SingleDrlxParseSuccess) child;
context.addDeclaration(child.getExprBinding(), singleDrlxChild.getLeftExprRawClass());
Expression dslExpr = buildBinding(singleDrlxChild);
context.addExpression(dslExpr);
}
}
return new MethodCallExpr(exprDSL, multi.getOperator() == BinaryExpr.Operator.OR ? EXPR_END_OR_CALL : EXPR_END_AND_CALL);
}
return buildSingleExpressionWithIndexing((SingleDrlxParseSuccess) drlxParseResult);
}
use of org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess in project drools by kiegroup.
the class PatternDSL method addNullSafeExpr.
private void addNullSafeExpr(ConstraintParser constraintParser, String patternIdentifier, List<PatternConstraintParseResult> patternConstraintParseResults) {
final List<Expression> nullSafeExpressions = patternConstraintParseResults.stream().flatMap(r -> r.getDrlxParseResult().acceptWithReturnValue(new ParseResultVisitor<List<Expression>>() {
@Override
public List<Expression> onSuccess(DrlxParseSuccess t) {
return t.getNullSafeExpressions();
}
@Override
public List<Expression> onFail(DrlxParseFail failure) {
return Collections.emptyList();
}
}).stream()).collect(Collectors.toList());
List<Expression> newNullSafeExpressions = reverseDistinct(nullSafeExpressions);
newNullSafeExpressions.forEach(expr -> {
String nullSafeExpression = printNode(expr);
DrlxParseResult nullSafeExpressionParsed = constraintParser.drlxParse(patternType, patternIdentifier, nullSafeExpression, false);
patternConstraintParseResults.add(0, new PatternConstraintParseResult(nullSafeExpression, patternIdentifier, nullSafeExpressionParsed));
});
}
Aggregations