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