当前位置: 首页>>代码示例>>C#>>正文


C# MethodDeclarationSyntax.InsertStatements方法代码示例

本文整理汇总了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;
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:57,代码来源:RefactoringProvider.cs

示例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;
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:32,代码来源:RefactoringProvider.cs


注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.MethodDeclarationSyntax.InsertStatements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。