Search in sources :

Example 1 with CSharpPrinter

use of sharpen.core.csharp.CSharpPrinter 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)

Example 2 with CSharpPrinter

use of sharpen.core.csharp.CSharpPrinter in project XobotOS by xamarin.

the class SharpenConversion method printTree.

private void printTree(CSCompilationUnit unit) {
    CSharpPrinter printer = getPrinter();
    printer.setWriter(_writer);
    printer.print(unit);
}
Also used : CSharpPrinter(sharpen.core.csharp.CSharpPrinter)

Example 3 with CSharpPrinter

use of sharpen.core.csharp.CSharpPrinter in project XobotOS by xamarin.

the class NativeBuilder method printManagedType.

public boolean printManagedType(CSCompilationUnit unit) {
    final URI projectRoot = my(APIDefinition.class).getProjectRoot();
    final String outputDir = my(ConfigFile.class).getSourceInfo().getOutputFolder();
    final String outputPath = projectRoot.getPath() + File.separatorChar + outputDir + File.separatorChar + _config.getOutputDir();
    if (!new File(outputPath).exists())
        new File(outputPath).mkdirs();
    final String fullSourceName = outputPath + File.separatorChar + _name + ".cs";
    FileWriter output;
    try {
        output = new FileWriter(fullSourceName);
    } catch (IOException e) {
        Sharpen.Log(e, "Cannot create managed glue file '%s'", fullSourceName);
        return false;
    }
    CSharpPrinter printer = new CSharpPrinter();
    printer.setWriter(output);
    printer.print(unit);
    try {
        output.close();
    } catch (IOException e) {
        Sharpen.Log(e, "Cannot create managed glue file '%s'", fullSourceName);
        return false;
    }
    return true;
}
Also used : CSharpPrinter(sharpen.core.csharp.CSharpPrinter) APIDefinition(sharpen.xobotos.api.APIDefinition) FileWriter(java.io.FileWriter) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File) ConfigFile(sharpen.xobotos.config.ConfigFile)

Aggregations

CSharpPrinter (sharpen.core.csharp.CSharpPrinter)3 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 URI (java.net.URI)1 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 CSCompilationUnit (sharpen.core.csharp.ast.CSCompilationUnit)1 APIDefinition (sharpen.xobotos.api.APIDefinition)1 ConfigFile (sharpen.xobotos.config.ConfigFile)1 CompilationUnitBuilder (sharpen.xobotos.generator.CompilationUnitBuilder)1