示例#1
0
        // Usually this will return zero or one name, but it can return more (eg for explicit interface
        // implementations).
        public Item[] Find(CsMember context, ResolvedTarget target, CsGlobalNamespace globals, string name, int arity)
        {
            Profile.Start("ResolveMembers::Find");
            var items = new List<Item>();

            var types = new List<CsType>();
            var baseNames = new List<string>();
            var interfaceNames = new List<string>();
            string[] allNames = DoGetBases(globals, target.TypeName, types, baseNames, interfaceNames);

            bool includeProtected = context != null && allNames.Contains(context.DeclaringType.FullName);
            foreach (CsType type in types)
            {
                var candidates = new List<Item>();

                bool includePrivate = context != null && type.FullName == context.DeclaringType.FullName;
                DoGetParsedMembers(type, target.IsInstance, target.IsStatic, candidates, includePrivate, includeProtected);
                items = (from m in candidates where DoMatch(m, name, arity) select m).ToList();
            }

            // Note that we need to make two GetMembers queries to ensure that interface
            // methods are not used in place of base methods (this gives us better results
            // when the context menu is used to filter out methods associated with types).
            DoAddIfMissingRange("Fields:", items, m_database.GetFields(baseNames.ToArray(), target.IsInstance, target.IsStatic, name, includeProtected));
            DoAddIfMissingRange("Base Members:", items, m_database.GetMembers(baseNames.ToArray(), target.IsInstance, target.IsStatic, name, arity, includeProtected));
            DoAddIfMissingRange("Interface Members:", items, m_database.GetMembers(interfaceNames.ToArray(), target.IsInstance, target.IsStatic, name, arity, includeProtected));

            if (target.IsInstance)
            {
                var namespaces = new List<string>();

                for (int i = 0; i < globals.Namespaces.Length; ++i)
                    namespaces.Add(globals.Namespaces[i].Name);

                for (int i = 0; i < globals.Uses.Length; ++i)
                    namespaces.Add(globals.Uses[i].Namespace);

                DoAddIfMissingRange("extension methods:", items, m_database.GetExtensionMethods(allNames, namespaces.ToArray(), name, arity));
            }

            Profile.Stop("ResolveMembers::Find");
            return items.ToArray();
        }
        private bool DoGetTarget(string text, string target, int offset, MockTargetDatabase database)
        {
            Log.WriteLine("AutoComplete", "{0} {1} {2}", new string('*', 10), new StackTrace().GetFrame(1).GetMethod().Name, new string('*', 10));

            var parser = new CsParser.Parser();
            CsGlobalNamespace globals = parser.Parse(text);

            var locals = new CsParser.LocalsParser();
            CsMember context = AutoComplete.FindDeclaration(globals, offset) as CsMember;
            var resolver = new ResolveName(context, database, locals, text, offset, globals);

            m_target = resolver.Resolve(target);
            return m_target != null;
        }
示例#3
0
        private ResolvedTarget DoHandleVariable(string name)
        {
            ResolvedTarget result = null;

            for (int i = 0; i < m_variables.Length && result == null; ++i)
            {
                if (m_variables[i].Name == name)
                {
                    string type = m_variables[i].Type;
                    if (type == "var" && m_variables[i].Value != null)
                    {
                        string value = m_variables[i].Value;
                        if (value.StartsWith("from "))		// these two don't have an explicit TYPE so we don't use ms_re for them
                        {
                            // var result = from ...;
                            value = "System.Collections.Generic.IEnumerable`1";
                        }
                        else if (value.StartsWith("typeof"))
                        {
                            // var result = typeof(...);
                            value = DoGetTypeofValue(value);
                        }
                        else
                        {
                            // var result = xxx TYPE yyy
                            value = DoGetReValue(value);
                        }

                        if (result == null && !string.IsNullOrEmpty(value))
                            result = Resolve(value);

                        if (result != null)
                        {
                            result = new ResolvedTarget(result.TypeName, result.Type, true, false);	// we resolved a type, but it's used as an instance...
                        }
                    }
                    else
                    {
                        result = m_typeResolver.Resolve(type, m_context, m_globals, true, false);
                    }
                }
            }

            return result;
        }
示例#4
0
        private bool DoGetTheTarget(string text, int offset, MockTargetDatabase database)
        {
            var parser = new CsParser.Parser();
            CsGlobalNamespace globals = parser.Parse(text);

            var locals = new CsParser.LocalsParser();
            CsMember context = AutoComplete.FindDeclaration(globals, offset) as CsMember;
            var nameResolver = new ResolveName(context, database, locals, text, offset, globals);
            var resolver = new ResolveExpr(database, globals, nameResolver);

            m_target = resolver.Resolve(context, text, offset);
            return m_target != null;
        }
示例#5
0
        private ResolvedTarget DoResolveOperand(CsMember context, ResolvedTarget target, string operand)
        {
            ResolvedTarget result = null;

            Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "    target: {0}, operand: '{1}'", target, operand);

            // Handle locals and args.
            if (target == null)
            {
                Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "trying local operand");
                result = m_nameResolver.Resolve(operand);
            }

            // Handle this calls (this will work for static calls too).
            if (target == null && result == null)
            {
                target = m_nameResolver.Resolve("this");
                Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "new target: {0}", target);
            }

            // Handle other calls.
            if (target != null && result == null)
            {
                int numArgs = DoGetNumArgs(operand);
                int i = operand.IndexOfAny(new char[]{'(', ' ', '\t', '\n', '\r'});
                string name = i >= 0 ? operand.Substring(0, i) : operand;

                if (name != null)
                {
                    Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "trying {0}({1} args) item operand", name, numArgs);

                    if (name == "typeof" && numArgs == 1)
                    {
                        Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "resolved to System.Type");
                        result = new ResolvedTarget("System.Type", null, true, false);
                    }
                    else
                    {
                        Item[] candidates = m_memberResolver.Find(context, target, m_globals, name, numArgs);
                        IEnumerable<Item> items = from c in candidates where c.Type != null select c;
                        if (items.Any())
                        {
                            if (items.All(m => m.Type == items.First().Type))
                            {
                                Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "{0}:{1} with {2} args resolved to {3}", target, name, numArgs, items.First().Type);
                                result = m_typeResolver.Resolve(items.First().Type, context, m_globals, true, false);
                            }
                            else
                            {
                                Log.WriteLine("AutoComplete", "{0} has an ambiguous return type:", name);
                                foreach (Item item in items)
                                {
                                    Log.WriteLine("AutoComplete", "    {0} {1}", item.Type, item);
                                }
                            }
                        }
                    }
                }
            }

            if (result == null)
                Log.WriteLine("AutoComplete", "failed to resolve {0}::{1}", target, operand);

            return result;
        }
示例#6
0
        private bool DoGetTarget(string text, string name, int offset, MockTargetDatabase database)
        {
            //Console.WriteLine("------------------------------------");
            //Console.WriteLine(name);
            //Console.WriteLine(text);

            var parser = new CsParser.Parser();
            CsGlobalNamespace globals = parser.Parse(text);

            var locals = new CsParser.LocalsParser();
            CsMember context = AutoComplete.FindDeclaration(globals, offset) as CsMember;
            var resolver = new ResolveName(context, database, locals, text, offset, globals);

            m_target = resolver.Resolve(name);
            return m_target != null;
        }