AstNode ToStaticMethodInvocation(InvocationExpression invocation, MemberReferenceExpression memberReference,
		                                 CSharpInvocationResolveResult invocationRR)
        {
            var newArgumentList = invocation.Arguments.Select(arg => arg.Clone()).ToList();
            newArgumentList.Insert(0, memberReference.Target.Clone());
            var newTarget = memberReference.Clone() as MemberReferenceExpression;
            newTarget.Target = new IdentifierExpression(invocationRR.Member.DeclaringType.Name);
            return new InvocationExpression(newTarget, newArgumentList);
        }
Esempio n. 2
0
        AstNode ToStaticMethodInvocation(InvocationExpression invocation, MemberReferenceExpression memberReference,
                                         CSharpInvocationResolveResult invocationRR)
        {
            var newArgumentList = invocation.Arguments.Select(arg => arg.Clone()).ToList();

            newArgumentList.Insert(0, memberReference.Target.Clone());
            var newTarget = memberReference.Clone() as MemberReferenceExpression;

            newTarget.Target = new IdentifierExpression(invocationRR.Member.DeclaringType.Name);
            return(new InvocationExpression(newTarget, newArgumentList));
        }
        public IEnumerable <CodeAction> GetActions(RefactoringContext context)
        {
            if (!context.IsSomethingSelected)
            {
                yield break;
            }
            var pexpr = context.GetNode <PrimitiveExpression>();

            if (pexpr == null || !(pexpr.Value is string))
            {
                yield break;
            }
            if (pexpr.LiteralValue.StartsWith("@", StringComparison.Ordinal))
            {
                if (!(pexpr.StartLocation < new TextLocation(context.Location.Line, context.Location.Column - 1) && new TextLocation(context.Location.Line, context.Location.Column + 1) < pexpr.EndLocation))
                {
                    yield break;
                }
            }
            else
            {
                if (!(pexpr.StartLocation < context.Location && context.Location < pexpr.EndLocation))
                {
                    yield break;
                }
            }

            yield return(new CodeAction(context.TranslateString("Introduce format item"), script => {
                var invocation = context.GetNode <InvocationExpression>();
                if (invocation != null && invocation.Target.IsMatch(PrototypeFormatReference))
                {
                    AddFormatCallToInvocation(context, script, pexpr, invocation);
                    return;
                }

                var arg = CreateFormatArgument(context);
                var newInvocation = new InvocationExpression(PrototypeFormatReference.Clone())
                {
                    Arguments = { CreateFormatString(context, pexpr, 0), arg }
                };

                script.Replace(pexpr, newInvocation);
                script.Select(arg);
            }, pexpr));
        }
        public void Run(RefactoringContext context)
        {
            var pexpr      = context.GetNode <PrimitiveExpression> ();
            var invocation = context.GetNode <InvocationExpression> ();

            if (invocation != null && invocation.Target.IsMatch(PrototypeFormatReference))
            {
                AddFormatCallToInvocation(context, pexpr, invocation);
                return;
            }

            var arg           = CreateFormatArgument(context);
            var newInvocation = new InvocationExpression(PrototypeFormatReference.Clone())
            {
                Arguments = { CreateFormatString(context, pexpr, 0), arg }
            };

            using (var script = context.StartScript()) {
                script.Replace(pexpr, newInvocation);
                script.Select(arg);
            }
        }