Search in sources :

Example 11 with DrlNameExpr

use of org.drools.mvel.parser.ast.expr.DrlNameExpr in project drools by kiegroup.

the class PreprocessPhase method assignToFieldAccess.

private AssignExpr assignToFieldAccess(PreprocessPhaseResult result, Expression scope, AssignExpr assignExpr) {
    DrlNameExpr originalFieldAccess = (DrlNameExpr) assignExpr.getTarget();
    String propertyName = originalFieldAccess.getName().asString();
    result.addUsedBinding(printNode(scope));
    FieldAccessExpr fieldAccessWithScope = new FieldAccessExpr(scope, propertyName);
    assignExpr.setTarget(fieldAccessWithScope);
    return assignExpr;
}
Also used : DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr)

Example 12 with DrlNameExpr

use of org.drools.mvel.parser.ast.expr.DrlNameExpr in project drools by kiegroup.

the class PreprocessPhase method addScopeToMethodCallExpr.

private Statement addScopeToMethodCallExpr(PreprocessPhaseResult result, Expression scope, Statement e) {
    if (e != null && e.isExpressionStmt()) {
        Expression expression = e.asExpressionStmt().getExpression();
        if (expression.isMethodCallExpr()) {
            MethodCallExpr mcExpr = expression.asMethodCallExpr();
            MethodCallExpr rootMcExpr = findRootScope(mcExpr);
            if (rootMcExpr == null) {
                return e;
            }
            Expression enclosed = new EnclosedExpr(scope);
            rootMcExpr.setScope(enclosed);
            if (scope.isNameExpr() || scope instanceof DrlNameExpr) {
                // some classes such "AtomicInteger" have a setter called "set"
                result.addUsedBinding(printNode(scope));
            }
            return new ExpressionStmt(mcExpr);
        }
    }
    return e;
}
Also used : Expression(com.github.javaparser.ast.expr.Expression) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) EnclosedExpr(com.github.javaparser.ast.expr.EnclosedExpr) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 13 with DrlNameExpr

use of org.drools.mvel.parser.ast.expr.DrlNameExpr in project drools by kiegroup.

the class AccumulateVisitor method parseFirstParameter.

private Optional<NewBinding> parseFirstParameter(PatternDescr basePattern, BaseDescr input, AccumulateDescr.AccumulateFunctionCallDescr function, MethodCallExpr functionDSL, String bindingId) {
    final String accumulateFunctionParameterStr = function.getParams()[0];
    final Expression accumulateFunctionParameter = DrlxParseUtil.parseExpression(accumulateFunctionParameterStr).getExpr();
    if (accumulateFunctionParameter instanceof BinaryExpr) {
        return binaryExprParameter(basePattern, function, functionDSL, bindingId, accumulateFunctionParameterStr);
    }
    if (parameterNeedsConvertionToMethodCallExpr(accumulateFunctionParameter)) {
        return methodCallExprParameter(basePattern, input, function, functionDSL, bindingId, accumulateFunctionParameter);
    }
    if (accumulateFunctionParameter instanceof DrlNameExpr) {
        nameExprParameter(basePattern, function, functionDSL, bindingId, accumulateFunctionParameter);
    } else if (accumulateFunctionParameter instanceof LiteralExpr) {
        literalExprParameter(basePattern, function, functionDSL, bindingId, accumulateFunctionParameter);
    } else {
        context.addCompilationError(new InvalidExpressionErrorResult("Invalid expression " + accumulateFunctionParameterStr, Optional.of(context.getRuleDescr())));
        throw new AccumulateParsingFailedException();
    }
    return Optional.empty();
}
Also used : InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) Expression(com.github.javaparser.ast.expr.Expression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) LiteralExpr(com.github.javaparser.ast.expr.LiteralExpr)

Aggregations

DrlNameExpr (org.drools.mvel.parser.ast.expr.DrlNameExpr)13 Expression (com.github.javaparser.ast.expr.Expression)12 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)8 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)7 NameExpr (com.github.javaparser.ast.expr.NameExpr)7 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)6 LiteralExpr (com.github.javaparser.ast.expr.LiteralExpr)6 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)6 FieldAccessExpr (com.github.javaparser.ast.expr.FieldAccessExpr)5 DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)5 NodeList (com.github.javaparser.ast.NodeList)4 CastExpr (com.github.javaparser.ast.expr.CastExpr)4 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)4 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)4 ThisExpr (com.github.javaparser.ast.expr.ThisExpr)4 UnaryExpr (com.github.javaparser.ast.expr.UnaryExpr)4 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)4 ArrayAccessExpr (com.github.javaparser.ast.expr.ArrayAccessExpr)3 ArrayCreationExpr (com.github.javaparser.ast.expr.ArrayCreationExpr)3 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)3