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));
}
}
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());
}
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);
}
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);
}
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);
}
Aggregations