Search in sources :

Example 26 with MethodCallExpr

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;
}
Also used : PackageModel(org.drools.modelcompiler.builder.PackageModel) Parameter(org.drools.javaparser.ast.body.Parameter) Expression(org.drools.javaparser.ast.expr.Expression) ModelGeneratorVisitor(org.drools.modelcompiler.builder.generator.visitor.ModelGeneratorVisitor) Collection(java.util.Collection) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) BIND_CALL(org.drools.modelcompiler.builder.generator.expression.FlowExpressionBuilder.BIND_CALL) NameExpr(org.drools.javaparser.ast.expr.NameExpr) DrlxParseUtil.fromVar(org.drools.modelcompiler.builder.generator.DrlxParseUtil.fromVar) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) List(java.util.List) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr) DrlxParseUtil.toVar(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toVar) Optional(java.util.Optional) LambdaExpr(org.drools.javaparser.ast.expr.LambdaExpr) PatternExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.PatternExpressionBuilder) Node(org.drools.javaparser.ast.Node) NameExpr(org.drools.javaparser.ast.expr.NameExpr) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 27 with MethodCallExpr

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;
}
Also used : PackageModel(org.drools.modelcompiler.builder.PackageModel) Parameter(org.drools.javaparser.ast.body.Parameter) Expression(org.drools.javaparser.ast.expr.Expression) ModelGeneratorVisitor(org.drools.modelcompiler.builder.generator.visitor.ModelGeneratorVisitor) Collection(java.util.Collection) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) BIND_CALL(org.drools.modelcompiler.builder.generator.expression.FlowExpressionBuilder.BIND_CALL) NameExpr(org.drools.javaparser.ast.expr.NameExpr) DrlxParseUtil.fromVar(org.drools.modelcompiler.builder.generator.DrlxParseUtil.fromVar) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) List(java.util.List) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr) DrlxParseUtil.toVar(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toVar) Optional(java.util.Optional) LambdaExpr(org.drools.javaparser.ast.expr.LambdaExpr) PatternExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.PatternExpressionBuilder) Node(org.drools.javaparser.ast.Node) Expression(org.drools.javaparser.ast.expr.Expression) LambdaExpr(org.drools.javaparser.ast.expr.LambdaExpr) NameExpr(org.drools.javaparser.ast.expr.NameExpr) Parameter(org.drools.javaparser.ast.body.Parameter) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 28 with MethodCallExpr

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();
    }
}
Also used : MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 29 with MethodCallExpr

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;
}
Also used : ArrayList(java.util.ArrayList) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Example 30 with MethodCallExpr

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);
}
Also used : QueryParameter(org.drools.modelcompiler.builder.generator.QueryParameter) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) NameExpr(org.drools.javaparser.ast.expr.NameExpr) MethodCallExpr(org.drools.javaparser.ast.expr.MethodCallExpr)

Aggregations

MethodCallExpr (org.drools.javaparser.ast.expr.MethodCallExpr)75 NameExpr (org.drools.javaparser.ast.expr.NameExpr)36 Expression (org.drools.javaparser.ast.expr.Expression)32 StringLiteralExpr (org.drools.javaparser.ast.expr.StringLiteralExpr)26 ArrayList (java.util.ArrayList)16 List (java.util.List)15 ClassExpr (org.drools.javaparser.ast.expr.ClassExpr)15 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)14 FieldAccessExpr (org.drools.javaparser.ast.expr.FieldAccessExpr)13 PackageModel (org.drools.modelcompiler.builder.PackageModel)13 Parameter (org.drools.javaparser.ast.body.Parameter)11 LambdaExpr (org.drools.javaparser.ast.expr.LambdaExpr)11 ClassOrInterfaceType (org.drools.javaparser.ast.type.ClassOrInterfaceType)11 Collection (java.util.Collection)10 Optional (java.util.Optional)10 Type (org.drools.javaparser.ast.type.Type)10 RuleContext (org.drools.modelcompiler.builder.generator.RuleContext)10 BinaryExpr (org.drools.javaparser.ast.expr.BinaryExpr)9 DeclarationSpec (org.drools.modelcompiler.builder.generator.DeclarationSpec)9 JavaParser (org.drools.javaparser.JavaParser)8