private static SolutionAnalysis Analyze(LeapSolution leapSolution)
        {
            if (leapSolution.UsesTooManyChecks())
            {
                return(leapSolution.DisapproveWithComment(LeapComments.UseMinimumNumberOfChecks));
            }

            if (leapSolution.ReturnsMinimumNumberOfChecksInSingleExpression())
            {
                return(leapSolution.UsesExpressionBody()
                    ? leapSolution.ApproveAsOptimal()
                    : leapSolution.ApproveWithComment(SharedComments.UseExpressionBodiedMember));
            }

            return(leapSolution.ReferToMentor());
        }
Example #2
0
 private static bool BinaryExpressionUsesYearParameter(this LeapSolution leapSolution, BinaryExpressionSyntax binaryExpression) =>
 binaryExpression.Left.IsEquivalentWhenNormalized(
     LeapParameterIdentifierName(leapSolution)) ||
 binaryExpression.Right.IsEquivalentWhenNormalized(
     LeapParameterIdentifierName(leapSolution));
Example #3
0
 public static bool UsesTooManyChecks(this LeapSolution leapSolution) =>
 leapSolution.IsLeapYearMethod
 .DescendantNodes()
 .OfType <BinaryExpressionSyntax>()
 .Count(leapSolution.BinaryExpressionUsesYearParameter) > MinimalNumberOfChecks;
Example #4
0
 public static bool UsesExpressionBody(this LeapSolution leapSolution) =>
 leapSolution.IsLeapYearMethod.IsExpressionBody();
Example #5
0
 public static bool ReturnsMinimumNumberOfChecksInSingleExpression(this LeapSolution leapSolution) =>
 leapSolution.Returns(LeapMinimumNumberOfChecksWithoutParenthesesBinaryExpression(leapSolution)) ||
 leapSolution.Returns(LeapMinimumNumberOfChecksWithParenthesesBinaryExpression(leapSolution));
 private static BinaryExpressionSyntax LeapModuloExpression(LeapSolution leapSolution, int number) =>
 ModuloExpression(
     LeapParameterIdentifierName(leapSolution),
     NumericLiteralExpression(number));
 public static IdentifierNameSyntax LeapParameterIdentifierName(LeapSolution leapSolution) =>
 IdentifierName(leapSolution.YearParameter.Identifier);
 public static BinaryExpressionSyntax LeapMinimumNumberOfChecksWithParenthesesBinaryExpression(LeapSolution leapSolution) =>
 LogicalAndExpression(
     EqualsExpression(
         LeapModuloExpression(leapSolution, 4),
         NumericLiteralExpression(0)),
     ParenthesizedExpression(
         LogicalOrExpression(
             NotEqualsExpression(
                 LeapModuloExpression(leapSolution, 100),
                 NumericLiteralExpression(0)),
             EqualsExpression(
                 LeapModuloExpression(leapSolution, 400),
                 NumericLiteralExpression(0)))));
Example #9
0
 private static BinaryExpressionSyntax LeapYearModuloExpression(LeapSolution solution, int year) =>
 ModuloExpression(
     LeapParameterIdentifierName(solution),
     NumericLiteralExpression(year));
Example #10
0
 private static BinaryExpressionSyntax DivisibleByFourHundred(LeapSolution solution) =>
 EqualsExpression(
     LeapYearModuloExpression(solution, 400),
     NumericLiteralExpression(0));
Example #11
0
 public static BinaryExpressionSyntax LeapMinimumNumberOfChecksWithParenthesesBinaryExpression(LeapSolution solution) =>
 LogicalAndExpression(
     DivisibleByFour(solution),
     ParenthesizedExpression(
         LogicalOrExpression(
             NotDivisibleByHundred(solution),
             DivisibleByFourHundred(solution))));
Example #12
0
 public static IdentifierNameSyntax LeapParameterIdentifierName(LeapSolution solution) =>
 IdentifierName(solution.YearParameterName);