use of boa.datagen.util.JavaScriptErrorCheckVisitor in project compiler by boalang.
the class AbstractCommit method parseJavaScriptFile.
private boolean parseJavaScriptFile(final String path, final ChangedFile.Builder fb, final String content, final String compliance, final int astLevel, final boolean storeOnError, Writer astWriter, String key) {
try {
//System.out.println("parsing=" + (++count) + "\t" + path);
final org.eclipse.wst.jsdt.core.dom.ASTParser parser = org.eclipse.wst.jsdt.core.dom.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);
JavaScriptUnit cu;
try {
cu = (JavaScriptUnit) parser.createAST(null);
} catch (java.lang.IllegalArgumentException ex) {
return false;
}
final JavaScriptErrorCheckVisitor errorCheck = new JavaScriptErrorCheckVisitor();
cu.accept(errorCheck);
if (!errorCheck.hasError || storeOnError) {
final ASTRoot.Builder ast = ASTRoot.newBuilder();
// final CommentsRoot.Builder comments =
// CommentsRoot.newBuilder();
final JavaScriptVisitor visitor = new JavaScriptVisitor(content);
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 {
// System.out.println("writing=" + count + "\t" + path);
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