use of org.eclipse.jdt.internal.compiler.batch.CompilationUnit in project lombok by rzwitserloot.
the class RunTestsViaEcj method transformCode.
@Override
public boolean transformCode(Collection<CompilerMessage> messages, StringWriter result, File file, String encoding, Map<String, String> formatPreferences) throws Throwable {
final AtomicReference<CompilationResult> compilationResult_ = new AtomicReference<CompilationResult>();
final AtomicReference<CompilationUnitDeclaration> compilationUnit_ = new AtomicReference<CompilationUnitDeclaration>();
ICompilerRequestor bitbucketRequestor = new ICompilerRequestor() {
@Override
public void acceptResult(CompilationResult result) {
compilationResult_.set(result);
}
};
String source = readFile(file);
final CompilationUnit sourceUnit = new CompilationUnit(source.toCharArray(), file.getName(), encoding == null ? "UTF-8" : encoding);
Compiler ecjCompiler = new Compiler(createFileSystem(file), ecjErrorHandlingPolicy(), ecjCompilerOptions(), bitbucketRequestor, new DefaultProblemFactory(Locale.ENGLISH)) {
@Override
protected synchronized void addCompilationUnit(ICompilationUnit inUnit, CompilationUnitDeclaration parsedUnit) {
if (inUnit == sourceUnit)
compilationUnit_.set(parsedUnit);
super.addCompilationUnit(inUnit, parsedUnit);
}
};
ecjCompiler.compile(new ICompilationUnit[] { sourceUnit });
CompilationResult compilationResult = compilationResult_.get();
CategorizedProblem[] problems = compilationResult.getAllProblems();
if (problems != null)
for (CategorizedProblem p : problems) {
messages.add(new CompilerMessage(p.getSourceLineNumber(), p.getSourceStart(), p.isError(), p.getMessage()));
}
CompilationUnitDeclaration cud = compilationUnit_.get();
if (cud == null)
result.append("---- NO CompilationUnit provided by ecj ----");
else
result.append(cud.toString());
return true;
}
Aggregations