Esempio n. 1
0
        /*
         * Update the target to include the fully
         * qualified type name of the target entity.
         */

        protected void GetFullyQualifiedTarget(
            LookupTarget target, List <string> namespaceList)
        {
            foreach (string ns in namespaceList)
            {
                string fullEntity = ns;
                if (ns != String.Empty)
                {
                    fullEntity += ".";
                }
                fullEntity += target.Entity;

                string[] split = fullEntity.Split('.');

                string type = String.Empty;

                for (int i = 0; i < split.Length; i++)
                {
                    if (i > 0)
                    {
                        type += ".";
                    }
                    type += split[i];

                    /*
                     * Try a lookahead for nested types. This is a hack
                     * and only works for one level (i.e. just one '+').
                     */

                    if (i < split.Length - 1)
                    {
                        string nestedName = type + "+" + split[i + 1];

                        target.Type = SearchAssemblyList(nestedName);

                        if (target.Type != null)
                        {
                            target.FullEntity = fullEntity;
                            return;
                        }
                    }

                    /*
                     * Get back to looking for 'normal' types.
                     */

                    target.Type = SearchAssemblyList(type);

                    if (target.Type != null)
                    {
                        target.FullEntity = fullEntity;
                        return;
                    }
                }
            }
        }
Esempio n. 2
0
        protected List <LookupListItem> GetChildNamespaces(
            LookupTarget target, string text)
        {
            string[] split = text.Split(';');
            text = split[split.Length - 1];

            Regex           re = new Regex(@"import\s+");
            MatchCollection mc = re.Matches(text);

            if (mc.Count == 0)
            {
                return(null);
            }

            return(GetImmediateChildNamespaces(target.Entity));
        }
        protected List <LookupListItem> GetTypeMembers(
            string source,
            LookupTarget target,
            bool staticLookup,
            bool allowNonPublic)
        {
            /*
             * First we need to fully qualify the target type if it's
             * not already fully qualified. We assume it isn't and
             * test each possible namespace prefix until we find a
             * valid type. We add a blank namespace to the list to allow
             * for types that are already fully qualified.
             */

            List <String> namespaceList = GetNamespaceList(source);

            namespaceList.Insert(0, String.Empty);

            GetFullyQualifiedTarget(target, namespaceList);

            if (target.Type == null)
            {
                return(null);
            }

            /*
             * We now need to separate the type from its sub-members
             * and work down the chain getting the type of
             * each sub-member until we either get a void return type or
             * reach the end of the list. The last type we get that's
             * not void is the type we want.
             */

            string members = target.FullEntity.Substring(
                target.Type.FullName.Length).TrimStart('.');

            Type type = target.Type;

            if (members != String.Empty)
            {
                string[] split = members.Split('.');

                if (split.Length == 0)
                {
                    return(null);
                }

                foreach (string member in split)
                {
                    MemberInfo[] mi = type.GetMember(member);

                    if (mi.Length == 0)
                    {
                        return(null);
                    }

                    staticLookup = false;

                    string typeName = GetMemberTypeName(mi[0]);

                    if (typeName == null)
                    {
                        return(null);
                    }
                    if (typeName == "System.Void")
                    {
                        return(null);
                    }

                    type = SearchAssemblyList(typeName);

                    // If not found try a nested type
                    if (type == null)
                    {
                        typeName = target.Type.FullName + "+" + typeName;
                        type     = SearchAssemblyList(typeName);
                    }

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

            return(GetTypeMemberList(
                       type, staticLookup, allowNonPublic, true));
        }
        private LookupList GetJScriptLookupList(
            QuickSharp.Editor.ScintillaEditForm document)
        {
            UpdateLists();

            if ((settingsManager.ColorizeTypes ||
                 settingsManager.ColorizeVariables) &&
                settingsManager.ColorizeOnLookup)
            {
                ColourizeVariablesAndTypes(document);
            }

            /*
             * Get the search target from the current line.
             */

            Line line = document.Editor.Lines.Current;

            string text = line.Text.Substring(0,
                                              line.SelectionStartPosition -
                                              line.StartPosition).TrimStart();

            /*
             * Check for embedded option or empty comment.
             */

            if (text.StartsWith("//"))
            {
                if (text.Length > 2 && "$?&".IndexOf(text[2]) != -1)
                {
                    return(EmbeddedOptionHelper.GetEmbbededOptionFileList(text));
                }
                else
                {
                    return(null);
                }
            }

            /*
             * Cleanup the source.
             */

            text = JScriptFormattingTools.RemoveUnwantedText(text);
            text = JScriptFormattingTools.RemoveUnwantedBracketText(text);
            text = JScriptFormattingTools.RemoveUnwantedParentheses(text);

            LookupTarget          target = new LookupTarget(text);
            List <LookupListItem> lookupItemList;

            string source = document.GetContent() as string;

            source = source.Substring(0, document.Editor.CurrentPos);
            source = JScriptFormattingTools.RemoveUnwantedText(source);
            source = JScriptFormattingTools.RemoveUnwantedBracketText(source);

            /*
             * Looking for namespaces as part of an 'import'
             * declaration...
             */

            lookupItemList = GetChildNamespaces(target, text);

            if (lookupItemList != null)
            {
                return(new LookupList(target.LookAhead, lookupItemList));
            }

            /*
             * Looking for members of a namespace...
             */

            if (target.Entity != String.Empty)
            {
                List <LookupListItem> types =
                    FindNamespaceTypeLookupItems(target.Entity);

                List <LookupListItem> namespaces =
                    FindNamespaceChildLookupItems(target.Entity);

                if (types != null || namespaces != null)
                {
                    lookupItemList = new List <LookupListItem>();
                    if (types != null)
                    {
                        lookupItemList.AddRange(types);
                    }
                    if (namespaces != null)
                    {
                        lookupItemList.AddRange(namespaces);
                    }
                }
            }

            if (lookupItemList != null)
            {
                return(new LookupList(target.LookAhead, lookupItemList));
            }

            /*
             * Get the local variables declared within the scope visible
             * from the lookup location (the caret)...
             */

            DeclaredVariables declaredVariables =
                new DeclaredVariables(source, fullNamespaceList, true);

            /*
             * Looking for anything in scope...
             */

            if (String.IsNullOrEmpty(target.Entity))
            {
                lookupItemList = GetVisibleTypes(
                    source, declaredVariables, true, true);

                if (lookupItemList != null)
                {
                    // Add the root namespaces
                    foreach (string ns in rootNamespaceList)
                    {
                        LookupListItem item = new LookupListItem();
                        item.DisplayText = ns;
                        item.InsertText  = ns;
                        item.Category    = QuickSharp.CodeAssist.Constants.NAMESPACE;
                        item.ToolTipText = String.Format("namespace {0}", ns);
                        lookupItemList.Add(item);
                    }

                    return(new LookupList(target.LookAhead, lookupItemList));
                }
            }

            /*
             * The target cannot be blank after this point; if we haven't found
             * anything using a blank target then there's nothing to find.
             */

            if (String.IsNullOrEmpty(target.Entity))
            {
                return(null);
            }

            /*
             * Looking for members of a variable...
             */

            Variable variable = declaredVariables.GetVariable(target.Entity);

            if (variable != null)
            {
                String[] split = target.Entity.Split('.');

                if (target.IsIndexed)
                {
                    target.Entity = variable.GetVariableCollectionType(target.Entity);
                }
                else
                {
                    split[0]      = variable.Type;
                    target.Entity = String.Join(".", split);
                }

                lookupItemList = GetTypeMembers(
                    source, target, false, false);

                if (lookupItemList != null)
                {
                    return(new LookupList(target.LookAhead, lookupItemList));
                }
            }

            /*
             * Looking for members of a class...
             */

            lookupItemList = GetTypeMembers(source, target, true, false);

            return(new LookupList(target.LookAhead, lookupItemList));
        }