Search in sources :

Example 1 with CSCompilationUnit

use of sharpen.core.csharp.ast.CSCompilationUnit in project XobotOS by xamarin.

the class XobotBuilder method stage4_save_output.

private boolean stage4_save_output(IProgressMonitor monitor, List<CompilationUnitBuilder> builders) {
    final int count = builders.size();
    final int totalWork = OUTPUT_PRICE * count;
    IProgressMonitor subMonitor = new SubProgressMonitor(monitor, totalWork);
    subMonitor.beginTask("Writing output", totalWork);
    Sharpen.Log(Level.INFO, "Writing output ...");
    int i = 0;
    boolean foundErrors = false;
    for (final CompilationUnitBuilder builder : builders) {
        final ICompilationUnit source = builder.getPair().source;
        final CSCompilationUnit unit = builder.getCompilationUnit();
        final String pathName = builder.getName();
        final String message = String.format("Saving (%d/%d): %s", ++i, count, pathName);
        subMonitor.subTask(message);
        try {
            if (!builder.writeOutput()) {
                Sharpen.Log(Level.SEVERE, "Failed to save output file: %s", pathName);
                foundErrors = true;
                continue;
            }
            if (unit.ignore() || unit.types().isEmpty())
                continue;
            final StringWriter writer = new StringWriter();
            writer.write(_config.header());
            CSharpPrinter printer = new CSharpPrinter();
            printer.setWriter(writer);
            printer.print(unit);
            if (writer.getBuffer().length() > 0)
                saveConvertedFile(source, unit, writer);
        } catch (CoreException e) {
            Sharpen.Log(e, "Cannot save output file: %s", pathName);
            foundErrors = true;
        } finally {
            subMonitor.worked(OUTPUT_PRICE);
        }
    }
    if (foundErrors) {
        Sharpen.Log(Level.SEVERE, "Errors while writing output!");
        _foundErrors = true;
    }
    subMonitor.done();
    return !foundErrors;
}
Also used : CSCompilationUnit(sharpen.core.csharp.ast.CSCompilationUnit) CSharpPrinter(sharpen.core.csharp.CSharpPrinter) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CompilationUnitBuilder(sharpen.xobotos.generator.CompilationUnitBuilder) CoreException(org.eclipse.core.runtime.CoreException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 CSharpPrinter (sharpen.core.csharp.CSharpPrinter)1 CSCompilationUnit (sharpen.core.csharp.ast.CSCompilationUnit)1 CompilationUnitBuilder (sharpen.xobotos.generator.CompilationUnitBuilder)1