Beispiel #1
0
        public override void Initialize(AnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            base.Initialize(context);

            context.RegisterSyntaxNodeAction(
                f => RemoveEmptyStatementRefactoring.AnalyzeEmptyStatement(f),
                SyntaxKind.EmptyStatement);
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out EmptyStatementSyntax emptyStatement))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove empty statement",
                cancellationToken => RemoveEmptyStatementRefactoring.RefactorAsync(context.Document, emptyStatement, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.RemoveEmptyStatement));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
Beispiel #3
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            EmptyStatementSyntax emptyStatement = root
                                                  .FindNode(context.Span, getInnermostNodeForTie: true)?
                                                  .FirstAncestorOrSelf <EmptyStatementSyntax>();

            if (emptyStatement == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove empty statement",
                cancellationToken => RemoveEmptyStatementRefactoring.RefactorAsync(context.Document, emptyStatement, cancellationToken),
                DiagnosticIdentifiers.RemoveEmptyStatement + EquivalenceKeySuffix);

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
Beispiel #4
0
        private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context)
        {
            SyntaxNode emptyStatement = context.Node;

            RemoveEmptyStatementRefactoring.Analyze(context, emptyStatement);
        }