use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class FlattenScopeTest method expr.
private Expression expr(String inputExpr) {
Expression expr = DrlxParseUtil.parseExpression(inputExpr).getExpr();
// This is because parsing doesn't set type arguments.
expr.ifMethodCallExpr(m -> m.setTypeArguments(nodeList()));
expr.getChildNodes().forEach((Node e) -> {
if (e instanceof Expression) {
((Expression) e).ifMethodCallExpr(m -> m.setTypeArguments(nodeList()));
}
});
return expr;
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class DrlxCompilerTest method testWhitespace.
@Test
public void testWhitespace() {
ParseStart<Expression> context = ParseStart.EXPRESSION;
MvelParser mvelParser = new MvelParser(new ParserConfiguration(), false);
ParseResult<Expression> result = mvelParser.parse(context, provider("1\n+1"));
assertEquals("1 + 1", result.getResult().get().toString());
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class RHSPhase method visit.
@Override
public TypedExpression visit(ObjectCreationExpr n, Context arg) {
List<TypedExpression> constructorArguments = new ArrayList<>();
for (Expression e : n.getArguments()) {
TypedExpression compiledArgument = e.accept(this, arg);
constructorArguments.add(compiledArgument);
}
return new ObjectCreationExpressionT(constructorArguments, resolveType(n.getType()));
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class StatementVisitor method visit.
@Override
public TypedExpression visit(ForEachStmt n, Void arg) {
Expression iterable = n.getIterable();
Optional<TypedExpression> convertedToDowncastStmt = iterable.toNameExpr().map(PrintUtil::printNode).flatMap(mvelCompilerContext::findDeclarations).filter(this::isDeclarationIterable).map(d -> toForEachDowncastStmtT(n, arg));
if (convertedToDowncastStmt.isPresent()) {
return convertedToDowncastStmt.get();
}
TypedExpression variableDeclarationExpr = new LHSPhase(mvelCompilerContext, Optional.empty()).invoke(n.getVariable());
TypedExpression typedIterable = new RHSPhase(mvelCompilerContext).invoke(n.getIterable());
TypedExpression body = n.getBody().accept(this, arg);
return new ForEachStmtT(variableDeclarationExpr, typedIterable, body);
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class PreprocessPhase method addTypeToInitialization.
private Optional<Expression> addTypeToInitialization(WithStatement withStatement, Deque<Statement> allNewStatements) {
if (withStatement.getWithObject().isAssignExpr()) {
AssignExpr assignExpr = withStatement.getWithObject().asAssignExpr();
Expression assignExprValue = assignExpr.getValue();
Expression assignExprTarget = assignExpr.getTarget();
if (assignExprValue.isObjectCreationExpr() && assignExprTarget instanceof DrlNameExpr) {
ObjectCreationExpr constructor = assignExprValue.asObjectCreationExpr();
ClassOrInterfaceType ctorType = constructor.getType();
String targetVariableName = ((DrlNameExpr) assignExprTarget).getNameAsString();
VariableDeclarationExpr variableDeclarationExpr = new VariableDeclarationExpr(ctorType, targetVariableName);
AssignExpr withTypeAssignmentExpr = new AssignExpr(variableDeclarationExpr, assignExprValue, assignExpr.getOperator());
allNewStatements.add(new ExpressionStmt(withTypeAssignmentExpr));
return of(new DrlNameExpr(targetVariableName));
}
}
return empty();
}
Aggregations