Search in sources :

Example 51 with Expression

use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.

the class ExpressionTyper method toTypedExpressionRec.

private Optional<TypedExpression> toTypedExpressionRec(Expression drlxExpr) {
    Class<?> typeCursor = patternType;
    if (drlxExpr instanceof FullyQualifiedInlineCastExpr) {
        return toTypedExpressionRec(transformFullyQualifiedInlineCastExpr(ruleContext.getTypeResolver(), (FullyQualifiedInlineCastExpr) drlxExpr));
    }
    if (drlxExpr instanceof EnclosedExpr) {
        Expression inner = ((EnclosedExpr) drlxExpr).getInner();
        Optional<TypedExpression> typedExpression = toTypedExpressionRec(inner);
        return typedExpression.map(t -> t.cloneWithNewExpression(new EnclosedExpr(t.getExpression())));
    }
    if (drlxExpr instanceof MethodCallExpr) {
        MethodCallExpr methodExpr = (MethodCallExpr) drlxExpr;
        Expression expr = methodExpr;
        if (isEval(methodExpr.getNameAsString(), methodExpr.getScope(), methodExpr.getArguments())) {
            expr = methodExpr.getArgument(0);
        }
        drlxExpr = expr;
    }
    if (drlxExpr instanceof NullSafeMethodCallExpr) {
        NullSafeMethodCallExpr methodExpr = (NullSafeMethodCallExpr) drlxExpr;
        Expression expr = methodExpr;
        if (isEval(methodExpr.getNameAsString(), methodExpr.getScope(), methodExpr.getArguments())) {
            expr = methodExpr.getArgument(0);
        }
        drlxExpr = expr;
    }
    if (drlxExpr instanceof UnaryExpr) {
        UnaryExpr unaryExpr = (UnaryExpr) drlxExpr;
        Optional<TypedExpression> optTypedExpr = toTypedExpressionRec(unaryExpr.getExpression());
        return optTypedExpr.map(typedExpr -> new TypedExpression(new UnaryExpr(typedExpr.getExpression(), unaryExpr.getOperator()), typedExpr.getType()));
    }
    if (drlxExpr instanceof BinaryExpr) {
        BinaryExpr binaryExpr = (BinaryExpr) drlxExpr;
        BinaryExpr.Operator operator = binaryExpr.getOperator();
        Optional<TypedExpression> optLeft = toTypedExpressionRec(binaryExpr.getLeft());
        Optional<TypedExpression> optRight = toTypedExpressionRec(binaryExpr.getRight());
        return optLeft.flatMap(left -> optRight.flatMap(right -> {
            final BinaryExpr combo = new BinaryExpr(left.getExpression(), right.getExpression(), operator);
            return of(new TypedExpression(combo, left.getType()));
        }));
    }
    if (drlxExpr instanceof HalfBinaryExpr) {
        final Expression binaryExpr = trasformHalfBinaryToBinary(drlxExpr);
        if (binaryExpr instanceof BinaryExpr && ((BinaryExpr) binaryExpr).getLeft() == drlxExpr) {
            throw new CannotTypeExpressionException("left leaf is the same : drlxExpr = " + drlxExpr + ", originalExpression = " + context.getOriginalExpression());
        }
        return toTypedExpressionRec(binaryExpr);
    }
    if (drlxExpr instanceof LiteralExpr) {
        drlxExpr = normalizeDigit(drlxExpr);
        return of(new TypedExpression(drlxExpr, getLiteralExpressionType((LiteralExpr) drlxExpr)));
    }
    if (drlxExpr instanceof ThisExpr || (drlxExpr instanceof NameExpr && THIS_PLACEHOLDER.equals(printNode(drlxExpr)))) {
        return of(new TypedExpression(new NameExpr(THIS_PLACEHOLDER), patternType));
    }
    if (drlxExpr instanceof CastExpr) {
        CastExpr castExpr = (CastExpr) drlxExpr;
        Optional<TypedExpression> optTypedExpr = toTypedExpressionRec(castExpr.getExpression());
        return optTypedExpr.map(typedExpr -> new TypedExpression(new CastExpr(castExpr.getType(), typedExpr.getExpression()), getClassFromContext(ruleContext.getTypeResolver(), castExpr.getType().asString())));
    }
    if (drlxExpr instanceof NameExpr) {
        return nameExpr(((NameExpr) drlxExpr).getNameAsString(), typeCursor);
    }
    if (drlxExpr instanceof FieldAccessExpr || drlxExpr instanceof MethodCallExpr || drlxExpr instanceof ObjectCreationExpr || drlxExpr instanceof NullSafeFieldAccessExpr || drlxExpr instanceof NullSafeMethodCallExpr || drlxExpr instanceof MapCreationLiteralExpression || drlxExpr instanceof ListCreationLiteralExpression) {
        return toTypedExpressionFromMethodCallOrField(drlxExpr).getTypedExpression();
    }
    if (drlxExpr instanceof PointFreeExpr) {
        final PointFreeExpr pointFreeExpr = (PointFreeExpr) drlxExpr;
        Optional<TypedExpression> optLeft = toTypedExpressionRec(pointFreeExpr.getLeft());
        Optional<TypedExpression> optRight = pointFreeExpr.getRight().size() == 1 ? toTypedExpressionRec(pointFreeExpr.getRight().get(0)) : Optional.empty();
        OperatorSpec opSpec = getOperatorSpec(pointFreeExpr.getRight(), pointFreeExpr.getOperator());
        return optLeft.map(left -> new TypedExpression(opSpec.getExpression(ruleContext, pointFreeExpr, left, this), left.getType()).setStatic(opSpec.isStatic()).setLeft(left).setRight(optRight.orElse(null)));
    }
    if (drlxExpr instanceof HalfPointFreeExpr) {
        final HalfPointFreeExpr halfPointFreeExpr = (HalfPointFreeExpr) drlxExpr;
        Expression parentLeft = findLeftLeafOfNameExprTraversingParent(halfPointFreeExpr);
        if (parentLeft == halfPointFreeExpr) {
            throw new CannotTypeExpressionException("left leaf is the same : halfPointFreeExpr = " + halfPointFreeExpr + ", originalExpression = " + context.getOriginalExpression());
        }
        Optional<TypedExpression> optLeft = toTypedExpressionRec(parentLeft);
        OperatorSpec opSpec = getOperatorSpec(halfPointFreeExpr.getRight(), halfPointFreeExpr.getOperator());
        final PointFreeExpr transformedToPointFree = new PointFreeExpr(halfPointFreeExpr.getTokenRange().orElseThrow(() -> new IllegalStateException("Token range is not present!")), parentLeft, halfPointFreeExpr.getRight(), halfPointFreeExpr.getOperator(), halfPointFreeExpr.isNegated(), halfPointFreeExpr.getArg1(), halfPointFreeExpr.getArg2(), halfPointFreeExpr.getArg3(), halfPointFreeExpr.getArg4());
        return optLeft.map(left -> new TypedExpression(opSpec.getExpression(ruleContext, transformedToPointFree, left, this), left.getType()).setStatic(opSpec.isStatic()).setLeft(left));
    }
    if (drlxExpr instanceof ArrayAccessExpr) {
        final ArrayAccessExpr arrayAccessExpr = (ArrayAccessExpr) drlxExpr;
        if (Map.class.isAssignableFrom(typeCursor)) {
            return createMapAccessExpression(arrayAccessExpr.getIndex(), arrayAccessExpr.getName() instanceof ThisExpr ? new NameExpr(THIS_PLACEHOLDER) : arrayAccessExpr.getName(), Map.class);
        } else if (arrayAccessExpr.getName() instanceof FieldAccessExpr) {
            Optional<TypedExpression> typedExpression = toTypedExpressionFromMethodCallOrField(drlxExpr).getTypedExpression();
            typedExpression.ifPresent(te -> {
                final Expression originalExpression = te.getExpression();
                DrlxParseUtil.removeRootNode(originalExpression);
            });
            return typedExpression;
        } else {
            String name = printNode(drlxExpr.asArrayAccessExpr().getName());
            final Optional<TypedExpression> nameExpr = nameExpr(name, typeCursor);
            Expression indexExpr = toTypedExpressionFromMethodCallOrField(arrayAccessExpr.getIndex()).getTypedExpression().orElseThrow(() -> new NoSuchElementException("TypedExpressionResult doesn't contain TypedExpression!")).getExpression();
            return nameExpr.flatMap(te -> transformToArrayOrMapExpressionWithType(indexExpr, te));
        }
    }
    if (drlxExpr instanceof InstanceOfExpr) {
        InstanceOfExpr instanceOfExpr = (InstanceOfExpr) drlxExpr;
        ruleContext.addInlineCastType(printNode(instanceOfExpr.getExpression()), instanceOfExpr.getType());
        return toTypedExpressionRec(instanceOfExpr.getExpression()).map(e -> new TypedExpression(new InstanceOfExpr(e.getExpression(), instanceOfExpr.getType()), boolean.class));
    }
    if (drlxExpr instanceof ClassExpr) {
        return of(new TypedExpression(drlxExpr, Class.class));
    }
    if (drlxExpr instanceof InlineCastExpr) {
        return toTypedExpressionFromMethodCallOrField(drlxExpr).getTypedExpression();
    }
    if (drlxExpr instanceof OOPathExpr) {
        Class<?> type = patternType;
        for (OOPathChunk chunk : ((OOPathExpr) drlxExpr).getChunks()) {
            final String fieldName = chunk.getField().toString();
            final TypedExpression callExpr = DrlxParseUtil.nameExprToMethodCallExpr(fieldName, type, null, ruleContext);
            if (callExpr == null) {
                return empty();
            }
            Class<?> fieldType = (chunk.getInlineCast() != null) ? DrlxParseUtil.getClassFromContext(ruleContext.getTypeResolver(), chunk.getInlineCast().toString()) : callExpr.getRawClass();
            if (!chunk.isSingleValue() && Iterable.class.isAssignableFrom(fieldType) || isDataSource(fieldType)) {
                type = extractGenericType(type, ((MethodCallExpr) callExpr.getExpression()).getName().toString());
            } else {
                type = fieldType;
            }
        }
        return of(new TypedExpression(drlxExpr, type));
    }
    if (drlxExpr.isAssignExpr()) {
        AssignExpr assignExpr = drlxExpr.asAssignExpr();
        final Expression rightSide = assignExpr.getValue();
        return toTypedExpressionRec(rightSide).map(e -> {
            final AssignExpr newExpression = new AssignExpr(assignExpr.getTarget(), e.getExpression(), assignExpr.getOperator());
            return new TypedExpression(newExpression, e.getType());
        });
    }
    throw new UnsupportedOperationException();
}
Also used : ArrayAccessExpr(com.github.javaparser.ast.expr.ArrayAccessExpr) Arrays(java.util.Arrays) ClassExpr(com.github.javaparser.ast.expr.ClassExpr) HalfPointFreeExpr(org.drools.mvel.parser.ast.expr.HalfPointFreeExpr) DrlxParseUtil.findRootNodeViaParent(org.drools.modelcompiler.builder.generator.DrlxParseUtil.findRootNodeViaParent) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) NodeList.nodeList(com.github.javaparser.ast.NodeList.nodeList) Optional.of(java.util.Optional.of) InstanceOfExpr(com.github.javaparser.ast.expr.InstanceOfExpr) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) ParseExpressionErrorResult(org.drools.modelcompiler.builder.errors.ParseExpressionErrorResult) FlattenScope.flattenScope(org.drools.modelcompiler.builder.generator.expressiontyper.FlattenScope.flattenScope) LiteralExpr(com.github.javaparser.ast.expr.LiteralExpr) CharLiteralExpr(com.github.javaparser.ast.expr.CharLiteralExpr) Type(com.github.javaparser.ast.type.Type) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) FlattenScope.transformFullyQualifiedInlineCastExpr(org.drools.modelcompiler.builder.generator.expressiontyper.FlattenScope.transformFullyQualifiedInlineCastExpr) ClassUtil.toRawClass(org.drools.modelcompiler.util.ClassUtil.toRawClass) DrlxParseUtil.getClassFromContext(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getClassFromContext) OperatorSpec(org.drools.modelcompiler.builder.generator.operatorspec.OperatorSpec) OOPathExpr(org.drools.mvel.parser.ast.expr.OOPathExpr) PackageModel(org.drools.modelcompiler.builder.PackageModel) SimpleName(com.github.javaparser.ast.expr.SimpleName) ArrayCreationExpr(com.github.javaparser.ast.expr.ArrayCreationExpr) DrlxParseUtil.getExpressionType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getExpressionType) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) MapCreationLiteralExpressionKeyValuePair(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpressionKeyValuePair) MethodUtils(org.drools.core.util.MethodUtils) UnaryExpr(com.github.javaparser.ast.expr.UnaryExpr) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ArrayInitializerExpr(com.github.javaparser.ast.expr.ArrayInitializerExpr) Optional.empty(java.util.Optional.empty) DrlxParseUtil.replaceAllHalfBinaryChildren(org.drools.modelcompiler.builder.generator.DrlxParseUtil.replaceAllHalfBinaryChildren) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) CastExpr(com.github.javaparser.ast.expr.CastExpr) ArrayList(java.util.ArrayList) NullSafeMethodCallExpr(org.drools.mvel.parser.ast.expr.NullSafeMethodCallExpr) DrlxParseUtil.transformDrlNameExprToNameExpr(org.drools.modelcompiler.builder.generator.DrlxParseUtil.transformDrlNameExprToNameExpr) ListCreationLiteralExpressionElement(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpressionElement) UnificationTypedExpression(org.drools.modelcompiler.builder.generator.UnificationTypedExpression) TypeVariable(java.lang.reflect.TypeVariable) NativeOperatorSpec(org.drools.modelcompiler.builder.generator.operatorspec.NativeOperatorSpec) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) InlineCastExpr(org.drools.mvel.parser.ast.expr.InlineCastExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) Field(java.lang.reflect.Field) InitializerDeclaration(com.github.javaparser.ast.body.InitializerDeclaration) ParameterizedType(java.lang.reflect.ParameterizedType) ModelGenerator(org.drools.modelcompiler.builder.generator.ModelGenerator) MapCreationLiteralExpression(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) DrlxParseUtil.prepend(org.drools.modelcompiler.builder.generator.DrlxParseUtil.prepend) DrlxParseUtil.getClassFromType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getClassFromType) TypeResolver(org.drools.core.addon.TypeResolver) TemporalOperatorSpec(org.drools.modelcompiler.builder.generator.operatorspec.TemporalOperatorSpec) LoggerFactory(org.slf4j.LoggerFactory) ThisExpr(com.github.javaparser.ast.expr.ThisExpr) InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) ClassUtils.getter2property(org.drools.core.util.ClassUtils.getter2property) DrlxParseUtil.isThisExpression(org.drools.modelcompiler.builder.generator.DrlxParseUtil.isThisExpression) CustomOperatorSpec(org.drools.modelcompiler.builder.generator.operatorspec.CustomOperatorSpec) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) Method(java.lang.reflect.Method) Node(com.github.javaparser.ast.Node) NodeList(com.github.javaparser.ast.NodeList) ReferenceType(com.github.javaparser.ast.type.ReferenceType) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) ListCreationLiteralExpression(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression) OOPathChunk(org.drools.mvel.parser.ast.expr.OOPathChunk) FullyQualifiedInlineCastExpr(org.drools.mvel.parser.ast.expr.FullyQualifiedInlineCastExpr) DrlxParseUtil.safeResolveType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.safeResolveType) THIS_PLACEHOLDER(org.drools.modelcompiler.builder.generator.DrlxParseUtil.THIS_PLACEHOLDER) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) EnclosedExpr(com.github.javaparser.ast.expr.EnclosedExpr) List(java.util.List) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) DrlxParseUtil.nameExprToMethodCallExpr(org.drools.modelcompiler.builder.generator.DrlxParseUtil.nameExprToMethodCallExpr) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) MvelParser.parseType(org.drools.mvel.parser.MvelParser.parseType) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr) DrlxParseUtil.toStringLiteral(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toStringLiteral) NodeWithArguments(com.github.javaparser.ast.nodeTypes.NodeWithArguments) HashMap(java.util.HashMap) ClassUtils.extractGenericType(org.drools.core.util.ClassUtils.extractGenericType) PointFreeExpr(org.drools.mvel.parser.ast.expr.PointFreeExpr) DoubleLiteralExpr(com.github.javaparser.ast.expr.DoubleLiteralExpr) DrlxParseUtil.getLiteralExpressionType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getLiteralExpressionType) ClassUtil.getTypeArgument(org.drools.modelcompiler.util.ClassUtil.getTypeArgument) RuleUnitUtil.isDataSource(org.kie.internal.ruleunit.RuleUnitUtil.isDataSource) NoSuchElementException(java.util.NoSuchElementException) Logger(org.slf4j.Logger) AssignExpr(com.github.javaparser.ast.expr.AssignExpr) NullSafeFieldAccessExpr(org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr) PrintUtil(org.drools.mvel.parser.printer.PrintUtil) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) DrlxParseUtil.trasformHalfBinaryToBinary(org.drools.modelcompiler.builder.generator.DrlxParseUtil.trasformHalfBinaryToBinary) BigDecimalArgumentCoercion(org.drools.mvelcompiler.util.BigDecimalArgumentCoercion) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) DrlxParseUtil.transformDrlNameExprToNameExpr(org.drools.modelcompiler.builder.generator.DrlxParseUtil.transformDrlNameExprToNameExpr) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) AssignExpr(com.github.javaparser.ast.expr.AssignExpr) OperatorSpec(org.drools.modelcompiler.builder.generator.operatorspec.OperatorSpec) NativeOperatorSpec(org.drools.modelcompiler.builder.generator.operatorspec.NativeOperatorSpec) TemporalOperatorSpec(org.drools.modelcompiler.builder.generator.operatorspec.TemporalOperatorSpec) CustomOperatorSpec(org.drools.modelcompiler.builder.generator.operatorspec.CustomOperatorSpec) OOPathExpr(org.drools.mvel.parser.ast.expr.OOPathExpr) OOPathChunk(org.drools.mvel.parser.ast.expr.OOPathChunk) FlattenScope.transformFullyQualifiedInlineCastExpr(org.drools.modelcompiler.builder.generator.expressiontyper.FlattenScope.transformFullyQualifiedInlineCastExpr) CastExpr(com.github.javaparser.ast.expr.CastExpr) InlineCastExpr(org.drools.mvel.parser.ast.expr.InlineCastExpr) FullyQualifiedInlineCastExpr(org.drools.mvel.parser.ast.expr.FullyQualifiedInlineCastExpr) NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) LiteralExpr(com.github.javaparser.ast.expr.LiteralExpr) CharLiteralExpr(com.github.javaparser.ast.expr.CharLiteralExpr) StringLiteralExpr(com.github.javaparser.ast.expr.StringLiteralExpr) DoubleLiteralExpr(com.github.javaparser.ast.expr.DoubleLiteralExpr) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr) NullSafeFieldAccessExpr(org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr) UnificationTypedExpression(org.drools.modelcompiler.builder.generator.UnificationTypedExpression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) ThisExpr(com.github.javaparser.ast.expr.ThisExpr) ListCreationLiteralExpression(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) Optional(java.util.Optional) ArrayAccessExpr(com.github.javaparser.ast.expr.ArrayAccessExpr) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) HalfBinaryExpr(org.drools.mvel.parser.ast.expr.HalfBinaryExpr) HalfPointFreeExpr(org.drools.mvel.parser.ast.expr.HalfPointFreeExpr) PointFreeExpr(org.drools.mvel.parser.ast.expr.PointFreeExpr) FlattenScope.transformFullyQualifiedInlineCastExpr(org.drools.modelcompiler.builder.generator.expressiontyper.FlattenScope.transformFullyQualifiedInlineCastExpr) InlineCastExpr(org.drools.mvel.parser.ast.expr.InlineCastExpr) FullyQualifiedInlineCastExpr(org.drools.mvel.parser.ast.expr.FullyQualifiedInlineCastExpr) HalfPointFreeExpr(org.drools.mvel.parser.ast.expr.HalfPointFreeExpr) UnaryExpr(com.github.javaparser.ast.expr.UnaryExpr) InstanceOfExpr(com.github.javaparser.ast.expr.InstanceOfExpr) NullSafeFieldAccessExpr(org.drools.mvel.parser.ast.expr.NullSafeFieldAccessExpr) MapCreationLiteralExpression(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression) Expression(com.github.javaparser.ast.expr.Expression) UnificationTypedExpression(org.drools.modelcompiler.builder.generator.UnificationTypedExpression) MapCreationLiteralExpression(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression) DrlxParseUtil.isThisExpression(org.drools.modelcompiler.builder.generator.DrlxParseUtil.isThisExpression) ListCreationLiteralExpression(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) ClassExpr(com.github.javaparser.ast.expr.ClassExpr) ClassUtil.toRawClass(org.drools.modelcompiler.util.ClassUtil.toRawClass) NullSafeMethodCallExpr(org.drools.mvel.parser.ast.expr.NullSafeMethodCallExpr) EnclosedExpr(com.github.javaparser.ast.expr.EnclosedExpr) FlattenScope.transformFullyQualifiedInlineCastExpr(org.drools.modelcompiler.builder.generator.expressiontyper.FlattenScope.transformFullyQualifiedInlineCastExpr) FullyQualifiedInlineCastExpr(org.drools.mvel.parser.ast.expr.FullyQualifiedInlineCastExpr) NoSuchElementException(java.util.NoSuchElementException) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) NullSafeMethodCallExpr(org.drools.mvel.parser.ast.expr.NullSafeMethodCallExpr) DrlxParseUtil.nameExprToMethodCallExpr(org.drools.modelcompiler.builder.generator.DrlxParseUtil.nameExprToMethodCallExpr)

Example 52 with Expression

use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.

the class AccumulateVisitor method buildConstraintExpression.

protected Expression buildConstraintExpression(Expression expr, Collection<String> usedDeclarations) {
    LambdaExpr lambdaExpr = new LambdaExpr();
    lambdaExpr.setEnclosingParameters(true);
    usedDeclarations.stream().map(s -> new Parameter(context.getDelarationType(s), s)).forEach(lambdaExpr::addParameter);
    lambdaExpr.setBody(new ExpressionStmt(expr));
    return lambdaExpr;
}
Also used : REACT_ON_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.REACT_ON_CALL) ModelGeneratorVisitor(org.drools.modelcompiler.builder.generator.visitor.ModelGeneratorVisitor) ACCUMULATE_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.ACCUMULATE_CALL) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) PatternDescr(org.drools.drl.ast.descr.PatternDescr) InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) ExpressionTyperContext(org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyperContext) LiteralExpr(com.github.javaparser.ast.expr.LiteralExpr) AccumulateUtil(org.drools.compiler.rule.builder.util.AccumulateUtil) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) Expression(com.github.javaparser.ast.expr.Expression) ConstraintParser(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintParser) PatternExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.PatternExpressionBuilder) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) Node(com.github.javaparser.ast.Node) PackageModel(org.drools.modelcompiler.builder.PackageModel) NodeList(com.github.javaparser.ast.NodeList) AND_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.AND_CALL) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Set(java.util.Set) LambdaUtil(org.drools.modelcompiler.util.LambdaUtil) BaseDescr(org.drools.drl.ast.descr.BaseDescr) VALUE_OF_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.VALUE_OF_CALL) Objects(java.util.Objects) List(java.util.List) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail) DrlxParseUtil.validateDuplicateBindings(org.drools.modelcompiler.builder.generator.DrlxParseUtil.validateDuplicateBindings) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) AbstractExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.AbstractExpressionBuilder) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) Parameter(com.github.javaparser.ast.body.Parameter) Pattern(org.drools.core.rule.Pattern) ArrayList(java.util.ArrayList) ACC_FUNCTION_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.ACC_FUNCTION_CALL) HashSet(java.util.HashSet) CollectListAccumulateFunction(org.drools.core.base.accumulators.CollectListAccumulateFunction) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) DrlxParseUtil.getLiteralExpressionType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getLiteralExpressionType) DslMethodNames.createDslTopLevelMethod(org.drools.modelcompiler.builder.generator.DslMethodNames.createDslTopLevelMethod) AndDescr(org.drools.drl.ast.descr.AndDescr) ReplaceTypeInLambda.replaceTypeInExprLambda(org.drools.modelcompiler.util.lambdareplace.ReplaceTypeInLambda.replaceTypeInExprLambda) BIND_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.BIND_CALL) Optional.ofNullable(java.util.Optional.ofNullable) BIND_AS_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.BIND_AS_CALL) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr) ExpressionTyper(org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyper) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) Collectors.toList(java.util.stream.Collectors.toList) CollectAccumulator(org.drools.core.base.accumulators.CollectAccumulator) CollectSetAccumulateFunction(org.drools.core.base.accumulators.CollectSetAccumulateFunction) ParseResultVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVisitor) Collections(java.util.Collections) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) Parameter(com.github.javaparser.ast.body.Parameter) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt)

Example 53 with Expression

use of com.github.javaparser.ast.expr.Expression 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));
    });
}
Also used : DrlxParseUtil.validateDuplicateBindings(org.drools.modelcompiler.builder.generator.DrlxParseUtil.validateDuplicateBindings) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) AggregateKey(org.drools.modelcompiler.builder.generator.AggregateKey) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) PatternSourceDescr(org.drools.drl.ast.descr.PatternSourceDescr) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) DescrBuildError(org.drools.compiler.compiler.DescrBuildError) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) ConstraintExpression(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintExpression) DrlxParseUtil.getPatternListenedProperties(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getPatternListenedProperties) PatternDescr(org.drools.drl.ast.descr.PatternDescr) InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) GENERATED_VARIABLE_PREFIX(org.drools.model.impl.VariableImpl.GENERATED_VARIABLE_PREFIX) ConstraintUtil(org.drools.modelcompiler.builder.generator.ConstraintUtil) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) NamesGenerator.generateName(org.drools.model.impl.NamesGenerator.generateName) Expression(com.github.javaparser.ast.expr.Expression) ConstraintParser(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintParser) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) PackageModel(org.drools.modelcompiler.builder.PackageModel) WindowReferenceGenerator(org.drools.modelcompiler.builder.generator.WindowReferenceGenerator) ClassUtils(org.drools.core.util.ClassUtils) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Set(java.util.Set) PatternBuilder.lookAheadFieldsOfIdentifier(org.drools.compiler.rule.builder.PatternBuilder.lookAheadFieldsOfIdentifier) StreamUtils.optionalToStream(org.drools.modelcompiler.util.StreamUtils.optionalToStream) FromVisitor(org.drools.modelcompiler.builder.generator.visitor.FromVisitor) Collectors(java.util.stream.Collectors) BaseDescr(org.drools.drl.ast.descr.BaseDescr) Objects(java.util.Objects) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) List(java.util.List) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) DSLNode(org.drools.modelcompiler.builder.generator.visitor.DSLNode) ParseResultVoidVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVoidVisitor) Watch(org.kie.api.definition.rule.Watch) Optional(java.util.Optional) ParseResultVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVisitor) Collections(java.util.Collections) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail) ConstraintExpression(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintExpression) Expression(com.github.javaparser.ast.expr.Expression) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) ParseResultVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVisitor) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail)

Example 54 with Expression

use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.

the class AccumulateVisitor method replaceBindingWithPatternBinding.

private MethodCallExpr replaceBindingWithPatternBinding(MethodCallExpr bindExpression, MethodCallExpr lastPattern) {
    // This method links a binding expression, used to evaluate the accumulated value,
    // to the last pattern in a multi-pattern accumulate like the following
    // 
    // accumulate( $c : Child( age < 10 ) and $a : Adult( name == $c.parent ) and $s : String( this == $a.name ),
    // $sum : sum($a.getAge() + $c.getAge() + $s.length()) )
    // 
    // In the case the bindExpression, that will have to be linked to the $s pattern, is originally generated as
    // 
    // bind(var_$sum, var_$a, var_$c, var_$s, (Adult $a, Child $c, String $s) -> $a.getAge() + $c.getAge() + $s.length())
    final Expression bindingId = lastPattern.getArgument(0);
    bindExpression.findFirst(NameExpr.class, e -> e.equals(bindingId)).ifPresent(name -> {
        // since the bind has to be linked to $s, the corresponding variable should be removed from the arguments list so it becomes
        // bind(var_$sum, var_$a, var_$c, (Adult $a, Child $c, String $s) -> $a.getAge() + $c.getAge() + $s.length())
        bindExpression.remove(name);
        // also the first formal parameter in the binding lambda has to be $s so it becomes
        // bind(var_$sum, var_$a, var_$c, (String $s, Adult $a, Child $c) -> $a.getAge() + $c.getAge() + $s.length())
        LambdaExpr lambda = (LambdaExpr) bindExpression.getArgument(bindExpression.getArguments().size() - 1);
        if (lambda.getParameters().size() > 1) {
            String formalArg = context.fromVar(name.getNameAsString());
            for (Parameter param : lambda.getParameters()) {
                if (param.getNameAsString().equals(formalArg)) {
                    lambda.getParameters().remove(param);
                    lambda.getParameters().add(0, param);
                    break;
                }
            }
        }
    });
    return bindExpression;
}
Also used : REACT_ON_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.REACT_ON_CALL) ModelGeneratorVisitor(org.drools.modelcompiler.builder.generator.visitor.ModelGeneratorVisitor) ACCUMULATE_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.ACCUMULATE_CALL) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) PatternDescr(org.drools.drl.ast.descr.PatternDescr) InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) ExpressionTyperContext(org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyperContext) LiteralExpr(com.github.javaparser.ast.expr.LiteralExpr) AccumulateUtil(org.drools.compiler.rule.builder.util.AccumulateUtil) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) Expression(com.github.javaparser.ast.expr.Expression) ConstraintParser(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintParser) PatternExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.PatternExpressionBuilder) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) Node(com.github.javaparser.ast.Node) PackageModel(org.drools.modelcompiler.builder.PackageModel) NodeList(com.github.javaparser.ast.NodeList) AND_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.AND_CALL) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Set(java.util.Set) LambdaUtil(org.drools.modelcompiler.util.LambdaUtil) BaseDescr(org.drools.drl.ast.descr.BaseDescr) VALUE_OF_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.VALUE_OF_CALL) Objects(java.util.Objects) List(java.util.List) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail) DrlxParseUtil.validateDuplicateBindings(org.drools.modelcompiler.builder.generator.DrlxParseUtil.validateDuplicateBindings) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) AbstractExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.AbstractExpressionBuilder) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) Parameter(com.github.javaparser.ast.body.Parameter) Pattern(org.drools.core.rule.Pattern) ArrayList(java.util.ArrayList) ACC_FUNCTION_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.ACC_FUNCTION_CALL) HashSet(java.util.HashSet) CollectListAccumulateFunction(org.drools.core.base.accumulators.CollectListAccumulateFunction) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) DrlxParseUtil.getLiteralExpressionType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getLiteralExpressionType) DslMethodNames.createDslTopLevelMethod(org.drools.modelcompiler.builder.generator.DslMethodNames.createDslTopLevelMethod) AndDescr(org.drools.drl.ast.descr.AndDescr) ReplaceTypeInLambda.replaceTypeInExprLambda(org.drools.modelcompiler.util.lambdareplace.ReplaceTypeInLambda.replaceTypeInExprLambda) BIND_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.BIND_CALL) Optional.ofNullable(java.util.Optional.ofNullable) BIND_AS_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.BIND_AS_CALL) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr) ExpressionTyper(org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyper) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) Collectors.toList(java.util.stream.Collectors.toList) CollectAccumulator(org.drools.core.base.accumulators.CollectAccumulator) CollectSetAccumulateFunction(org.drools.core.base.accumulators.CollectSetAccumulateFunction) ParseResultVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVisitor) Collections(java.util.Collections) Expression(com.github.javaparser.ast.expr.Expression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) Parameter(com.github.javaparser.ast.body.Parameter)

Example 55 with Expression

use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.

the class AccumulateVisitor method binaryExprParameter.

private Optional<NewBinding> binaryExprParameter(PatternDescr basePattern, AccumulateDescr.AccumulateFunctionCallDescr function, MethodCallExpr functionDSL, String bindingId, String accumulateFunctionParameterStr) {
    final DrlxParseResult parseResult = ConstraintParser.defaultConstraintParser(context, packageModel).drlxParse(Object.class, bindingId, accumulateFunctionParameterStr);
    Optional<NewBinding> optNewBinding = parseResult.acceptWithReturnValue(new ParseResultVisitor<Optional<NewBinding>>() {

        @Override
        public Optional<NewBinding> onSuccess(DrlxParseSuccess drlxParseResult) {
            SingleDrlxParseSuccess singleResult = (SingleDrlxParseSuccess) drlxParseResult;
            Class<?> exprRawClass = singleResult.getExprRawClass();
            AccumulateFunction accumulateFunction = getAccumulateFunction(function, exprRawClass);
            validateAccFunctionTypeAgainstPatternType(context, basePattern, accumulateFunction);
            final String bindExpressionVariable = context.getExprId(accumulateFunction.getResultType(), singleResult.getLeft().toString());
            singleResult.setExprBinding(bindExpressionVariable);
            context.addDeclarationReplacing(new DeclarationSpec(singleResult.getPatternBinding(), exprRawClass));
            context.getExpressions().forEach(expression -> replaceTypeInExprLambda(bindingId, exprRawClass, expression));
            functionDSL.addArgument(createAccSupplierExpr(accumulateFunction));
            final MethodCallExpr newBindingFromBinary = AccumulateVisitor.this.buildBinding(bindExpressionVariable, singleResult.getUsedDeclarations(), singleResult.getExpr());
            context.addDeclarationReplacing(new DeclarationSpec(bindExpressionVariable, exprRawClass));
            functionDSL.addArgument(context.getVarExpr(bindExpressionVariable));
            return Optional.of(new NewBinding(Collections.emptyList(), newBindingFromBinary));
        }

        @Override
        public Optional<NewBinding> onFail(DrlxParseFail failure) {
            return Optional.empty();
        }
    });
    return optNewBinding;
}
Also used : SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) REACT_ON_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.REACT_ON_CALL) ModelGeneratorVisitor(org.drools.modelcompiler.builder.generator.visitor.ModelGeneratorVisitor) ACCUMULATE_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.ACCUMULATE_CALL) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) DrlxParseUtil(org.drools.modelcompiler.builder.generator.DrlxParseUtil) PatternDescr(org.drools.drl.ast.descr.PatternDescr) InvalidExpressionErrorResult(org.drools.modelcompiler.builder.errors.InvalidExpressionErrorResult) ExpressionTyperContext(org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyperContext) LiteralExpr(com.github.javaparser.ast.expr.LiteralExpr) AccumulateUtil(org.drools.compiler.rule.builder.util.AccumulateUtil) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) Expression(com.github.javaparser.ast.expr.Expression) ConstraintParser(org.drools.modelcompiler.builder.generator.drlxparse.ConstraintParser) PatternExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.PatternExpressionBuilder) BinaryExpr(com.github.javaparser.ast.expr.BinaryExpr) Node(com.github.javaparser.ast.Node) PackageModel(org.drools.modelcompiler.builder.PackageModel) NodeList(com.github.javaparser.ast.NodeList) AND_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.AND_CALL) Collection(java.util.Collection) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) Set(java.util.Set) LambdaUtil(org.drools.modelcompiler.util.LambdaUtil) BaseDescr(org.drools.drl.ast.descr.BaseDescr) VALUE_OF_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.VALUE_OF_CALL) Objects(java.util.Objects) List(java.util.List) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) Optional(java.util.Optional) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail) DrlxParseUtil.validateDuplicateBindings(org.drools.modelcompiler.builder.generator.DrlxParseUtil.validateDuplicateBindings) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) AbstractExpressionBuilder(org.drools.modelcompiler.builder.generator.expression.AbstractExpressionBuilder) LambdaExpr(com.github.javaparser.ast.expr.LambdaExpr) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) PrintUtil.printNode(org.drools.mvel.parser.printer.PrintUtil.printNode) Parameter(com.github.javaparser.ast.body.Parameter) Pattern(org.drools.core.rule.Pattern) ArrayList(java.util.ArrayList) ACC_FUNCTION_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.ACC_FUNCTION_CALL) HashSet(java.util.HashSet) CollectListAccumulateFunction(org.drools.core.base.accumulators.CollectListAccumulateFunction) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) DrlxParseUtil.getLiteralExpressionType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.getLiteralExpressionType) DslMethodNames.createDslTopLevelMethod(org.drools.modelcompiler.builder.generator.DslMethodNames.createDslTopLevelMethod) AndDescr(org.drools.drl.ast.descr.AndDescr) ReplaceTypeInLambda.replaceTypeInExprLambda(org.drools.modelcompiler.util.lambdareplace.ReplaceTypeInLambda.replaceTypeInExprLambda) BIND_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.BIND_CALL) Optional.ofNullable(java.util.Optional.ofNullable) BIND_AS_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.BIND_AS_CALL) DrlNameExpr(org.drools.mvel.parser.ast.expr.DrlNameExpr) NameExpr(com.github.javaparser.ast.expr.NameExpr) MethodReferenceExpr(com.github.javaparser.ast.expr.MethodReferenceExpr) ExpressionTyper(org.drools.modelcompiler.builder.generator.expressiontyper.ExpressionTyper) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) Collectors.toList(java.util.stream.Collectors.toList) CollectAccumulator(org.drools.core.base.accumulators.CollectAccumulator) CollectSetAccumulateFunction(org.drools.core.base.accumulators.CollectSetAccumulateFunction) ParseResultVisitor(org.drools.modelcompiler.builder.generator.drlxparse.ParseResultVisitor) Collections(java.util.Collections) Optional(java.util.Optional) DrlxParseFail(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseFail) DeclarationSpec(org.drools.modelcompiler.builder.generator.DeclarationSpec) SingleDrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.SingleDrlxParseSuccess) DrlxParseSuccess(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseSuccess) DrlxParseResult(org.drools.modelcompiler.builder.generator.drlxparse.DrlxParseResult) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) CollectListAccumulateFunction(org.drools.core.base.accumulators.CollectListAccumulateFunction) CollectSetAccumulateFunction(org.drools.core.base.accumulators.CollectSetAccumulateFunction) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)429 Test (org.junit.Test)166 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)149 NameExpr (com.github.javaparser.ast.expr.NameExpr)135 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)94 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)90 DrlxExpression (org.drools.mvel.parser.ast.expr.DrlxExpression)84 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)73 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)71 NodeList (com.github.javaparser.ast.NodeList)66 DrlxParser.parseExpression (org.drools.mvel.parser.DrlxParser.parseExpression)61 TypedExpression (org.drools.modelcompiler.builder.generator.TypedExpression)53 CompilationUnit (com.github.javaparser.ast.CompilationUnit)51 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)50 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)49 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)49 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)46 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)44 List (java.util.List)44 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)43