use of org.drools.javaparser.ast.expr.Expression in project drools by kiegroup.
the class FlowDSLPattern method buildPattern.
@Override
public void buildPattern() {
generatePatternIdentifierIfMissing();
final Optional<Expression> declarationSource = buildFromDeclaration(pattern);
context.addDeclaration(new DeclarationSpec(pattern.getIdentifier(), patternType, Optional.of(pattern), declarationSource));
if (constraintDescrs.isEmpty() && !(pattern.getSource() instanceof AccumulateDescr)) {
context.addExpression(createInputExpression(pattern));
} else {
if (!context.hasErrors()) {
final List<PatternConstraintParseResult> patternConstraintParseResults = findAllConstraint(pattern, constraintDescrs, patternType);
if (shouldAddInputPattern(patternConstraintParseResults)) {
context.addExpression(createInputExpression(pattern));
}
buildConstraints(pattern, patternType, patternConstraintParseResults, allConstraintsPositional);
}
}
}
use of org.drools.javaparser.ast.expr.Expression in project drools by kiegroup.
the class PatternDSLPattern method buildPattern.
@Override
public void buildPattern() {
generatePatternIdentifierIfMissing();
final Optional<Expression> declarationSource = buildFromDeclaration(pattern);
context.addDeclaration(new DeclarationSpec(pattern.getIdentifier(), patternType, Optional.of(pattern), declarationSource));
if (constraintDescrs.isEmpty() && !(pattern.getSource() instanceof AccumulateDescr)) {
context.addExpression(addWatchToPattern(createPatternExpression(pattern)));
} else {
if (!context.hasErrors()) {
final List<PatternConstraintParseResult> patternConstraintParseResults = findAllConstraint(pattern, constraintDescrs, patternType);
MethodCallExpr patternExpression = createPatternExpression(pattern);
List<Expression> exprs = new ArrayList<>();
context.pushExprPointer(exprs::add);
buildConstraints(pattern, patternType, patternConstraintParseResults);
context.popExprPointer();
List<Expression> additionalPatterns = new ArrayList<>();
for (Expression expr : exprs) {
Optional<Expression> rootScope = findRootNodeViaScope(expr);
if (rootScope.isPresent() && ((MethodCallExpr) rootScope.get()).getNameAsString().equals("pattern")) {
additionalPatterns.add(expr);
} else {
MethodCallExpr currentExpr = (MethodCallExpr) expr;
((MethodCallExpr) expr).setScope(patternExpression);
patternExpression = currentExpr;
}
}
context.addExpression(addWatchToPattern(patternExpression));
additionalPatterns.forEach(context::addExpression);
}
}
}
use of org.drools.javaparser.ast.expr.Expression in project drools by kiegroup.
the class QueryCall method buildPattern.
@Override
public void buildPattern() {
MethodCallExpr callMethod = new MethodCallExpr(new NameExpr(queryDef), QUERY_INVOCATION_CALL);
callMethod.addArgument("" + !pattern.isQuery());
List<QueryParameter> parameters = packageModel.getQueryDefWithType().get(queryDef).getContext().getQueryParameters();
for (int i = 0; i < parameters.size(); i++) {
String queryName = context.getQueryName().orElseThrow(RuntimeException::new);
ExprConstraintDescr variableExpr = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(i);
String variableName = variableExpr.toString();
int unifPos = variableName.indexOf(":=");
if (unifPos > 0) {
variableName = variableName.substring(0, unifPos).trim();
}
Optional<String> unificationId = context.getUnificationId(variableName);
int queryIndex = i + 1;
Expression parameterCall = unificationId.map(name -> (Expression) new NameExpr(toVar(name))).orElseGet(() -> new MethodCallExpr(new NameExpr(queryName), QueryGenerator.toQueryArg(queryIndex)));
callMethod.addArgument(parameterCall);
}
context.addExpression(callMethod);
}
Aggregations