public static string CreateBooCode(CompilerErrorCollection errors, CompilerWarningCollection warnings, Module module, IList <ICSharpCode.NRefactory.ISpecial> specials) { using (StringWriter w = new StringWriter()) { foreach (CompilerError error in errors) { w.WriteLine("ERROR: " + error.ToString()); } if (errors.Count > 0) { w.WriteLine(); } foreach (CompilerWarning warning in warnings) { w.WriteLine("# WARNING: " + warning.ToString()); } if (warnings.Count > 0) { w.WriteLine(); } BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w); printer.OnModule(module); printer.Finish(); return(w.ToString()); } }
public ConvertVisitor(ConverterSettings settings) { this.settings = settings; this.fileName = settings.FileName; this.errors = settings.Errors; this.warnings = settings.Warnings; this.nameComparer = settings.NameComparer; }
public void TestSuppressWarning() { CompilerWarningCollection warnings = new CompilerWarningCollection(); warnings.Adding += delegate(object sender, CompilerWarningEventArgs args) { if (args.Warning.Code == "foo") { args.Cancel(); } }; warnings.Add(new CompilerWarning(LexicalInfo.Empty, "foo", "foo")); Assert.AreEqual(0, warnings.Count); warnings.Add(new CompilerWarning(LexicalInfo.Empty, "bar", "bar")); Assert.AreEqual(1, warnings.Count); }
public static bool ConvertToBoo(string fileName, string ProvidedSource, out string ConvertedSource, out string ErrorMessage) { ConvertedSource = ErrorMessage = ""; CompilerErrorCollection errors = new CompilerErrorCollection(); CompilerWarningCollection warnings = new CompilerWarningCollection(); Module module; IList <ICSharpCode.NRefactory.ISpecial> specials; CompileUnit compileUnit = new CompileUnit(); using (StringReader r = new StringReader(ProvidedSource)) { // modified: removed fileName guessing module = Parser.ParseModule(compileUnit, r, BooHelpers.ApplySettings(fileName, errors, warnings), out specials); } if (module == null) { StringBuilder errorBuilder = new StringBuilder(); foreach (CompilerError error in errors) { errorBuilder.AppendLine(error.ToString()); } if (warnings.Count > 0) { foreach (CompilerWarning warning in warnings) { errorBuilder.AppendLine(warning.ToString()); } } ErrorMessage = errorBuilder.ToString(); return(false); } else { ConvertedSource = BooHelpers.CreateBooCode(errors, warnings, module, specials); } return(true); }
public ConverterSettings(string fileName, StringComparer nameComparer, CompilerErrorCollection errors, CompilerWarningCollection warnings) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (nameComparer == null) { throw new ArgumentNullException("nameComparer"); } if (errors == null) { throw new ArgumentNullException("errors"); } if (warnings == null) { throw new ArgumentNullException("warnings"); } this.errors = errors; this.warnings = warnings; this.fileName = fileName; this.nameComparer = nameComparer; }
public override void Run() { IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; if (window != null && window.ActiveViewContent is IEditable) { CompilerErrorCollection errors = new CompilerErrorCollection(); CompilerWarningCollection warnings = new CompilerWarningCollection(); Module module; IList <ICSharpCode.NRefactory.ISpecial> specials; CompileUnit compileUnit = new CompileUnit(); using (StringReader r = new StringReader(((IEditable)window.ActiveViewContent).Text)) { string fileName = window.ActiveViewContent.PrimaryFileName; module = Parser.ParseModule(compileUnit, r, ApplySettings(fileName, errors, warnings), out specials); } if (module == null) { StringBuilder errorBuilder = new StringBuilder(); foreach (CompilerError error in errors) { errorBuilder.AppendLine(error.ToString()); } if (warnings.Count > 0) { foreach (CompilerWarning warning in warnings) { errorBuilder.AppendLine(warning.ToString()); } } MessageService.ShowError(errorBuilder.ToString()); } else { FileService.NewFile("Generated.boo", CreateBooCode(errors, warnings, module, specials)); } } }
/// <summary> /// Allow a derived class to get access to the warnings that occured during /// compilation /// </summary> /// <param name="warnings">The warnings.</param> protected virtual void HandleWarnings(CompilerWarningCollection warnings) { }
public ConverterSettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) : this(fileName, GetComparer(fileName), errors, warnings) { }
bool ConvertFileInternal(string input, string output) { string directory = Path.GetDirectoryName(output); if (directory.Length > 0) { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } } bool isFailed = false; if (!overwriteFiles && File.Exists(output)) { FailFile(ref isFailed, input, "The output file '{0}' already exists.", output); return(false); } try { CompilerErrorCollection errors = new CompilerErrorCollection(); CompilerWarningCollection warnings = new CompilerWarningCollection(); Module module; IList <ICSharpCode.NRefactory.Parser.ISpecial> specials; CompileUnit compileUnit = new CompileUnit(); using (StreamReader r = OpenFile(input)) { module = Parser.ParseModule(compileUnit, r, ApplySettings(input, errors, warnings), out specials); } foreach (CompilerError error in errors) { FailFile(ref isFailed, input, error.ToString()); } if (!isFailed && warnings.Count > 0) { Console.WriteLine(input + ":"); foreach (CompilerWarning warning in warnings) { Console.WriteLine(" " + warning.ToString()); } } using (StreamWriter w = new StreamWriter(output, false, Encoding.UTF8)) { foreach (CompilerError error in errors) { w.WriteLine("ERROR: " + error.ToString()); } if (errors.Count > 0) { w.WriteLine(); } foreach (CompilerWarning warning in warnings) { w.WriteLine("# WARNING: " + warning.ToString()); } if (warnings.Count > 0) { w.WriteLine(); } BooPrinterVisitorWithComments printer = new BooPrinterVisitorWithComments(specials, w); if (module != null) { printer.OnModule(module); } printer.Finish(); } } catch (Exception ex) { FailFile(ref isFailed, input, ex); } return(!isFailed); }
ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) { ConverterSettings settings = new ConverterSettings(fileName, errors, warnings); settings.SimplifyTypeNames = simplifyTypeNames; settings.RemoveRedundantTypeReferences = removeRedundantTypeReferences; return(settings); }
public static ConverterSettings ApplySettings(string fileName, CompilerErrorCollection errors, CompilerWarningCollection warnings) { ConverterSettings settings = new ConverterSettings(fileName, errors, warnings); settings.SimplifyTypeNames = true; return(settings); }