4
有人可以給我澄清visit
方法的第二個參數arg
的用法,如JavaParser documentation example page的以下代碼所示?
我在互聯網上找不到任何信息。JavaParser訪問方法arg參數澄清
public class MethodPrinter {
public static void main(String[] args) throws Exception {
// creates an input stream for the file to be parsed
FileInputStream in = new FileInputStream("test.java");
CompilationUnit cu;
try {
// parse the file
cu = JavaParser.parse(in);
} finally {
in.close();
}
// visit and print the methods names
new MethodVisitor().visit(cu, null);
}
/**
* Simple visitor implementation for visiting MethodDeclaration nodes.
*/
private static class MethodVisitor extends VoidVisitorAdapter {
@Override
public void visit(MethodDeclaration n, Object arg) {
// here you can access the attributes of the method.
// this method will be called for all methods in this
// CompilationUnit, including inner class methods
System.out.println(n.getName());
}
}
}