Search in sources :

Example 1 with UnalteredTypedExpression

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

the class RHSPhase method visit.

@Override
public TypedExpression visit(ArrayAccessExpr n, Context arg) {
    TypedExpression name = n.getName().accept(this, arg);
    Optional<Type> type = name.getType();
    if (type.filter(TypeUtils::isCollection).isPresent()) {
        return new ListAccessExprT(name, n.getIndex(), type.get());
    }
    return new UnalteredTypedExpression(n, type.orElse(null));
}
Also used : NullType(org.drools.core.util.MethodUtils.NullType) Type(java.lang.reflect.Type) TypeUtils.classFromType(org.drools.mvelcompiler.util.TypeUtils.classFromType) ListAccessExprT(org.drools.mvelcompiler.ast.ListAccessExprT) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression)

Example 2 with UnalteredTypedExpression

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

the class LHSPhase method visit.

@Override
public TypedExpression visit(ArrayAccessExpr n, Void arg) {
    if (parentIsExpressionStmt(n)) {
        return rhsOrError();
    }
    TypedExpression name = n.getName().accept(this, arg);
    Optional<Type> type = name.getType();
    if (type.filter(TypeUtils::isCollection).isPresent()) {
        Expression index = n.getIndex();
        if (index.isStringLiteralExpr() || index.isNameExpr()) {
            return new MapPutExprT(name, index, rhsOrNull(), name.getType());
        } else {
            return new ListAccessExprT(name, index, type.get());
        }
    }
    return new UnalteredTypedExpression(n, type.orElse(null));
}
Also used : MapPutExprT(org.drools.mvelcompiler.ast.MapPutExprT) Type(java.lang.reflect.Type) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) Expression(com.github.javaparser.ast.expr.Expression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression) ListAccessExprT(org.drools.mvelcompiler.ast.ListAccessExprT) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) UnalteredTypedExpression(org.drools.mvelcompiler.ast.UnalteredTypedExpression) TypedExpression(org.drools.mvelcompiler.ast.TypedExpression)

Example 3 with UnalteredTypedExpression

use of org.drools.mvelcompiler.ast.UnalteredTypedExpression 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)

Aggregations

TypedExpression (org.drools.mvelcompiler.ast.TypedExpression)3 UnalteredTypedExpression (org.drools.mvelcompiler.ast.UnalteredTypedExpression)3 Type (java.lang.reflect.Type)2 ListAccessExprT (org.drools.mvelcompiler.ast.ListAccessExprT)2 Expression (com.github.javaparser.ast.expr.Expression)1 Optional (java.util.Optional)1 NullType (org.drools.core.util.MethodUtils.NullType)1 MapPutExprT (org.drools.mvelcompiler.ast.MapPutExprT)1 TypeUtils.classFromType (org.drools.mvelcompiler.util.TypeUtils.classFromType)1