public CompilationResult compile()

in src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java [173:208]


    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;
    }