Beispiel #1
0
        private void DoAddParsedTypes(List<Item> items, string ns, string stem)
        {
            CsType[] types = m_parses.FindTypes(ns, stem);

            foreach (CsType type in types)
            {
                var item = new NameItem(type.Name, type.FullName, ns + " types", type.FullName);
                items.AddIfMissing(item);
            }
        }
Beispiel #2
0
        private Item[] DoGetNamespacesNamed(string name)
        {
            Profile.Start("AutoComplete::DoGetNamespacesNamed");
            var items = new List<Item>(m_database.GetNamespaces(name));

            string[] names = m_parses.FindNamespaces(name);
            #if DEBUG
            Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "db namespaces: {0}", items.ToDebugString());
            Log.WriteLine(TraceLevel.Verbose, "AutoComplete", "parsed namespaces: {0}", names.ToDebugString());
            #endif

            foreach (string n in names)
            {
                var item = new NameItem(n, name + '.' + n, name + " types");
                items.AddIfMissing(item);
            }

            Profile.Stop("AutoComplete::DoGetNamespacesNamed");
            return items.ToArray();
        }
Beispiel #3
0
 private void DoAddAliasedTypes(List<Item> items, string stem)
 {
     IEnumerable<string> aliases = CsHelpers.GetAliasedNames();
     foreach (string alias in aliases)
     {
         if (alias.StartsWith(stem))
         {
             var item = new NameItem(alias, CsHelpers.GetRealName(alias), "System types", CsHelpers.GetRealName(alias));
             items.AddIfMissing(item);
         }
     }
 }
Beispiel #4
0
        private Item DoCreateItem(string displayText, string filter, int kind, string type)
        {
            string[] parts = displayText.Split(':');
            Contract.Assert(parts.Length == 6, "expected 6 parts from " + displayText);

            string rtype = parts[0];
            string name = parts[2];

            Item result;
            if (kind == 1 || kind == 2)
            {
                // property getter or setter
                result = new NameItem(name, rtype + ' ' + name, filter, type);
            }
            else
            {
                string[] gargs = parts[3].Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries);
                string[] argTypes = parts[4].Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries);
                string[] argNames = parts[5].Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries);

                if (kind == 3)
                {
                    // indexer getter
                    result = new MethodItem(rtype, name, gargs, argTypes, argNames, type, filter, '[', ']');
                }
                else if (kind == 4)
                {
                    // indexer setter
                    argTypes = argTypes.SubArray(0, argTypes.Length - 1);
                    argNames = argNames.SubArray(0, argNames.Length - 1);
                    result = new MethodItem(rtype, name, gargs, argTypes, argNames, "System.Void", filter, '[', ']');
                }
                else if (kind == 8)
                {
                    // extension method
                    argTypes = argTypes.SubArray(1);
                    argNames = argNames.SubArray(1);
                    result = new MethodItem(rtype, name, gargs, argTypes, argNames, type, filter);
                }
                else if (kind == 0 || kind == 6)
                {
                    // normal method or constructor
                    result = new MethodItem(rtype, name, gargs, argTypes, argNames, type, filter);
                }
                else
                    throw new Exception("bad method kind: " + kind);
            }

            return result;
        }
Beispiel #5
0
        public Item[] GetStemmedTypes(string[] namespaces, string stem)
        {
            if (m_disposed)
                throw new ObjectDisposedException(GetType().Name);
            Profile.Start("TargetDatabase::GetStemmedTypes");
            var items = new List<Item>();

            var ns = new StringBuilder();
            if (namespaces.Length > 0)
            {
                ns.Append('(');
                for (int i = 0; i < namespaces.Length; ++i)
                {
                    ns.AppendFormat("namespace = '{0}'", namespaces[i]);

                    if (i + 1 < namespaces.Length)
                        ns.Append(" OR ");
                }
                ns.Append(") AND");
            }

            string sql;
            if (stem.Length > 0)
                sql = string.Format(@"
                    SELECT name, root_name
                        FROM Types
                    WHERE visibility < 3 AND {0} name GLOB '{1}*'", ns.ToString(), stem);
            else
                sql = string.Format(@"
                    SELECT name, root_name
                        FROM Types
                    WHERE {0} visibility < 3", ns.ToString());

            string[][] rows = m_database.QueryRows(sql);
            foreach (string[] r in rows)
            {
                var item = new NameItem(r[0], r[1], "types");
                items.AddIfMissing(item);
            }

            Profile.Stop("TargetDatabase::GetStemmedTypes");
            return items.ToArray();
        }
Beispiel #6
0
        public Item[] GetNamespaces(string ns)
        {
            if (m_disposed)
                throw new ObjectDisposedException(GetType().Name);
            var items = new List<Item>();
            Profile.Start("TargetDatabase::GetNamespaces");

            if (ns.Length > 0)
            {
                string sql = string.Format(@"
                    SELECT children
                        FROM Namespaces
                    WHERE parent = '{0}'", ns);
                string[][] rows = m_database.QueryRows(sql);

                foreach (string[] r in rows)
                {
                    string[] children = r[0].Split(';');
                    foreach (string child in children)
                    {
                        var item = new NameItem(child, ns + '.' + child, "Namespaces");
                        items.AddIfMissing(item);
                    }
                }
            }
            else
            {
                string sql = @"
                    SELECT parent, children
                        FROM Namespaces";
                string[][] rows = m_database.QueryRows(sql);

                foreach (string[] r in rows)
                {
                    string[] children = r[1].Split(';');
                    foreach (string child in children)
                    {
                        var item = new NameItem(r[0] + '.' + child, ns + '.' + r[0] + '.' + child, "Namespaces");
                        items.AddIfMissing(item);
                    }
                }
            }

            Profile.Stop("TargetDatabase::GetNamespaces");
            return items.ToArray();
        }
Beispiel #7
0
        public Item[] GetMembers(string[] typeNames, bool instanceCall, bool isStaticCall, string name, int arity, bool includeProtected)
        {
            if (m_disposed)
                throw new ObjectDisposedException(GetType().Name);
            Profile.Start("TargetDatabase::GetMembers2");
            var items = new List<Item>();

            if (typeNames.Length > 0)
            {
                var types = new StringBuilder();
                for (int i = 0; i < typeNames.Length; ++i)
                {
                    types.AppendFormat("declaring_root_name = '{0}'", typeNames[i].Replace("'", "''"));

                    if (i + 1 < typeNames.Length)
                        types.Append(" OR ");
                }

                string access = includeProtected ? "access < 3" : "(access = 0 OR access = 2)";

                string sql;
                if (instanceCall && isStaticCall)
                    sql = string.Format(@"
                        SELECT display_text, declaring_root_name, kind, return_type_name, name
                            FROM Methods
                        WHERE (name = '{0}' OR name = '{1}') AND params_count = {2} AND
                            (kind <= 2 OR kind = 5) AND {4} AND ({3})", name, "get_" + name, arity, types.ToString(), access);
                else
                    sql = string.Format(@"
                        SELECT display_text, declaring_root_name, kind, return_type_name, name
                            FROM Methods
                        WHERE (name = '{0}' OR name = '{1}') AND params_count = {2} AND
                            static = {4} AND {5} AND (kind <= 2 OR kind = 5) AND ({3})", name, "get_" + name, arity, types.ToString(), isStaticCall ? "1" : "0", access);

                NamedRows rows = m_database.QueryNamedRows(sql);
                foreach (NamedRow r in rows)
                {
                    int kind = int.Parse(r["kind"]);

                    if (kind <= 2)
                    {
                        Item item = DoCreateItem(r["display_text"], r["declaring_root_name"], kind, r["return_type_name"]);
                        items.AddIfMissing(item);
                    }
                    else
                    {
                        string eName = r["name"];
                        int i = eName.IndexOf('_');
                        eName = eName.Substring(i + 1);

                        Item item = new NameItem(eName, "event " + eName, r["declaring_root_name"], "event-type");
                        items.AddIfMissing(item);
                    }
                }
            }

            Profile.Stop("TargetDatabase::GetMembers2");
            return items.ToArray();
        }