Open manucapo opened 2 years ago
Currently the JavaParser class only prints to console.
We need to improve the class to also add the parsed information to the data structure.
method.walk(Node.TreeTraversal.PREORDER, this::CheckIfMethodCallNode);
The walk method is a functional method that uses a consumer CheckIfMethodCallNode() to operate on each node it iterates through.
Since the consumer method is supposed to have no side effects it would be bad form to try to update the diagram structure using the consumer.
One promising option is to use the .FindAll method:
method.findAll(MethodCallExpr.class,Node.TreeTraversal.PREORDER ))
This method returns a List of nodes that we can then iterate through.
Another option is to use the visitor API provided by the javaparser library.
static class MethodVisitor extends VoidVisitorAdapter<Void> { // Visitor class that checks MethodCall nodes. @Override public void visit(MethodCallExpr n, Void arg) { System.out.println(n.getName()); super.visit(n, arg); } }
I think the Visitor method is the right way to go about it if one wants to modify the AST.
Since we are NOT interested in modifying the AST i suspect the .findall() method should be easier to work with here.
Currently the JavaParser class only prints to console.
We need to improve the class to also add the parsed information to the data structure.
The walk method is a functional method that uses a consumer CheckIfMethodCallNode() to operate on each node it iterates through.
Since the consumer method is supposed to have no side effects it would be bad form to try to update the diagram structure using the consumer.
One promising option is to use the .FindAll method:
This method returns a List of nodes that we can then iterate through.
Another option is to use the visitor API provided by the javaparser library.
I think the Visitor method is the right way to go about it if one wants to modify the AST.
Since we are NOT interested in modifying the AST i suspect the .findall() method should be easier to work with here.