use of boa.datagen.util.Java7Visitor in project compiler by boalang.
the class AbstractCommit method parseJavaFile.
private boolean parseJavaFile(final String path, final ChangedFile.Builder fb, final String content, final String compliance, final int astLevel, final boolean storeOnError, Writer astWriter, String key) {
try {
final ASTParser parser = ASTParser.newParser(astLevel);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setResolveBindings(true);
parser.setSource(content.toCharArray());
final Map options = JavaCore.getOptions();
JavaCore.setComplianceOptions(compliance, options);
parser.setCompilerOptions(options);
final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
final JavaErrorCheckVisitor errorCheck = new JavaErrorCheckVisitor();
cu.accept(errorCheck);
if (!errorCheck.hasError || storeOnError) {
final ASTRoot.Builder ast = ASTRoot.newBuilder();
//final CommentsRoot.Builder comments = CommentsRoot.newBuilder();
final Java7Visitor visitor;
if (astLevel == AST.JLS8)
visitor = new Java8Visitor(content, connector.nameIndices);
else
visitor = new Java7Visitor(content, connector.nameIndices);
try {
ast.addNamespaces(visitor.getNamespaces(cu));
for (final String s : visitor.getImports()) ast.addImports(s);
/*for (final Comment c : visitor.getComments())
comments.addComments(c);*/
} catch (final UnsupportedOperationException e) {
return false;
} catch (final Exception e) {
if (debug)
System.err.println("Error visiting: " + path);
e.printStackTrace();
return false;
}
if (astWriter != null) {
try {
astWriter.append(new Text(key), new BytesWritable(ast.build().toByteArray()));
} catch (IOException e) {
e.printStackTrace();
}
} else
fb.setAst(ast);
//fb.setComments(comments);
}
return !errorCheck.hasError;
} catch (final Exception e) {
e.printStackTrace();
return false;
}
}
Aggregations