Esempio n. 1
0
        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax invocation)
        {
            invocation = (InvocationExpressionSyntax)base.VisitInvocationExpression(invocation);
            if (InvocationMatches(invocation, _method.Type, _method.Name))
            {
                var newInvocation = invocation;

                var argList = new List <ArgumentSyntax>();
                argList.AddRange(invocation.ArgumentList.Arguments);

                var itemsToRemove = _positions
                                    .Select(position => argList[position - 1])
                                    .ToList();

                foreach (var item in itemsToRemove)
                {
                    argList.Remove(item);
                }


                var argListSyntax = ArgumentList(SeparatedList(argList));
                argListSyntax = argListSyntax.WithCloseParenToken(argListSyntax.CloseParenToken
                                                                  .WithTrailingTrivia(invocation.ArgumentList.CloseParenToken.TrailingTrivia)
                                                                  .WithLeadingTrivia(invocation.ArgumentList.CloseParenToken.LeadingTrivia));

                newInvocation = newInvocation.WithArgumentList(argListSyntax);

                invocation = invocation.CopyAnnotationsTo(newInvocation);
            }
            return(invocation);
        }
Esempio n. 2
0
            private InvocationExpressionSyntax RewriteExtensionMethodInvocation(
                InvocationExpressionSyntax originalNode,
                ExpressionSyntax thisExpression,
                IMethodSymbol reducedExtensionMethod,
                SymbolDisplayFormat symbolDisplayFormat)
            {
                var containingType  = reducedExtensionMethod.ContainingType.ToDisplayString(symbolDisplayFormat);
                var newMemberAccess = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ParseExpression(containingType), ((MemberAccessExpressionSyntax)originalNode.Expression).OperatorToken, ((MemberAccessExpressionSyntax)originalNode.Expression).Name)
                                      .WithLeadingTrivia(thisExpression.GetFirstToken().LeadingTrivia);

                // Copies the annotation for the member access expression
                newMemberAccess = originalNode.Expression.CopyAnnotationsTo(newMemberAccess).WithAdditionalAnnotations(Simplifier.Annotation);

                var thisArgument = SyntaxFactory.Argument(thisExpression).WithLeadingTrivia(SyntaxTriviaList.Empty);

                // Copies the annotation for the left hand side of the member access expression to the first argument in the complexified form
                thisArgument = ((MemberAccessExpressionSyntax)originalNode.Expression).Expression.CopyAnnotationsTo(thisArgument);

                var arguments       = originalNode.ArgumentList.Arguments.Insert(0, thisArgument);
                var replacementNode = SyntaxFactory.InvocationExpression(
                    newMemberAccess,
                    originalNode.ArgumentList.WithArguments(arguments));

                // This Annotation copy is for the InvocationExpression
                return(originalNode.CopyAnnotationsTo(replacementNode).WithAdditionalAnnotations(Simplifier.Annotation));
            }
Esempio n. 3
0
        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax invocation)
        {
            invocation = (InvocationExpressionSyntax)base.VisitInvocationExpression(invocation);
            if (InvocationMatches(invocation, FullTypeName, MethodName))
            {
                var newInvocation = invocation;

                var argList = new List <ArgumentSyntax>();
                argList.AddRange(invocation.ArgumentList.Arguments);

                foreach (var arg in Arguments)
                {
                    var argument = Argument(!string.IsNullOrEmpty(arg.DefaultValueExpression) ?
                                            ParseExpression(arg.DefaultValueExpression):
                                            DefaultExpression(IdentifierName((string)arg.Type)));

                    argList.Insert(arg.Position - 1, argument);
                }

                var argListSyntax = ArgumentList(SeparatedList(argList));
                argListSyntax = argListSyntax.WithCloseParenToken(argListSyntax.CloseParenToken
                                                                  .WithTrailingTrivia(invocation.ArgumentList.CloseParenToken.TrailingTrivia)
                                                                  .WithLeadingTrivia(invocation.ArgumentList.CloseParenToken.LeadingTrivia));

                newInvocation = newInvocation.WithArgumentList(argListSyntax);

                invocation = invocation.CopyAnnotationsTo(newInvocation);
            }
            return(invocation);
        }
Esempio n. 4
0
        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax invocation)
        {
            invocation = (InvocationExpressionSyntax)base.VisitInvocationExpression(invocation);
            if (InvocationMatches(invocation, _method.Type, _method.Name))
            {
                var newInvocation = invocation;

                var argList = new List <ArgumentSyntax>();
                argList.AddRange(invocation.ArgumentList.Arguments);

                foreach (var arg in _arguments)
                {
                    argList[arg.Position - 1] = Argument(ParseExpression(arg.DefaultValueExpression));
                    // TODO: Add identifier type, if possible
                }

                var argListSyntax = ArgumentList(SeparatedList(argList));
                argListSyntax = argListSyntax.WithCloseParenToken(argListSyntax.CloseParenToken
                                                                  .WithTrailingTrivia(invocation.ArgumentList.CloseParenToken.TrailingTrivia)
                                                                  .WithLeadingTrivia(invocation.ArgumentList.CloseParenToken.LeadingTrivia));

                newInvocation = newInvocation.WithArgumentList(argListSyntax);

                invocation = invocation.CopyAnnotationsTo(newInvocation);
            }
            return(invocation);
        }
Esempio n. 5
0
        public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax invocation)
        {
            if (InvocationMatches(invocation, FullTypeName, OldMethodName))
            {
                var oldIdentifier = GetMethodIdentifier(invocation.Expression);

                var newIdentifier = IdentifierName(NewMethodName);
                newIdentifier = oldIdentifier.CopyAnnotationsTo(newIdentifier);

                var newInvocation = invocation.ReplaceNode(
                    oldIdentifier,
                    newIdentifier);

                invocation = invocation.CopyAnnotationsTo(newInvocation);

                Context.UpdateNodeContainingClassType(newIdentifier, FullTypeName);
            }
            return(invocation);
        }
            private InvocationExpressionSyntax RewriteExtensionMethodInvocation(
                InvocationExpressionSyntax originalNode,
                ExpressionSyntax thisExpression,
                IMethodSymbol reducedExtensionMethod,
                SymbolDisplayFormat symbolDisplayFormat)
            {
                var containingType = reducedExtensionMethod.ContainingType.ToDisplayString(symbolDisplayFormat);
                var newMemberAccess = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ParseExpression(containingType), ((MemberAccessExpressionSyntax)originalNode.Expression).OperatorToken, ((MemberAccessExpressionSyntax)originalNode.Expression).Name)
                    .WithLeadingTrivia(thisExpression.GetFirstToken().LeadingTrivia);

                // Copies the annotation for the member access expression
                newMemberAccess = originalNode.Expression.CopyAnnotationsTo(newMemberAccess).WithAdditionalAnnotations(Simplifier.Annotation);

                var thisArgument = SyntaxFactory.Argument(thisExpression).WithLeadingTrivia(SyntaxTriviaList.Empty);

                // Copies the annotation for the left hand side of the member access expression to the first argument in the complexified form
                thisArgument = ((MemberAccessExpressionSyntax)originalNode.Expression).Expression.CopyAnnotationsTo(thisArgument);

                var arguments = originalNode.ArgumentList.Arguments.Insert(0, thisArgument);
                var replacementNode = SyntaxFactory.InvocationExpression(
                    newMemberAccess,
                    originalNode.ArgumentList.WithArguments(arguments));

                // This Annotation copy is for the InvocationExpression
                return originalNode.CopyAnnotationsTo(replacementNode).WithAdditionalAnnotations(Simplifier.Annotation, Formatter.Annotation);
            }