java - What does the accept() method of ASTNode do and how does it use the ASTVisitor? -
what accept
method of astnode (the javadoc didn't much...) , when visit(expression node)
method called? here example code of how need use it:
final list<expression> listi = new arraylist<expression>(); string stringi = opi.generate(entrycontract, true_false_maybe); // stringi representes expression, 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 expression
class subtype of astnode
class, , astvisitor
class present other visit methods (which surely empty), accepting argument other astnode
subclasses.
it's implementation of gof visitor design pattern (also described @ wikipedia).
the accept
method on astnode
invoke visit
method on visitor implementation, passing parameter visit
method.
Comments
Post a Comment