public static int DoAnnotate(string[] args) { #region CodeContracts Contract.Requires(args != null); Contract.Requires(Contract.ForAll(0, args.Length, i => args[i] != null)); Contract.Ensures(-1 <= Contract.Result <int>()); // we return 0 on success, -1 on failure #endregion CodeContracts // 1. parse the command line options Options options; String error; if (!Options.TryParseOptions(args, out options, out error)) { Options.PrintUsage(error); Output.WriteError("Can't parse the options"); return(-1); } // 2. Create a compilation using Roslyn Task <Compilation> compilationAsync; Compilation compilation; MSBuildWorkspace workspace; Project project; if (!RoslynInterface.TryCreateCompilation(options, out compilationAsync, out workspace, out project)) { Output.WriteError("Unable to create compilation"); return(-1); } // 3. Read Clousot XML CCCheckOutput xml; if (!XmlDoc.TryReadXml(options.ClousotXML, out xml)) { Output.WriteError("Unable to read XML"); return(-1); } compilation = compilationAsync.Result; // 4. Check for diagnostics in the solution Output.WritePhase("Checking whether the original project has errors"); var existingDiagnostics = compilation.GetDiagnostics(); if (existingDiagnostics.Where(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error).Any()) { Output.WriteWarning("The original project has some errors"); HelperForDiagnostics.PrintDiagnostics(existingDiagnostics); } // 5. Annotate Output.WritePhase("Reading the Contracts from Clousot"); var annotations = Parser.GetAnnotationDictionary(xml); Output.WritePhase("Applying the annotations to the source code"); var newcomp = ApplyAnnotations(annotations, compilation, project, true); // 6. Pretty print result Output.WritePhase("Cleaning up the code"); newcomp = UsingHelpers.CleanImports(project, newcomp); // 7. Write result to disk Output.WritePhase("Writing result back to disk"); newcomp = Writer.WriteChanges(compilation, newcomp, options.Output == OutputOption.inplace); //CommentHelpers.WriteCommentsFile(xml, compilation, newcomp, options.GitRoot); return(0); }