Slide 13
Slide 13 text
Unless otherwise indicated, these slides are © 2013-2018 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Parsing Java
private void scanFiles(IJavaProject project, ASTParser parser, String[] javaFiles,
String[] classpathEntries) throws Exception {
Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(JavaCore.VERSION_10, options);
ASTParser parser = ASTParser.newParser(AST.JLS10);
parser.setCompilerOptions(options);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
parser.setResolveBindings(true);
parser.setIgnoreMethodBodies(false);
String[] sourceEntries = new String[0];
parser.setEnvironment(classpathEntries, sourceEntries, null, false);
FileASTRequestor requestor = new FileASTRequestor() {
@Override
public void acceptAST(String sourceFilePath, CompilationUnit cu) {
...
}
};
parser.createASTs(javaFiles, null, new String[0], requestor, null);
}
13