use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class QueryDefImplGenerator method callMethod.
private void callMethod(ClassOrInterfaceDeclaration clazz) {
MethodDeclaration method = clazz.addMethod("call", Modifier.Keyword.PUBLIC);
addOverride(method);
method.addParameter("boolean", "open");
method.setType(toClassOrInterfaceType(QueryCallViewItem.class));
BlockStmt statements = new BlockStmt();
NodeList<Expression> arguments = nodeList();
ClassOrInterfaceType queryCallViewItemImpl = toClassOrInterfaceType(QueryCallViewItemImpl.class);
ObjectCreationExpr objCreationExpr = new ObjectCreationExpr(null, queryCallViewItemImpl, arguments);
statements.addStatement(new ReturnStmt(objCreationExpr));
objCreationExpr.addArgument("this");
objCreationExpr.addArgument("open");
rangeArity().forEach(i -> {
String varWithIndex = stringWithIndex("var", i);
String genericTypeName = genericTypeName(i);
method.addParameter(genericType("Argument", genericTypeName), varWithIndex);
objCreationExpr.addArgument(varWithIndex);
});
method.setBody(statements);
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class QueryDefGenerator method callMethod.
private void callMethod(ClassOrInterfaceDeclaration clazz) {
MethodDeclaration method = clazz.addMethod("call", Modifier.Keyword.DEFAULT);
method.setType(toClassOrInterfaceType(QueryCallViewItem.class));
BlockStmt stmts = new BlockStmt();
NodeList<Expression> arguments = nodeList();
MethodCallExpr objCreationExpr = new MethodCallExpr(null, "call", arguments);
stmts.addStatement(new ReturnStmt(objCreationExpr));
objCreationExpr.addArgument(new BooleanLiteralExpr(true));
rangeArity().forEach(i -> {
String varWithIndex = stringWithIndex("var", i);
String genericTypeName = stringWithIndex("T", i);
method.addParameter(genericType("Argument", genericTypeName), varWithIndex);
objCreationExpr.addArgument(varWithIndex);
});
method.setBody(stmts);
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class FromVisitor method createSingleFrom.
private Optional<Expression> createSingleFrom(String expression) {
final Expression parsedExpression = DrlxParseUtil.parseExpression(expression).getExpr();
if (parsedExpression instanceof FieldAccessExpr || parsedExpression instanceof NameExpr || parsedExpression instanceof DrlNameExpr) {
return fromFieldOrName(expression);
}
if (parsedExpression instanceof ObjectCreationExpr) {
return fromConstructorExpr(expression, (ObjectCreationExpr) parsedExpression);
}
if (parsedExpression instanceof LiteralExpr) {
MethodCallExpr fromCall = createDslTopLevelMethod(FROM_CALL);
fromCall.addArgument(parsedExpression);
return of(fromCall);
}
return fromExpression(expression, parsedExpression);
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class EvaluatorGenerator method lastStatementIsGetter.
private void lastStatementIsGetter(BlockStmt mvelBlock, Expression expression) {
MethodCallExpr methodCallExprClone = expression.asMethodCallExpr().clone();
String getterName = methodCallExprClone.getName().asString().replace("set", "get");
MethodCallExpr getter = new MethodCallExpr(getterName);
methodCallExprClone.getScope().ifPresent(getter::setScope);
final Expression assignExpr = new AssignExpr(new NameExpr(RESULT_VALUE_REFERENCE_NAME), getter, AssignExpr.Operator.ASSIGN);
mvelBlock.addStatement(assignExpr);
}
use of com.github.javaparser.ast.expr.Expression in project drools by kiegroup.
the class EvaluatorGenerator method defineLastStatement.
// Simulate "Last expression is a return statement"
private void defineLastStatement(BlockStmt mvelBlock) {
if (!lastMVELStatement.isExpressionStmt()) {
return;
}
Expression expression = lastMVELStatement.asExpressionStmt().getExpression();
addResultReference();
if (expression.isMethodCallExpr() && expression.asMethodCallExpr().getNameAsString().startsWith("set")) {
lastStatementIsGetter(mvelBlock, expression);
} else {
final Expression assignExpr = new AssignExpr(new NameExpr(RESULT_VALUE_REFERENCE_NAME), expression, AssignExpr.Operator.ASSIGN);
mvelBlock.replace(lastMVELStatement, new ExpressionStmt(assignExpr));
}
returnResult();
}
Aggregations