use of com.github.javaparser.ast.Node in project drools by kiegroup.
the class PreprocessPhase method withPreprocessor.
private PreprocessPhaseResult withPreprocessor(WithStatement withStatement) {
PreprocessPhaseResult result = new StatementResult();
Deque<Statement> allNewStatements = new ArrayDeque<>();
Optional<Expression> initScope = addTypeToInitialization(withStatement, allNewStatements);
final Expression scope = initScope.orElse(withStatement.getWithObject());
withStatement.findAll(AssignExpr.class).replaceAll(assignExpr -> assignToFieldAccess(result, scope, assignExpr));
// Do not use findAll as we should only process top level expressions
withStatement.getExpressions().replaceAll(e -> addScopeToMethodCallExpr(result, scope, e));
NodeList<Statement> bodyStatements = wrapToExpressionStmt(withStatement.getExpressions());
allNewStatements.addAll(bodyStatements);
// delete modify statement and add the new statements to its children
Node parentNode = withStatement.getParentNode().orElseThrow(() -> new MvelCompilerException("A parent node is expected here"));
// See RuleChainingTest.testRuleChainingWithLogicalInserts
if (parentNode instanceof BlockStmt) {
BlockStmt parentBlock = (BlockStmt) parentNode;
Iterator<Statement> newStatementsReversed = allNewStatements.descendingIterator();
while (newStatementsReversed.hasNext()) {
parentBlock.getStatements().addAfter(newStatementsReversed.next(), withStatement);
}
withStatement.remove();
} else {
throw new MvelCompilerException("Expecting a BlockStmt as a parent");
}
return result;
}
use of com.github.javaparser.ast.Node in project drools by kiegroup.
the class ObjectCreationExpressionT method toJavaExpression.
@Override
public Node toJavaExpression() {
ObjectCreationExpr objectCreationExpr = new ObjectCreationExpr();
objectCreationExpr.setType(type);
List<Expression> arguments = this.constructorArguments.stream().map(typedExpression -> (Expression) typedExpression.toJavaExpression()).collect(Collectors.toList());
objectCreationExpr.setArguments(NodeList.nodeList(arguments));
return objectCreationExpr;
}
use of com.github.javaparser.ast.Node in project drools by kiegroup.
the class VariableDeclaratorTExpr method toJavaExpression.
@Override
public Node toJavaExpression() {
Optional<Type> optInitType = initExpression.flatMap(TypedExpression::getType);
com.github.javaparser.ast.type.Type jpType = toJPType(this.type);
return initExpression.map(ie -> {
Expression initializer = (Expression) ie.toJavaExpression();
// Used to downcast map.get see testAddCastToMapGetOfDeclaration
if (!optInitType.isPresent() || optInitType.get().equals(Object.class)) {
initializer = new CastExpr(jpType, new EnclosedExpr(initializer));
}
return (Node) new VariableDeclarationExpr(new VariableDeclarator(jpType, name, initializer));
}).orElse(new VariableDeclarationExpr(jpType, name));
}
use of com.github.javaparser.ast.Node in project drools by kiegroup.
the class MethodCallExprT method toJavaExpression.
@Override
public Node toJavaExpression() {
Node scopeE = scope.map(TypedExpression::toJavaExpression).orElse(null);
List<Expression> methodArguments;
// MVEL forces a to string on each String value in map
if (PUT_CALL.equals(name) && arguments.size() == 2) {
methodArguments = coercedMapArguments();
} else {
methodArguments = toJavaExpressionArgument();
}
return new MethodCallExpr((Expression) scopeE, name, nodeList(methodArguments));
}
use of com.github.javaparser.ast.Node in project zaproxy by zaproxy.
the class JFlexToRstaTokenMaker method removeMethod.
private static void removeMethod(TypeDeclaration<?> type, String... names) {
if (names == null || names.length == 0) {
return;
}
for (String name : names) {
List<MethodDeclaration> methods = type.getMethodsByName(name);
MethodDeclaration method = methods.get(methods.size() - 1);
method.getJavadocComment().ifPresent(Node::remove);
method.remove();
}
}
Aggregations