use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class AccumulateVisitorPatternDSL method buildBinding.
@Override
protected MethodCallExpr buildBinding(String bindingName, Collection<String> usedDeclaration, Expression expression) {
MethodCallExpr bindDSL = new MethodCallExpr(null, BIND_CALL);
bindDSL.addArgument(toVar(bindingName));
usedDeclaration.stream().map(d -> new NameExpr(toVar(d))).forEach(bindDSL::addArgument);
bindDSL.addArgument(buildConstraintExpression(expression, usedDeclaration));
return bindDSL;
}
use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class AccumulateVisitorPatternDSL method replaceBindingWithPatternBinding.
private MethodCallExpr replaceBindingWithPatternBinding(MethodCallExpr bindExpression, MethodCallExpr lastPattern) {
final Expression bindingId = lastPattern.getArgument(0);
bindExpression.findFirst(NameExpr.class, e -> e.equals(bindingId)).ifPresent(name -> {
bindExpression.remove(name);
LambdaExpr lambda = (LambdaExpr) bindExpression.getArgument(bindExpression.getArguments().size() - 1);
if (lambda.getParameters().size() > 1) {
String formalArg = fromVar(name.getNameAsString());
for (Parameter param : lambda.getParameters()) {
if (param.getNameAsString().equals(formalArg)) {
lambda.getParameters().remove(param);
lambda.getParameters().add(0, param);
break;
}
}
}
});
return (MethodCallExpr) bindExpression;
}
use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class FlowDSLPattern method buildConstraints.
private void buildConstraints(PatternDescr pattern, Class<?> patternType, List<PatternConstraintParseResult> patternConstraintParseResults, boolean allConstraintsPositional) {
if (allConstraintsPositional) {
final MethodCallExpr andDSL = new MethodCallExpr(null, "and");
context.addExpression(andDSL);
context.pushExprPointer(andDSL::addArgument);
}
for (PatternConstraintParseResult patternConstraintParseResult : patternConstraintParseResults) {
buildConstraint(pattern, patternType, patternConstraintParseResult);
}
if (allConstraintsPositional) {
context.popExprPointer();
}
}
use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class PatternDSLPattern method addWatchToPattern.
private MethodCallExpr addWatchToPattern(MethodCallExpr patternExpression) {
Collection<String> watchedProps = new ArrayList<>();
watchedProps.addAll(context.getRuleDescr().lookAheadFieldsOfIdentifier(pattern));
watchedProps.addAll(getPatternListenedProperties(pattern));
if (!watchedProps.isEmpty()) {
patternExpression = new MethodCallExpr(patternExpression, "watch");
watchedProps.stream().map(StringLiteralExpr::new).forEach(patternExpression::addArgument);
}
return patternExpression;
}
use of org.drools.javaparser.ast.expr.MethodCallExpr in project drools by kiegroup.
the class Query method buildPattern.
@Override
public void buildPattern() {
NameExpr queryCall = new NameExpr(toQueryDef(pattern.getObjectType()));
MethodCallExpr callCall = new MethodCallExpr(queryCall, QUERY_INVOCATION_CALL);
callCall.addArgument("" + !pattern.isQuery());
for (int i = 0; i < constraintDescrs.size(); i++) {
String itemText = constraintDescrs.get(i).getText();
if (QueryGenerator.isLiteral(itemText)) {
MethodCallExpr valueOfMethod = new MethodCallExpr(null, VALUE_OF_CALL);
valueOfMethod.addArgument(new NameExpr(itemText));
callCall.addArgument(valueOfMethod);
} else {
QueryParameter qp = packageModel.queryVariables(queryName).get(i);
context.addDeclaration(new DeclarationSpec(itemText, qp.getType()));
callCall.addArgument(QueryGenerator.substituteBindingWithQueryParameter(context, itemText));
}
}
context.addExpression(callCall);
}
Aggregations