I am trying to parse a Java file and count the method declarations in it. Right now I am using the following code:
import ParseTree;
import lang::java::\syntax::Java15;
import IO;
public int countMethods(loc file) {
int n = 0;
try {
comp = parse(#CompilationUnit, file);
for (/MethodDec md <- comp) {
n = n + 1;
}
} catch ParseError(loc l): {
println("Error at line <l.begin.line>, col <l.begin.column>.");
}
return n;
}
I am stuck with the error message that the CompilationUnit type is not enumerable. Now i wonder how I can get/iterate through all the methods?