I'm trying to use java compiler api. First I've got "mytest.java" which runs well. Then I have this code:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
String[] as = new String[]{"mytest.java"};
List<String> list = Arrays.asList(as);
Iterable fileObjects = fileManager.getJavaFileObjectsFromStrings(list);
for (Iterator it = fileObjects.iterator(); it.hasNext(); ) {
//RegularFileObject str = (RegularFileObject) it.next();
System.out.println("for loop");
}
(1) I expected that the for loop will be able to iterate all JavaFileObjects. In my case, it has only one file, right? But running the program, it prints a lot of "for loop" without stop. I expect it's printed only once
So what's wrong here?
(2) RegularFileObject is not a public class, so how can I visit the content of these file objects?
The iterator "it" is not updated/incremented in the for loop.