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());
        }
Example #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))));
Example #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));
        }
Example #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);
        }
Example #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))));
Example #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));
Example #13
0
 public static bool UsesAddMethod(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.AddMethod.InvokesExpression(
     GigasecondAddMemberAccessExpression(gigasecondSolution));
Example #14
0
 public static bool ReturnsAddSecondsWithMathPow(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.Returns(
     GigasecondAddSecondsInvocationExpression(
         gigasecondSolution,
         GigasecondAddSecondsWithMathPowInvocationExpression()));
Example #15
0
 public static bool ReturnsAddSecondsWithDigitsWithoutSeparator(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.Returns(
     GigasecondAddSecondsWithDigitsWithoutSeparatorInvocationExpression(gigasecondSolution));
 public static MemberAccessExpressionSyntax GigasecondAddMemberAccessExpression(GigasecondSolution gigasecondSolution) =>
 GigasecondMemberAccessExpression(gigasecondSolution, IdentifierName("Add"));
Example #17
0
 public static bool UsesExpressionBody(this GigasecondSolution gigasecondSolution) =>
 gigasecondSolution.AddMethod.IsExpressionBody();