protected void CheckForBooleanConstant(TBinaryExpression binaryExpression, IsBooleanLiteralKind isBooleanLiteralKind, ErrorLocation errorLocation, SyntaxNodeAnalysisContext context, bool isLeftSide) { var expression = isLeftSide ? RemoveParentheses(GetLeftNode(binaryExpression)) : RemoveParentheses(GetRightNode(binaryExpression)); if (!isBooleanLiteralKind(expression)) { return; } context.ReportDiagnosticWhenActive(Diagnostic.Create(SupportedDiagnostics[0], GetLocation())); Location GetLocation() { switch (errorLocation) { case ErrorLocation.BoolLiteral: return(expression.GetLocation()); case ErrorLocation.BoolLiteralAndOperator: return(CalculateExtendedLocation(binaryExpression, isLeftSide)); case ErrorLocation.NonBoolLiteralExpression: return(CalculateExtendedLocation(binaryExpression, !isLeftSide)); default: return(null); } } }
protected void CheckForBooleanConstantOnRight(TBinaryExpression binaryExpression, IsBooleanLiteralKind isBooleanLiteralKind, ErrorLocation errorLocation, SyntaxNodeAnalysisContext context) => CheckForBooleanConstant(binaryExpression, isBooleanLiteralKind, errorLocation, context, isLeftSide: false);