private static SolutionAnalysis Analyze(GigasecondSolution gigasecondSolution)
        {
            if (gigasecondSolution.ReturnsAddSecondsWithScientificNotation())
            {
                return(gigasecondSolution.UsesExpressionBody()
                    ? gigasecondSolution.ApproveAsOptimal()
                    : gigasecondSolution.ApproveWithComment(SharedComments.UseExpressionBodiedMember));
            }

            if (gigasecondSolution.ReturnsAddSecondsWithMathPow())
            {
                return(gigasecondSolution.ApproveWithComment(GigasecondComments.UseScientificNotationNotMathPow));
            }

            if (gigasecondSolution.ReturnsAddSecondsWithDigitsWithoutSeparator())
            {
                return(gigasecondSolution.ApproveWithComment(GigasecondComments.UseScientificNotationOrDigitSeparators));
            }

            if (gigasecondSolution.UsesAddMethod() ||
                gigasecondSolution.UsesPlusOperator())
            {
                return(gigasecondSolution.DisapproveWithComment(GigasecondComments.UseAddSeconds));
            }

            return(gigasecondSolution.ReferToMentor());
        }
Exemple #2
0
 public static bool UsesPlusOperator(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.AddMethod
 .DescendantNodes <BinaryExpressionSyntax>()
 .Any(binaryExpression =>
      binaryExpression.IsKind(SyntaxKind.AddExpression) &&
      binaryExpression.DescendantNodes <IdentifierNameSyntax>()
      .Any(identifierName =>
           identifierName.IsEquivalentWhenNormalized(
               GigasecondParameterIdentifierName(gigasecondSolution))));
Exemple #3
0
        private static SolutionAnalysis ApproveWhenValid(this GigasecondSolution gigasecondSolution)
        {
            if (gigasecondSolution.UsesMathPow())
            {
                return(gigasecondSolution.ApproveWithComment(UseScientificNotationNotMathPow));
            }

            if (gigasecondSolution.UsesDigitsWithoutSeparator())
            {
                return(gigasecondSolution.ApproveWithComment(UseScientificNotationOrDigitSeparators));
            }

            if (!gigasecondSolution.UsesScientificNotation() &&
                !gigasecondSolution.UsesDigitsWithSeparator())
            {
                return(null);
            }

            if (gigasecondSolution.AssignsToParameterAndReturns() ||
                gigasecondSolution.AssignsToVariableAndReturns())
            {
                return(gigasecondSolution.ApproveWithComment(ReturnImmediately));
            }

            if (gigasecondSolution.UsesLocalConstVariable())
            {
                return(gigasecondSolution.ApproveAsOptimal());
            }

            if (gigasecondSolution.UsesLocalVariable())
            {
                return(gigasecondSolution.ApproveWithComment(UseConstant));
            }

            if (gigasecondSolution.UsesPrivateConstField())
            {
                return(gigasecondSolution.UsesExpressionBody()
                    ? gigasecondSolution.ApproveAsOptimal()
                    : gigasecondSolution.ApproveWithComment(UseExpressionBodiedMember));
            }

            if (gigasecondSolution.UsesConstField())
            {
                return(gigasecondSolution.ApproveWithComment(UsePrivateVisibility));
            }

            if (gigasecondSolution.UsesField())
            {
                return(gigasecondSolution.ApproveWithComment(UseConstant));
            }

            return(gigasecondSolution.UsesExpressionBody()
                ? gigasecondSolution.ApproveAsOptimal()
                : gigasecondSolution.ApproveWithComment(UseExpressionBodiedMember));
        }
Exemple #4
0
        private static SolutionAnalysis DisapproveWhenInvalid(this GigasecondSolution gigasecondSolution)
        {
            if (gigasecondSolution.CreatesNewDatetime())
            {
                return(gigasecondSolution.DisapproveWithComment(DontCreateDateTime));
            }

            if (gigasecondSolution.DoesNotUseAddSeconds())
            {
                return(gigasecondSolution.DisapproveWithComment(UseAddSeconds));
            }

            return(null);
        }
Exemple #5
0
 private static SolutionAnalysis Analyze(GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.DisapproveWhenInvalid() ??
 gigasecondSolution.ApproveWhenValid() ??
 gigasecondSolution.ReferToMentor();
 public static MemberAccessExpressionSyntax AddSecondsMemberAccessExpression(GigasecondSolution solution) =>
 SimpleMemberAccessExpression(
     IdentifierName(solution.AddMethodParameterName),
     IdentifierName("AddSeconds"));
 public static IdentifierNameSyntax GigasecondParameterIdentifierName(GigasecondSolution gigasecondSolution) =>
 IdentifierName(gigasecondSolution.BirthDateParameter.Identifier);
 private static MemberAccessExpressionSyntax GigasecondMemberAccessExpression(GigasecondSolution gigasecondSolution, IdentifierNameSyntax methodName) =>
 SimpleMemberAccessExpression(
     GigasecondParameterIdentifierName(gigasecondSolution),
     methodName);
 public static InvocationExpressionSyntax GigasecondAddSecondsInvocationExpression(GigasecondSolution gigasecondSolution, ExpressionSyntax argumentExpression) =>
 // TODO: consider adding factory method to invocation with argument
 InvocationExpression(
     GigasecondMemberAccessExpression(gigasecondSolution, IdentifierName("AddSeconds")))
 .WithArgumentList(
     ArgumentList(
         SingletonSeparatedList(
             GigasecondBirthDateArgument(argumentExpression))));
Exemple #10
0
 public static bool ReturnsAddSecondsWithScientificNotation(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.Returns(
     GigasecondAddSecondsWithScientificNotationInvocationExpression(gigasecondSolution));
 public static InvocationExpressionSyntax GigasecondAddSecondsWithScientificNotationInvocationExpression(GigasecondSolution gigasecondSolution) =>
 GigasecondAddSecondsInvocationExpression(
     gigasecondSolution,
     NumericLiteralExpression("1E9", 1e9));
 public static InvocationExpressionSyntax GigasecondAddSecondsWithDigitsWithoutSeparatorInvocationExpression(GigasecondSolution gigasecondSolution) =>
 GigasecondAddSecondsInvocationExpression(
     gigasecondSolution,
     NumericLiteralExpression(1000000000));
Exemple #13
0
 public static bool UsesAddMethod(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.AddMethod.InvokesExpression(
     GigasecondAddMemberAccessExpression(gigasecondSolution));
Exemple #14
0
 public static bool ReturnsAddSecondsWithMathPow(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.Returns(
     GigasecondAddSecondsInvocationExpression(
         gigasecondSolution,
         GigasecondAddSecondsWithMathPowInvocationExpression()));
Exemple #15
0
 public static bool ReturnsAddSecondsWithDigitsWithoutSeparator(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.Returns(
     GigasecondAddSecondsWithDigitsWithoutSeparatorInvocationExpression(gigasecondSolution));
 public static MemberAccessExpressionSyntax GigasecondAddMemberAccessExpression(GigasecondSolution gigasecondSolution) =>
 GigasecondMemberAccessExpression(gigasecondSolution, IdentifierName("Add"));
Exemple #17
0
 public static bool UsesExpressionBody(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.AddMethod.IsExpressionBody();