use of java.nio.file.FileVisitResult.CONTINUE in project javaparser by javaparser.
the class SourceRoot method parse.
/**
* Tries to parse all .java files in a package recursively and passes them one by one to the callback. In comparison
* to the other parse methods, this is much more memory efficient, but saveAll() won't work.
*
* @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
*/
public SourceRoot parse(String startPackage, ParserConfiguration configuration, Callback callback) throws IOException {
assertNotNull(startPackage);
assertNotNull(configuration);
assertNotNull(callback);
logPackage(startPackage);
final JavaParser javaParser = new JavaParser(configuration);
final Path path = packageAbsolutePath(root, startPackage);
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path absolutePath, BasicFileAttributes attrs) throws IOException {
if (!attrs.isDirectory() && absolutePath.toString().endsWith(".java")) {
Path localPath = root.relativize(absolutePath);
Log.trace("Parsing %s", localPath);
final ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT, provider(absolutePath));
result.getResult().ifPresent(cu -> cu.setStorage(absolutePath));
if (callback.process(localPath, absolutePath, result) == SAVE) {
if (result.getResult().isPresent()) {
save(result.getResult().get(), path);
}
}
}
return CONTINUE;
}
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
return isSensibleDirectoryToEnter(dir) ? CONTINUE : SKIP_SUBTREE;
}
});
return this;
}
Aggregations