public CSharpSyntaxNode AddRequires(ParameterSyntax parameter, SemanticModel semanticModel)
        {
            Contract.Requires(parameter != null);
            Contract.Requires(semanticModel != null);

            if (_method != null)
            {
                var anchor = GetParentForCurrentParameter(parameter, ContractBlock.CreateForMethodAsync(_method, semanticModel).Result);
                return(RequiresUtils.AddRequires(parameter, _method, anchor));
            }

            var accessors = new SyntaxList <AccessorDeclarationSyntax>();

            foreach (var accessor in _indexer.AccessorList.Accessors)
            {
                var contractBlock = ContractBlock.CreateForMethodAsync(accessor, semanticModel).Result;
                var anchor        = GetParentForCurrentParameter(parameter, contractBlock);
                if (contractBlock.Preconditions.Any(x => x.ChecksForNotNull(parameter)))
                {
                    accessors = accessors.Add(accessor);
                }
                else
                {
                    var body = RequiresUtils.AddRequires(parameter, accessor.Body, anchor);
                    accessors = accessors.Add(accessor.WithBody(body));
                }
            }

            return(_indexer.WithAccessorList(_indexer.AccessorList.WithAccessors(accessors)));
        }
        public async Task <string> AddNotNullPrecondition(string method)
        {
            var doc = await ClassTemplate.FromMethodAsync(method);

            var parameterSyntax = doc.SelectedNode as ParameterSyntax;

            Assert.IsNotNull(parameterSyntax);

            var newMethod = RequiresUtils.AddRequires(parameterSyntax);

            Console.WriteLine("Original method:\r\n" + method);

            //var rr = Formatter.Format(method, Formatter.Annotation, doc.Document.Project.Solution.Workspace);
            var newMethodString = newMethod.WithLeadingTrivia().GetText().ToString();

            Console.WriteLine("New method (without leading trivia):\r\n" + newMethodString);

            return(newMethodString);
        }