Beispiel #1
0
        public async Task <bool> Test_Refactoring_Availability(string method)
        {
            var doc = await ClassTemplate.FromMethodAsync(method);

            var refactoring = await AddNotNullEnsuresRefactoring.Create(doc.SelectedNode, doc.SemanticModel);

            return(await refactoring.IsAvailableAsync(CancellationToken.None));
        }
        private void AnalyseReturnType(SyntaxNodeAnalysisContext context)
        {
            var enclosingMetod = context.Node.Parent as MethodDeclarationSyntax;

            if (enclosingMetod == null || !enclosingMetod.IsPublicOrProtected())
            {
                return;
            }

            var ensuresRefactoring = AddNotNullEnsuresRefactoring.Create(context.Node, context.SemanticModel,
                                                                         context.CancellationToken).Result;

            if (ensuresRefactoring.IsAvailableAsync(context.CancellationToken).Result)
            {
                var methodDeclaration = (MethodDeclarationSyntax)context.Node.Parent;
                var diagnostic        = Diagnostic.Create(AddEnsuresRule, context.Node.GetLocation(), methodDeclaration.ReturnType);
                context.ReportDiagnostic(diagnostic);
            }
        }
Beispiel #3
0
 internal override async Task <ICodeContractRefactoring> CreateRefactoringAsync(ClassTemplate doc)
 {
     return(await AddNotNullEnsuresRefactoring.Create(doc.SelectedNode, doc.SemanticModel));
 }