Beispiel #1
0
 private static void AnalyzeLogicalAndLogicalOr(
     SyntaxNodeAnalysisContext context,
     BinaryExpressionSyntax binaryExpression,
     ExpressionSyntax left,
     ExpressionSyntax right,
     SyntaxKind kind)
 {
     if (left.IsKind(kind) ||
         right.IsKind(kind))
     {
         RemoveRedundantBooleanLiteralAnalysis.ReportDiagnostic(context, binaryExpression, left, right);
     }
 }
Beispiel #2
0
        private static void AnalyzeEqualsNotEquals(
            SyntaxNodeAnalysisContext context,
            BinaryExpressionSyntax binaryExpression,
            ExpressionSyntax left,
            ExpressionSyntax right,
            SyntaxKind kind,
            SyntaxKind kind2)
        {
            SyntaxKind leftKind = left.Kind();

            if (leftKind == kind)
            {
                switch (AnalyzeExpression(right, context.SemanticModel, context.CancellationToken))
                {
                case AnalysisResult.Boolean:
                {
                    SimplifyBooleanComparisonAnalysis.ReportDiagnostic(context, binaryExpression, left, right, fadeOut: true);
                    break;
                }

                case AnalysisResult.LogicalNotWithNullableBoolean:
                {
                    SimplifyBooleanComparisonAnalysis.ReportDiagnostic(context, binaryExpression, left, right, fadeOut: false);
                    break;
                }
                }
            }
            else if (leftKind == kind2)
            {
                switch (AnalyzeExpression(right, context.SemanticModel, context.CancellationToken))
                {
                case AnalysisResult.Boolean:
                {
                    RemoveRedundantBooleanLiteralAnalysis.ReportDiagnostic(context, binaryExpression, left, right);
                    break;
                }

                case AnalysisResult.LogicalNotWithNullableBoolean:
                {
                    SimplifyBooleanComparisonAnalysis.ReportDiagnostic(context, binaryExpression, left, right, fadeOut: false);
                    break;
                }
                }
            }
            else
            {
                SyntaxKind rightKind = right.Kind();

                if (rightKind == kind)
                {
                    switch (AnalyzeExpression(left, context.SemanticModel, context.CancellationToken))
                    {
                    case AnalysisResult.Boolean:
                    {
                        SimplifyBooleanComparisonAnalysis.ReportDiagnostic(context, binaryExpression, left, right, fadeOut: true);
                        break;
                    }

                    case AnalysisResult.LogicalNotWithNullableBoolean:
                    {
                        SimplifyBooleanComparisonAnalysis.ReportDiagnostic(context, binaryExpression, left, right, fadeOut: false);
                        break;
                    }
                    }
                }
                else if (rightKind == kind2)
                {
                    switch (AnalyzeExpression(left, context.SemanticModel, context.CancellationToken))
                    {
                    case AnalysisResult.Boolean:
                    {
                        RemoveRedundantBooleanLiteralAnalysis.ReportDiagnostic(context, binaryExpression, left, right);
                        break;
                    }

                    case AnalysisResult.LogicalNotWithNullableBoolean:
                    {
                        SimplifyBooleanComparisonAnalysis.ReportDiagnostic(context, binaryExpression, left, right, fadeOut: false);
                        break;
                    }
                    }
                }
            }
        }