Exemplo n.º 1
0
        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());
        }
Exemplo n.º 2
0
 private static bool BinaryExpressionUsesYearParameter(this LeapSolution leapSolution, BinaryExpressionSyntax binaryExpression) =>
 binaryExpression.Left.IsEquivalentWhenNormalized(
     LeapParameterIdentifierName(leapSolution)) ||
 binaryExpression.Right.IsEquivalentWhenNormalized(
     LeapParameterIdentifierName(leapSolution));
Exemplo n.º 3
0
 public static bool UsesTooManyChecks(this LeapSolution leapSolution) =>
 leapSolution.IsLeapYearMethod
 .DescendantNodes()
 .OfType <BinaryExpressionSyntax>()
 .Count(leapSolution.BinaryExpressionUsesYearParameter) > MinimalNumberOfChecks;
Exemplo n.º 4
0
 public static bool UsesExpressionBody(this LeapSolution leapSolution) =>
 leapSolution.IsLeapYearMethod.IsExpressionBody();
Exemplo n.º 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)))));
Exemplo n.º 9
0
 private static BinaryExpressionSyntax LeapYearModuloExpression(LeapSolution solution, int year) =>
 ModuloExpression(
     LeapParameterIdentifierName(solution),
     NumericLiteralExpression(year));
Exemplo n.º 10
0
 private static BinaryExpressionSyntax DivisibleByFourHundred(LeapSolution solution) =>
 EqualsExpression(
     LeapYearModuloExpression(solution, 400),
     NumericLiteralExpression(0));
Exemplo n.º 11
0
 public static BinaryExpressionSyntax LeapMinimumNumberOfChecksWithParenthesesBinaryExpression(LeapSolution solution) =>
 LogicalAndExpression(
     DivisibleByFour(solution),
     ParenthesizedExpression(
         LogicalOrExpression(
             NotDivisibleByHundred(solution),
             DivisibleByFourHundred(solution))));
Exemplo n.º 12
0
 public static IdentifierNameSyntax LeapParameterIdentifierName(LeapSolution solution) =>
 IdentifierName(solution.YearParameterName);