Search in sources :

Example 16 with TypedExpression

use of org.drools.mvelcompiler.ast.TypedExpression in project drools by kiegroup.

the class LHSPhase method visit.

@Override
public TypedExpression visit(FieldAccessExpr n, Void arg) {
    logPhase("FieldAccessExpr {}", n);
    if (parentIsExpressionStmt(n)) {
        return rhsOrError();
    }
    TypedExpression fieldAccessScope = n.getScope().accept(this, arg);
    n.getName().accept(this, arg);
    if (parentIsArrayAccessExpr(n)) {
        return tryParseItAsMap(n, fieldAccessScope).map(Optional::of).orElseGet(() -> tryParseItAsSetter(n, fieldAccessScope, getRHSType())).orElse(new UnalteredTypedExpression(n));
    } else {
        return tryParseAsArithmeticExpression(n, fieldAccessScope).map(Optional::of).orElseGet(() -> tryParseItAsSetter(n, fieldAccessScope, getRHSType())).orElse(new UnalteredTypedExpression(n));
    }
}
Also used : Optional(java.util.Optional) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression)

Example 17 with TypedExpression

use of org.drools.mvelcompiler.ast.TypedExpression in project drools by kiegroup.

the class RHSPhase method visit.

@Override
public TypedExpression visit(BinaryExpr n, Context arg) {
    TypedExpression left = n.getLeft().accept(this, arg);
    TypedExpression right = n.getRight().accept(this, arg);
    return withPossiblyBigDecimalConversion(left, right, n.getOperator());
}
Also used : UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression)

Example 18 with TypedExpression

use of org.drools.mvelcompiler.ast.TypedExpression in project drools by kiegroup.

the class RHSPhase method asFieldAccessTExpr.

private Optional<TypedExpression> asFieldAccessTExpr(SimpleName n, Context arg) {
    Optional<TypedExpression> lastTypedExpression = arg.scope;
    Optional<Type> scopeType = arg.getScopeType();
    Optional<Field> fieldType = scopeType.flatMap(te -> {
        Class parentClass = TypeUtils.classFromType(te);
        Field field = ClassUtils.getField(parentClass, n.asString());
        return ofNullable(field);
    });
    return map2(lastTypedExpression, fieldType, FieldAccessTExpr::new);
}
Also used : Field(java.lang.reflect.Field) NullType(org.drools.core.util.MethodUtils.NullType) Type(java.lang.reflect.Type) TypeUtils.classFromType(org.drools.mvelcompiler.util.TypeUtils.classFromType) FieldAccessTExpr(org.drools.mvelcompiler.ast.FieldAccessTExpr) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression)

Example 19 with TypedExpression

use of org.drools.mvelcompiler.ast.TypedExpression in project drools by kiegroup.

the class StatementVisitor method visit.

@Override
public TypedExpression visit(ForStmt n, Void arg) {
    List<TypedExpression> typedInitialization = n.getInitialization().stream().map(this::compileMVEL).collect(Collectors.toList());
    Optional<TypedExpression> typedCompare = n.getCompare().map(c -> new RHSPhase(mvelCompilerContext).invoke(c));
    List<TypedExpression> typedUpdate = n.getUpdate().stream().map(this::compileMVEL).collect(Collectors.toList());
    TypedExpression body = n.getBody().accept(this, arg);
    return new ForStmtT(typedInitialization, typedCompare, typedUpdate, body);
}
Also used : ForStmtT(org.drools.mvelcompiler.ast.ForStmtT) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression)

Example 20 with TypedExpression

use of org.drools.mvelcompiler.ast.TypedExpression in project drools by kiegroup.

the class StatementVisitor method visit.

@Override
public TypedExpression visit(IfStmt n, Void arg) {
    TypedExpression typedCondition = new RHSPhase(mvelCompilerContext).invoke(n.getCondition());
    TypedExpression typedThen = n.getThenStmt().accept(this, arg);
    Optional<TypedExpression> typedElse = n.getElseStmt().map(e -> e.accept(this, arg));
    return new IfStmtT(typedCondition, typedThen, typedElse);
}
Also used : IfStmtT(org.drools.mvelcompiler.ast.IfStmtT) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression)

Aggregations

TypedExpression (org.drools.mvelcompiler.ast.TypedExpression)21 UnalteredTypedExpression (org.drools.mvelcompiler.ast.UnalteredTypedExpression)18 Expression (com.github.javaparser.ast.expr.Expression)8 Node (com.github.javaparser.ast.Node)4 Type (java.lang.reflect.Type)4 Optional (java.util.Optional)4 FieldToAccessorTExpr (org.drools.mvelcompiler.ast.FieldToAccessorTExpr)4 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)3 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)3 Method (java.lang.reflect.Method)3 List (java.util.List)3 Optional.ofNullable (java.util.Optional.ofNullable)3 DrlGenericVisitor (org.drools.mvel.parser.ast.visitor.DrlGenericVisitor)3 DoStmtT (org.drools.mvelcompiler.ast.DoStmtT)3 ForEachStmtT (org.drools.mvelcompiler.ast.ForEachStmtT)3 MapPutExprT (org.drools.mvelcompiler.ast.MapPutExprT)3 WhileStmtT (org.drools.mvelcompiler.ast.WhileStmtT)3 BinaryExpr (com.github.javaparser.ast.expr.BinaryExpr)2 DoStmt (com.github.javaparser.ast.stmt.DoStmt)2 ForEachStmt (com.github.javaparser.ast.stmt.ForEachStmt)2