protected override BasePropertyDeclarationSyntax InjectMutations(PropertyDeclarationSyntax sourceNode,
                                                                         BasePropertyDeclarationSyntax targetNode, MutationContext context)
        {
            var result = base.InjectMutations(sourceNode, targetNode, context);

            if (!context.HasStatementLevelMutant)
            {
                return(result);
            }
            var mutated = result as PropertyDeclarationSyntax;

            if (mutated?.ExpressionBody == null)
            {
                return(result);
            }
            mutated = MutantPlacer.ConvertPropertyExpressionToBodyAccessor(mutated);
            var getter = mutated.GetAccessor();

            result = mutated.ReplaceNode(getter.Body !, SyntaxFactory.Block(
                                             MutantPlacer.PlaceStatementControlledMutations(
                                                 getter.Body,
                                                 context.StatementLevelControlledMutations.Union(context.BlockLevelControlledMutations).Select(
                                                     m => (m.Id,
                                                           SyntaxFactory.ReturnStatement(
                                                               sourceNode.ExpressionBody !.Expression
                                                               .InjectMutation(m.Mutation)) as StatementSyntax)))))
                     .WithSemicolonToken(SyntaxFactory.MissingToken(SyntaxKind.SemicolonToken));
            return(result);
        }
Exemple #2
0
        protected override BasePropertyDeclarationSyntax InjectMutations(PropertyDeclarationSyntax sourceNode,
                                                                         BasePropertyDeclarationSyntax targetNode, MutationContext context)
        {
            var result  = base.InjectMutations(sourceNode, targetNode, context);
            var mutated = result as PropertyDeclarationSyntax;

            // if there is no statement level mutations or this is not an expression property declaration, we can stop
            if (!context.HasStatementLevelMutant || mutated?.ExpressionBody == null)
            {
                return(result);
            }

            // we need to convert the expression property to a regular property
            mutated = MutantPlacer.ConvertPropertyExpressionToBodyAccessor(mutated);
            var getter = mutated.GetAccessor();

            // and inject pending mutations in the getter's body.
            result = mutated.ReplaceNode(getter.Body !,
                                         SyntaxFactory.Block(context.InjectBlockLevelExpressionMutation(getter.Body, sourceNode.ExpressionBody !.Expression, true)))
                     .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.None));
            return(result);
        }