public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false); LiteralExpressionSyntax literalExpression = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <LiteralExpressionSyntax>(); Debug.Assert(literalExpression != null, $"{nameof(literalExpression)} is null"); if (literalExpression == null) { return; } Debug.Assert(literalExpression.IsBooleanLiteralExpression(), literalExpression.Kind().ToString()); if (!literalExpression.IsBooleanLiteralExpression()) { return; } SyntaxNode parent = literalExpression.Parent; switch (parent?.Kind()) { case SyntaxKind.ForStatement: { RegisterCodeFix( context, cancellationToken => { return(RemoveRedundantBooleanLiteralRefactoring.RefactorAsync( context.Document, (ForStatementSyntax)parent, cancellationToken)); }); break; } case SyntaxKind.LogicalAndExpression: case SyntaxKind.LogicalOrExpression: case SyntaxKind.EqualsExpression: case SyntaxKind.NotEqualsExpression: { RegisterCodeFix( context, cancellationToken => { return(RemoveRedundantBooleanLiteralRefactoring.RefactorAsync( context.Document, (BinaryExpressionSyntax)parent, cancellationToken)); }); break; } } }