What does the accept
method of ASTNode do (The javadoc didn't help too much...) and when will the visit(Expression node)
method be called?
Here is an example code of how I need to use it:
final List<Expression> listi = new ArrayList<Expression>();
String stringi = opi.generate(entryContract, true_false_maybe);
// stringi representes an expression, for example "g!=h".
parser.setSource(stringi.toCharArray());
unit = (CompilationUnit) parser.createAST(null);
ASTNode astRoot = unit.getRoot();
astRoot.accept(new ASTVisitor() {
public boolean visit(Expression node) {
listi.add(node);
return true;
}
});
Thank you
I guess your Expression
class is a subtype of the ASTNode
class, and the ASTVisitor
class present other visit methods (which surely will be empty), accepting as an argument other ASTNode
subclasses.
It's an implementation of the GoF Visitor Design Pattern (also described at Wikipedia).
The accept
method on ASTNode
will just invoke the visit
method on the visitor implementation, passing itself as parameter for the visit
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With