public async Task <Document> ApplyRefactoringAsync(Document document, CancellationToken token) { MethodDeclarationSyntax method = _selectedNode.AncestorsAndSelf().OfType <MethodDeclarationSyntax>().First(); Option <ExpressionStatementSyntax> lastRequires = await GetLastRequiresStatement(document, method, token); SyntaxNode root = await document.GetSyntaxRootAsync(token); SyntaxNode rootWithRequires = root.ReplaceNode(method, RequiresUtils.AddEnsures(method, _semanticModel, lastRequires)); SyntaxNode rootWithUsings = RequiresUtils.AddContractNamespaceIfNeeded(rootWithRequires); return(document.WithSyntaxRoot(rootWithUsings)); }