Exemplo n.º 1
0
        AstType GuessType(RefactoringContext context, IdentifierExpression identifier)
        {
            var type = CreateField.GuessType(context, identifier);

            if (type != null)
            {
                return(type);
            }

            if (identifier != null && (identifier.Parent is InvocationExpression || identifier.Parent.Parent is InvocationExpression))
            {
                var invocation = (identifier.Parent as InvocationExpression) ?? (identifier.Parent.Parent as InvocationExpression);
                var result     = context.Resolve(invocation).Type.GetDelegateInvokeMethod();
                if (result == null)
                {
                    return(null);
                }
                int i = 0;
                foreach (var arg in invocation.Arguments)
                {
                    if (arg.Contains(identifier.StartLocation))
                    {
                        break;
                    }
                    i++;
                }
                if (result.Parameters.Count < i)
                {
                    return(null);
                }
                return(context.CreateShortType(result.Parameters[i].Type));
            }
            return(null);
        }
Exemplo n.º 2
0
 AstNode GeneratePropertyDeclaration(RefactoringContext context, IdentifierExpression identifier)
 {
     return(new PropertyDeclaration()
     {
         ReturnType = CreateField.GuessType(context, identifier),
         Name = identifier.Identifier,
         Getter = new Accessor(),
         Setter = new Accessor()
     });
 }
Exemplo n.º 3
0
        public bool IsValid(RefactoringContext context)
        {
            var identifier = CreateField.GetIdentifier(context);

            if (identifier == null)
            {
                return(false);
            }
            return(context.Resolve(identifier) == null && CreateField.GuessType(context, identifier) != null);
        }
Exemplo n.º 4
0
        public bool IsValid(RefactoringContext context)
        {
            if (GetUnresolvedArguments(context).Count > 0)
            {
                return(true);
            }
            var identifier = CreateField.GetIdentifier(context);

            if (identifier == null)
            {
                return(false);
            }
            if (context.GetNode <Statement> () == null)
            {
                return(false);
            }
            return(context.Resolve(identifier) == null && GuessType(context, identifier) != null);
        }
Exemplo n.º 5
0
        public void Run(RefactoringContext context)
        {
            var stmt = context.GetNode <Statement> ();
            var unresolvedArguments = GetUnresolvedArguments(context);

            if (unresolvedArguments.Count > 0)
            {
                using (var script = context.StartScript()) {
                    foreach (var id in unresolvedArguments)
                    {
                        script.InsertBefore(stmt, GenerateLocalVariableDeclaration(context, id));
                    }
                }
                return;
            }

            using (var script = context.StartScript()) {
                script.InsertBefore(stmt, GenerateLocalVariableDeclaration(context, CreateField.GetIdentifier(context)));
            }
        }