本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.MethodDeclarationSyntax.InsertStatements方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDeclarationSyntax.InsertStatements方法的具体用法?C# MethodDeclarationSyntax.InsertStatements怎么用?C# MethodDeclarationSyntax.InsertStatements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.MethodDeclarationSyntax
的用法示例。
在下文中一共展示了MethodDeclarationSyntax.InsertStatements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractAndAddPmQm
private MethodDeclarationSyntax ExtractAndAddPmQm(ref CancellationToken cancellationToken,
Microsoft.CodeAnalysis.Document localDocument, SyntaxNode oldRoot, MethodDeclarationSyntax newExtractedMethod) {
var newText = oldRoot.ToFullString();
cancellationToken.ThrowIfCancellationRequested();
Utils.DumpCSFile("BeforePmQm.cs", newText);
var newSolution = localDocument.Project.Solution.WithDocumentText(localDocument.Id, SourceText.From(newText));
//var newSolution = localDocument.Project.Solution.UpdateDocument(localDocument.Id, SourceText.From(newText));
var newLocalDocument = newSolution.GetDocument(localDocument.Id);
localDocument = null; // to be sure we do not use it
var newTree = newLocalDocument.GetSyntaxTree();
Utils.Trace("Running Clousot to infer <Pm, Qm> and <Pr, Qr>");
var newRoot = (CompilationUnitSyntax)newTree.GetRoot();
if (newRoot.ContainsDiagnostics) {
Utils.Trace("Aborting: the new tree has syntax errors");
return null;
}
// Let Clousot see the rewritten unit
var connectionToClousot = new RoslynToCCICodeModel.ClousotGlue();
var results = connectionToClousot.AnalyzeMeAUnit(newLocalDocument, newRoot, cancellationToken, this.options,
new string[] { "-extractmethodmoderefine", newExtractedMethod.Identifier.ValueText, "-premode", "combined", "-suggest", "methodensures", "-suggest:requires" });
if (results == null) return null;
foreach (var result in results)
{
cancellationToken.ThrowIfCancellationRequested();
Utils.Trace("Getting Clousot Result");
String condition;
ContractKind kind;
if (result.Message.TryParseSuggestion(out kind, out condition)) {
Utils.Trace("Inserting Clousot result. New Condition: " + condition);
// Parse the condition
var newContract = SyntaxFactory.ParseStatement(condition + Environment.NewLine);
if (!newContract.ContainsDiagnostics) {
newExtractedMethod = newExtractedMethod.InsertStatements(newContract, kind);
} else {
Utils.Trace("\tskipped, as it contains syntax errors");
}
}
}
return newExtractedMethod;
}
示例2: ExtractAndAddPsQs
private MethodDeclarationSyntax ExtractAndAddPsQs(ref CancellationToken cancellationToken, Microsoft.CodeAnalysis.Document localDocument, CompilationUnitSyntax newRoot, MethodDeclarationSyntax newExtractedMethod)
{
// Let Clousot see the rewritten unit
var connectionToClousot = new RoslynToCCICodeModel.ClousotGlue();
var results = connectionToClousot.AnalyzeMeAUnit(localDocument, newRoot, cancellationToken, this.options,
new string[] { "-extractmethodmode", "-arrays:arraypurity", "-suggest:requires" /*"-memberNameSelect",*/ });
if (results == null) return null;
foreach (var result in results)
{
cancellationToken.ThrowIfCancellationRequested();
Utils.Trace("Getting Clousot Result");
String condition;
ContractKind kind;
if (result.IsExtractMethodSuggestion && result.Message.TryParseSuggestion(out kind, out condition))
{
Utils.Trace("Inserting Clousot result. New Condition: " + condition);
// Parse the condition
var newContract = SyntaxFactory.ParseStatement(condition + Environment.NewLine);
newExtractedMethod = newExtractedMethod.InsertStatements(newContract, kind);
}
else
{
Utils.Trace("Skipped Clousot output : " + result.Message);
}
}
return newExtractedMethod;
}