use of com.github.javaparser.ParserConfiguration 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;
}
use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class CommentParsingSteps method whenTheClassIsParsedByTheCommentParser.
@When("the class is parsed by the comment parser")
public void whenTheClassIsParsedByTheCommentParser() throws IOException {
ParseResult<CompilationUnit> parseResult = new JavaParser(new ParserConfiguration()).parse(COMPILATION_UNIT, provider(sourceUnderTest));
commentsCollection = parseResult.getCommentsCollection().orElse(new CommentsCollection());
}
use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class TryStmtTest method parse9.
private <T> T parse9(String code) {
JavaParser parser = new JavaParser(new ParserConfiguration().setLanguageLevel(JAVA_9));
ParseResult<Statement> result = parser.parse(ParseStart.STATEMENT, provider(code));
assertTrue(result.toString(), result.isSuccessful());
return (T) result.getResult().get();
}
use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class BulkParseTest method parseJdkSrcZip.
private void parseJdkSrcZip() throws IOException {
// This is where Ubuntu stores the contents of package openjdk-8-src
Path path = Paths.get("/usr/lib/jvm/openjdk-9/src.zip");
bulkTest(new SourceZip(path), "openjdk_src_zip_test_results.txt", new ParserConfiguration().setLanguageLevel(JAVA_9));
}
use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class BulkParseTest method parseOpenJdkLangToolsRepository.
private void parseOpenJdkLangToolsRepository() throws IOException {
Path workdir = CodeGenerationUtils.mavenModuleRoot(BulkParseTest.class).resolve(Paths.get(temporaryDirectory(), "javaparser_bulkparsetest"));
workdir.toFile().mkdirs();
Path openJdkZipPath = workdir.resolve("langtools.zip");
if (Files.notExists(openJdkZipPath)) {
Log.info("Downloading JDK langtools");
/* Found by choosing a tag here: http://hg.openjdk.java.net/jdk9/jdk9/langtools/tags
then copying the "zip" link to the line below: */
download(new URL("http://hg.openjdk.java.net/jdk10/jdk10/langtools/archive/19293ea3999f.zip"), openJdkZipPath);
}
bulkTest(new SourceZip(openJdkZipPath), "openjdk_src_repo_test_results.txt", new ParserConfiguration().setLanguageLevel(JAVA_10));
}
Aggregations