I'm using Java JDT to run through source code and am using the visitor pattern to detect different items such as variables, methods etc.
However I'm not sure how a loop is defined for example:
for(int i = 0; i i < a.size();i++){
or
while(i<10)
The method I need looks like
public boolean visit(XXXXXXX node) {
System.out.println(node);
return false;
}
where XXXXXXX is something in Java JDT.
If you are referring to the AST visitor, then:
for(int i = 0; i i < a.size();i++) {
}
A for loop with a variable is represented by the type ForStatement
.
for (String s : array) {
}
A for loop over an array is represented by the type EnhancedForStatement
.
while(i<10) {
}
A while loop if represented by the type WhileStatement
.
A great tool to analize your code is the ASTView. It can show you the AST of any code marked in your editor. You can install it into Eclipse from the update site http://www.eclipse.org/jdt/ui/update-site