private void AnalyzeStatement(SyntaxNodeAnalysisContext context) { if (GeneratedCodeAnalyzer?.IsGeneratedCode(context) == true) { return; } if (!context.Node.IsKind(SyntaxKind.IfStatement) || IfElseChainAnalysis.IsIsolatedIf((IfStatementSyntax)context.Node)) { BlockSyntax block = EmbeddedStatementAnalysis.GetBlockThatCanBeEmbeddedStatement(context.Node); if (block != null && !block.OpenBraceToken.IsMissing && !block.CloseBraceToken.IsMissing && block.OpenBraceToken.LeadingTrivia.IsWhitespaceOrEndOfLine() && block.OpenBraceToken.TrailingTrivia.IsWhitespaceOrEndOfLine() && block.CloseBraceToken.LeadingTrivia.IsWhitespaceOrEndOfLine() && block.CloseBraceToken.TrailingTrivia.IsWhitespaceOrEndOfLine()) { context.ReportDiagnostic( DiagnosticDescriptors.RemoveBracesFromStatement, block.GetLocation()); DiagnosticHelper.FadeOutBraces(context, block, DiagnosticDescriptors.RemoveBracesFromStatementFadeOut); } } }
public static void Analyze(SyntaxNodeAnalysisContext context, IfStatementSyntax ifStatement) { if (IfElseChainAnalysis.IsIsolatedIf(ifStatement) && CheckCondition(ifStatement.Condition)) { IfStatementSyntax ifStatement2 = GetContainedIfStatement(ifStatement); if (ifStatement2 != null && ifStatement2.Else == null && CheckCondition(ifStatement2.Condition)) { context.ReportDiagnostic( DiagnosticDescriptors.MergeIfStatementWithContainedIfStatement, ifStatement.GetLocation()); FadeOut(context, ifStatement, ifStatement2); } } }
private void AnalyzeStatement(SyntaxNodeAnalysisContext context) { if (GeneratedCodeAnalyzer?.IsGeneratedCode(context) == true) { return; } AnalyzeEmbeddedStatement(context); if (context.Node.IsKind(SyntaxKind.IfStatement) && !IfElseChainAnalysis.IsIsolatedIf((IfStatementSyntax)context.Node)) { return; } StatementSyntax statement = EmbeddedStatementAnalysis.GetEmbeddedStatementThatShouldBeInsideBlock(context.Node); if (statement != null) { context.ReportDiagnostic( DiagnosticDescriptors.AddBracesToStatement, statement.GetLocation()); } }