abstract syntax tree - How can I find all for-loops in a Java file using javaparser? -
i using javaparser parse java file , find occurrences of for
loops (foreach
& normal for
loops). approach far, finds some, not occurrences.
public class astelementtraverser extends voidvisitoradapter<file> { @override public void visit(foreachstmt n, file sourcefile) { system.out.println("found foreach loop " + sourcefile.getabsolutepath() + " @ " + n.getbeginline()); } @override public void visit(forstmt n, file sourcefile) { system.out.println("found loop " + sourcefile.getabsolutepath() + " @ " + n.getbeginline()); } }
for instance, seems work line:
for (final javadoctaginfo tag : javadoctaginfo.values()) {
... not this:
for (propertydescriptor<?> descriptor : propertydescriptors) {
... nor one:
for (int = 1; < typecodes.length; i++) {
is possible bug in javaparser, or using wrong way?
Comments
Post a Comment