use of org.apache.sling.scripting.sightly.impl.compiler.CompilationResultImpl in project sling by apache.
the class SightlyCompiler method compile.
/**
* Compiles a {@link CompilationUnit}, passing the processed {@link CommandStream} to the provided {@link BackendCompiler}.
*
* @param compilationUnit a compilation unit
* @param backendCompiler the backend compiler
* @return the compilation result
*/
public CompilationResult compile(CompilationUnit compilationUnit, BackendCompiler backendCompiler) {
String scriptName = compilationUnit.getScriptName();
String scriptSource = null;
PushStream stream = new PushStream();
SanityChecker.attachChecker(stream);
CommandStream optimizedStream = optimizer.transform(stream);
CompilationResultImpl compilationResult = new CompilationResultImpl(optimizedStream);
try {
scriptSource = IOUtils.toString(compilationUnit.getScriptReader());
//optimizedStream.addHandler(LoggingHandler.INSTANCE);
if (backendCompiler != null) {
backendCompiler.handle(optimizedStream);
}
frontend.compile(stream, scriptSource);
for (PushStream.StreamMessage w : stream.getWarnings()) {
ScriptError warning = getScriptError(scriptSource, w.getCode(), 1, 0, w.getMessage());
compilationResult.getWarnings().add(new CompilerMessageImpl(scriptName, warning.errorMessage, warning.lineNumber, warning.column));
}
} catch (SightlyCompilerException e) {
ScriptError scriptError = getScriptError(scriptSource, e.getOffendingInput(), e.getLine(), e.getColumn(), e.getMessage());
compilationResult.getErrors().add(new CompilerMessageImpl(scriptName, scriptError.errorMessage, scriptError.lineNumber, scriptError.column));
} catch (IOException e) {
throw new SightlyCompilerException("Unable to read source code from CompilationUnit identifying script " + scriptName, e);
}
compilationResult.seal();
return compilationResult;
}
Aggregations