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));
}
use of com.github.javaparser.ParserConfiguration in project javaparser by javaparser.
the class JavaParserAPIIntegrationTest method annotationMemberDeclarationResolve.
@Test
public void annotationMemberDeclarationResolve() throws IOException {
File f = adaptPath(new File("src/test/resources/Annotations.java.txt"));
ParserConfiguration parserConfiguration = new ParserConfiguration();
parserConfiguration.setSymbolResolver(new JavaSymbolSolver(typeSolver));
CompilationUnit cu = new JavaParser(parserConfiguration).parse(ParseStart.COMPILATION_UNIT, new StreamProvider(new FileInputStream(f))).getResult().get();
AnnotationDeclaration declaration = (AnnotationDeclaration) cu.getType(2);
assertEquals("MyAnnotationWithFields", declaration.getNameAsString());
AnnotationMemberDeclaration memberDeclaration = (AnnotationMemberDeclaration) declaration.getMember(0);
ResolvedAnnotationMemberDeclaration resolvedDeclaration = memberDeclaration.resolve();
}
use of com.github.javaparser.ParserConfiguration in project drools by kiegroup.
the class DrlxCompiler method toPackageDescr.
public PackageDescr toPackageDescr(Resource resource) throws IOException {
ParseStart<CompilationUnit> context = ParseStart.DRLX_COMPILATION_UNIT;
MvelParser mvelParser = new MvelParser(new ParserConfiguration(), false);
ParseResult<CompilationUnit> result = mvelParser.parse(context, provider(resource.getReader()));
if (result.isSuccessful()) {
DrlxVisitor drlxCompiler = new DrlxVisitor();
drlxCompiler.visit(result.getResult().get(), null);
PackageDescr pkg = drlxCompiler.getPackageDescr();
if (pkg == null) {
this.results.add(new ParserError(resource, "Parser returned a null Package", 0, 0));
return null;
} else {
pkg.setResource(resource);
return pkg;
}
} else {
for (Problem problem : result.getProblems()) {
TokenRange tokenRange = problem.getLocation().get();
Range range = tokenRange.getBegin().getRange().get();
int lineCount = range.getLineCount();
this.results.add(new ParserError(problem.getMessage(), lineCount, -1));
}
return null;
}
}
Aggregations