use of org.eclipse.jdt.internal.compiler.CompilationResult in project Japid by branaway.
the class RendererCompiler method compile.
/**
* Please compile this className and set the bytecode to the class holder
*/
@SuppressWarnings("deprecation")
public void compile(String[] classNames) {
ICompilationUnit[] compilationUnits = new CompilationUnit[classNames.length];
for (int i = 0; i < classNames.length; i++) {
compilationUnits[i] = new CompilationUnit(this, classNames[i]);
}
IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitOnFirstError();
IProblemFactory problemFactory = new DefaultProblemFactory(Locale.ENGLISH);
/**
* To find types ...
*/
INameEnvironment nameEnvironment = new NameEnv(this);
/**
* Compilation result
*/
ICompilerRequestor compilerRequestor = new CompilerRequestor(this);
/**
* The JDT compiler
*/
Compiler jdtCompiler = new Compiler(nameEnvironment, policy, settings, compilerRequestor, problemFactory) {
@Override
protected void handleInternalException(Throwable e, CompilationUnitDeclaration ud, CompilationResult result) {
}
};
// Go !
jdtCompiler.compile(compilationUnits);
}
use of org.eclipse.jdt.internal.compiler.CompilationResult 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, int minVersion, boolean checkPositions) 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);
char[] sourceArray = source.toCharArray();
final ICompilationUnit sourceUnit;
try {
sourceUnit = getSourceUnit(file, source);
} catch (Throwable t) {
t.printStackTrace();
return false;
}
Compiler ecjCompiler = new Compiler(createFileSystem(file, minVersion), 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);
}
};
// initializeEclipseBundles();
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 {
String output = cud.toString();
// starting somewhere around ecj16, the print code is a bit too cavalier with printing modifiers.
output = output.replace("non-sealed @val", "@val");
result.append(output);
}
if (eclipseAvailable()) {
EclipseDomConversion.toDomAst(cud, sourceArray);
}
return true;
}
Aggregations