Пример #1
0
        /// <summary>
        /// Returns list of namespaces that affect given result item (using blocks and namespaces declarations)
        /// </summary>
        private NamespacesList GetUsedNamespacesFor(CodeStringResultItem resultItem)
        {
            if (resultItem is NetStringResultItem)
            {
                CodeNamespace namespaceElement = (resultItem as NetStringResultItem).NamespaceElement;

                if (namespaceElement == null)   // no parent namespace - use source item as a key
                {
                    if (!usedNamespacesCache.ContainsKey(resultItem.SourceItem))
                    {
                        usedNamespacesCache.Add(resultItem.SourceItem, namespaceElement.GetUsedNamespaces(resultItem.SourceItem));
                    }
                    return(usedNamespacesCache[resultItem.SourceItem]);
                }
                else     // has parent namespace - used namespaces can differ, use the parent namespace as a key
                {
                    if (!usedNamespacesCache.ContainsKey(namespaceElement))
                    {
                        usedNamespacesCache.Add(namespaceElement, namespaceElement.GetUsedNamespaces(resultItem.SourceItem));
                        if (usedNamespacesCache.ContainsKey(resultItem.SourceItem))
                        {
                            usedNamespacesCache[namespaceElement].AddRange(usedNamespacesCache[resultItem.SourceItem]);
                        }
                    }

                    return(usedNamespacesCache[namespaceElement]);
                }
            }
            else if (resultItem is AspNetStringResultItem)
            {
                // in case of ASP .NET result items, always use source item as a key
                if (!usedNamespacesCache.ContainsKey(resultItem.SourceItem))
                {
                    usedNamespacesCache.Add(resultItem.SourceItem, (resultItem as AspNetStringResultItem).DeclaredNamespaces);
                }
                return(usedNamespacesCache[resultItem.SourceItem]);
            }
            else
            {
                throw new Exception("Unkown result item type.");
            }
        }
Пример #2
0
        /// <summary>
        /// Should return result item located in current selection point. Returns null in any case of errors and exceptions.
        /// </summary>
        public override VBCodeReferenceResultItem GetCodeReferenceResultItem()
        {
            if (currentCodeModel == null)
            {
                throw new Exception("Current document has no CodeModel.");
            }

            string       text;
            TextPoint    startPoint;
            string       codeFunctionName;
            string       codeVariableName;
            CodeElement2 codeClass;
            TextSpan     selectionSpan;
            bool         isConst;
            object       codeModelSource;

            // get code block in which current selection point is located
            bool ok = GetCodeBlockFromSelection(out text, out startPoint, out codeFunctionName, out codeVariableName, out codeClass, out selectionSpan, out isConst, out codeModelSource);
            VBCodeReferenceResultItem result = null;

            if (ok)
            {
                CodeNamespace codeNamespace = codeClass.GetNamespace();

                // get list of all references in given code block
                List <VBCodeReferenceResultItem> items = VBCodeReferenceLookuper.Instance.LookForReferences(currentDocument.ProjectItem, text, startPoint, currentDocument.ProjectItem.ContainingProject.GetResXItemsAround(false, true).CreateTrie(),
                                                                                                            codeNamespace.GetUsedNamespaces(currentDocument.ProjectItem), false, currentDocument.ProjectItem.ContainingProject, null);

                // select the reference located in current selection (if any)
                foreach (VBCodeReferenceResultItem item in items)
                {
                    if (item.ReplaceSpan.Contains(selectionSpan))
                    {
                        result                 = item;
                        result.SourceItem      = currentDocument.ProjectItem;
                        result.CodeModelSource = codeModelSource;
                        break;
                    }
                }
            }

            return(result);
        }
Пример #3
0
 /// <summary>
 /// Get namespaces affecting this result item
 /// </summary>
 public override NamespacesList GetUsedNamespaces()
 {
     return(NamespaceElement.GetUsedNamespaces(SourceItem));
 }