use of org.eclipse.xtext.xbase.testing.CompilationTestHelper.Result in project xtext-xtend by eclipse.
the class XtendCompilerTester method compile.
public void compile(CharSequence source, final IAcceptor<CompilationResult> acceptor) {
try {
compilationTestHelper.configureFreshWorkspace();
compilationTestHelper.compile(source, new IAcceptor<CompilationTestHelper.Result>() {
@Override
public void accept(final Result t) {
acceptor.accept(new CompilationResult() {
@Override
public Map<String, String> getGeneratedCode() {
return t.getGeneratedCode();
}
@Override
public String getGeneratedCode(String typeName) {
return t.getGeneratedCode(typeName);
}
@Override
public String getSingleGeneratedCode() {
return t.getSingleGeneratedCode();
}
@Override
public Class<?> getCompiledClass() {
return t.getCompiledClass();
}
@Override
public Class<?> getCompiledClass(String className) {
return t.getCompiledClass(className);
}
@Override
public List<? extends Problem> getProblems(Element element) {
return getTransformationContext().getProblems(element);
}
@Override
public List<? extends Problem> getAllProblems() {
Resource resource = compilationUnitImpl.getXtendFile().eResource();
Iterable<EObjectDiagnosticImpl> issues = Iterables.filter(Iterables.concat(resource.getErrors(), resource.getWarnings()), EObjectDiagnosticImpl.class);
List<Problem> result = Lists.newArrayList(Iterables.transform(issues, new Function<EObjectDiagnosticImpl, Problem>() {
@Override
public Problem apply(EObjectDiagnosticImpl diag) {
ProblemImpl result = new ProblemImpl(diag.getCode(), diag.getMessage(), translateSeverity(diag.getSeverity()));
return result;
}
private org.eclipse.xtend.lib.macro.services.Problem.Severity translateSeverity(Severity severity) {
switch(severity) {
case ERROR:
return Problem.Severity.ERROR;
case WARNING:
return Problem.Severity.WARNING;
case INFO:
return Problem.Severity.INFO;
case IGNORE:
return Problem.Severity.IGNORE;
default:
throw new IllegalArgumentException(String.valueOf(severity));
}
}
}));
return result;
}
@Override
public Map<String, CharSequence> getAllGeneratedResources() {
return t.getAllGeneratedResources();
}
CompilationUnitImpl compilationUnitImpl;
{
compilationUnitImpl = compilationUnitProvider.get();
XtendFile xtendFile = (XtendFile) t.getResourceSet().getResources().get(0).getContents().get(0);
compilationUnitImpl.setXtendFile(xtendFile);
}
@Override
public CompilationUnit getCompilationUnit() {
return compilationUnitImpl;
}
@Override
public TransformationContext getTransformationContext() {
TransformationContextImpl transformationContextImpl = new TransformationContextImpl();
transformationContextImpl.setUnit(compilationUnitImpl);
return transformationContextImpl;
}
});
}
});
} catch (IOException e) {
Exceptions.sneakyThrow(e);
}
}
Aggregations