private void AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) { var switchSection = (SwitchSectionSyntax)context.Node; FormatEachStatementOnSeparateLineRefactoring.Analyze(context, switchSection); if (AddBreakStatementToSwitchSectionRefactoring.CanRefactor(context, switchSection)) { context.ReportDiagnostic( DiagnosticDescriptors.AddBreakStatementToSwitchSection, switchSection); } RemoveRedundantDefaultSwitchSectionRefactoring.Analyze(context, switchSection); RemoveUnnecessaryCaseLabelRefactoring.Analyze(context, switchSection); FormatSwitchSectionStatementOnSeparateLineRefactoring.Analyze(context, switchSection); DefaultLabelShouldBeLastLabelInSwitchSectionRefactoring.Analyze(context, switchSection); SyntaxList <StatementSyntax> statements = switchSection.Statements; if (statements.Count > 1) { context.ReportDiagnostic( DiagnosticDescriptors.AddBracesToSwitchSectionWithMultipleStatements, Location.Create(switchSection.SyntaxTree, statements.Span)); } }
private void AnalyzeBlock(SyntaxNodeAnalysisContext context) { var block = (BlockSyntax)context.Node; FormatEachStatementOnSeparateLineRefactoring.Analyze(context, block); FormatEmptyBlockRefactoring.Analyze(context, block); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); if (!TryFindFirstAncestorOrSelf(root, context.Span, out StatementSyntax statement)) { return; } CodeAction codeAction = CodeAction.Create( "Format statement on a separate line", cancellationToken => FormatEachStatementOnSeparateLineRefactoring.RefactorAsync(context.Document, statement, cancellationToken), GetEquivalenceKey(DiagnosticIdentifiers.FormatEachStatementOnSeparateLine)); context.RegisterCodeFix(codeAction, context.Diagnostics); }
public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context) { SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false); StatementSyntax statement = root .FindNode(context.Span, getInnermostNodeForTie: true)? .FirstAncestorOrSelf <StatementSyntax>(); if (statement == null) { return; } CodeAction codeAction = CodeAction.Create( "Format embedded statement on a separate line", cancellationToken => FormatEachStatementOnSeparateLineRefactoring.RefactorAsync(context.Document, statement, cancellationToken), DiagnosticIdentifiers.FormatEmbeddedStatementOnSeparateLine + EquivalenceKeySuffix); context.RegisterCodeFix(codeAction, context.Diagnostics); }