Esempio n. 1
0
 private ISymbolTable ApplyFilters(ISymbolTable table)
 {
     int mustRun;
     ISymbolFilter[] filters = GetSymbolFilters(out mustRun);
     return table.Filter(filters);
 }
Esempio n. 2
0
        private static ISymbolTable GetReferenceSymbolTable(IPsiServices psiServices, [CanBeNull] string area,
                                                            [CanBeNull] string controller, [CanBeNull] string view, MvcKind mvcKind, [CanBeNull] IProject project, Version version)
        {
            if (project == null)
            {
                return(EmptySymbolTable.INSTANCE);
            }
            ISolution solution  = project.GetSolution();
            var       component = solution.GetComponent <MvcCache>();
            IEnumerable <IProject> searcheableProjects = GetSearcheableProjects(project);
            bool hasExtension = false;

            if (view != null)
            {
                if (view.IndexOfAny(FileSystemDefinition.InvalidPathChars) != -1)
                {
                    return(EmptySymbolTable.INSTANCE);
                }
                if (view == "???")
                {
                    return(EmptySymbolTable.INSTANCE);
                }
                hasExtension = Path.HasExtension(view);
            }
            ISymbolTable symbolTable = EmptySymbolTable.INSTANCE;

            foreach (IProject current in searcheableProjects)
            {
                ISymbolTable symbolTable2 = EmptySymbolTable.INSTANCE;
                string       text         = null;
                if (view != null)
                {
                    string text2 = Path.IsPathRooted(view) ? ("~" + view) : view;
                    text = HtmlPathReferenceUtil.ExpandRootName(text2.Replace('/', '\\'), current);
                    if (Path.IsPathRooted(text))
                    {
                        FileSystemPath fileSystemPath = FileSystemPath.Parse(text);
                        if (!fileSystemPath.IsAbsolute)
                        {
                            fileSystemPath = WebPathReferenceUtil.GetRootPath(project).Combine(fileSystemPath);
                        }
                        symbolTable2 = symbolTable2.Merge(new DeclaredElementsSymbolTable <PathDeclaredElement>(psiServices, new[]
                        {
                            new PathDeclaredElement(psiServices, fileSystemPath)
                        }, 0, null));
                    }
                }
                List <string> list = null;
                if (hasExtension)
                {
                    list = component.GetDisplayModes(current).ToList();
                }
                string[] arg_152_0;
                if (!area.IsEmpty())
                {
                    var array = new string[2];
                    array[0]  = area;
                    arg_152_0 = array;
                }
                else
                {
                    arg_152_0 = new[]
                    {
                        area
                    };
                }
                string[] array2 = arg_152_0;
                for (int i = 0; i < array2.Length; i++)
                {
                    string area2 = array2[i];
                    foreach (
                        string current2 in
                        component.GetLocations(current, MvcUtil.GetViewLocationType(mvcKind, area2), true))
                    {
                        using (
                            IEnumerator <Pair <string, string> > enumerator3 =
                                ParseLocationFormatString(current2, mvcKind, controller, area2).GetEnumerator())
                        {
                            while (enumerator3.MoveNext())
                            {
                                Pair <string, string> location        = enumerator3.Current;
                                FileSystemPath        fileSystemPath2 = FileSystemPath.TryParse(location.First);
                                FileSystemPath        location2       = (location.First.LastIndexOf('\\') ==
                                                                         location.First.Length - 1)
                                    ? fileSystemPath2
                                    : fileSystemPath2.Directory;
                                var projectFolder = current.FindProjectItemByLocation(location2) as IProjectFolder;
                                if (projectFolder != null)
                                {
                                    Func <IProjectItem, bool> extensionFilter = item => item.Location.FullPath.EndsWith(location.Second, StringComparison.OrdinalIgnoreCase);
                                    Func <IProjectItem, bool> preFilter       = extensionFilter;
                                    if (view != null)
                                    {
                                        string text3 = Path.IsPathRooted(text)
                                            ? text
                                            : (location.First + text + location.Second);
                                        string extension     = Path.GetExtension(text3);
                                        var    possibleNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
                                        {
                                            text3
                                        };
                                        if (list != null)
                                        {
                                            foreach (string current3 in list)
                                            {
                                                possibleNames.Add(Path.ChangeExtension(text3, current3 + extension));
                                            }
                                        }
                                        preFilter = item => extensionFilter(item) && possibleNames.Contains(item.Location.FullPath);
                                    }
                                    // todo tmp
                                    var referenceContext = new PathReferenceContext(psiServices, projectFolder.Location);
                                    symbolTable2 = symbolTable2.Merge(PathReferenceUtil.GetSymbolTableByPath(referenceContext, false, true, projectItem => GetViewName(projectItem.Location, location), preFilter));
                                }
                            }
                        }
                    }
                }
                symbolTable = symbolTable.Merge(symbolTable2.Filter(new[]
                {
                    FileFilters.FileExists,
                    new FileFilters.ItemInProjectFilter(current)
                }));
            }
            return(symbolTable.Distinct(PathInfoComparer.Instance));
        }
 public static ISymbolTable Filter(this ISymbolTable symbolTable, Func <ISymbolInfo, bool> predicate)
 {
     return(symbolTable.Filter(new PredicateFilter(predicate)));
 }
        private static IEnumerable GetChildren(ITypeElement typeElement, bool instanceVisible)
        {
            // Obtain language service for the type
            PsiLanguageType language = PresentationUtil.GetPresentationLanguage(typeElement);

            if (language.IsNullOrUnknown())
            {
                return(Enumerable.Empty <DeclaredElementEnvoy <ITypeMember> >());
            }

            LanguageService languageService = language.LanguageService();

            if (languageService == null)
            {
                return(Enumerable.Empty <DeclaredElementEnvoy <ITypeMember> >());
            }

            // Get symbol table for the typeElement and filter it with OverriddenFilter
            // This filter removes all but leaf members for override chains
            ISymbolTable symbolTable = TypeFactory.CreateType(typeElement).GetSymbolTable(typeElement.Module);

            symbolTable = symbolTable.Filter(OverriddenFilter.INSTANCE);

            // Obtain ITypeElement for System.Object
            // We don't want ToString(), GetHashCode(), GetType() and Equals() to pollute tree view
            ITypeElement objectType = typeElement.Module.GetPredefinedType(typeElement.ResolveContext).Object.GetTypeElement();
            var          children   = new List <DeclaredElementEnvoy <ITypeMember> >();

            foreach (string name in symbolTable.Names())
            {
                foreach (ISymbolInfo info in symbolTable.GetSymbolInfos(name))
                {
                    // Select all ITypeMembers from symbol table
                    var member = info.GetDeclaredElement() as ITypeMember;
                    if (member == null)
                    {
                        continue;
                    }
                    // Checks that member is visible in language. For example, get_Property() member is not visible in C#
                    if (!languageService.IsTypeMemberVisible(member))
                    {
                        continue;
                    }
                    // Do not show members of System.Object
                    // This doesn't hide respective overrides, though
                    if (Equals(member.GetContainingType(), objectType))
                    {
                        continue;
                    }
                    // Checks that member is not "synthetic". Synthetic members are generated by ReSharper to support
                    // generative languages, like ASP.NET
                    if (member.IsSynthetic())
                    {
                        continue;
                    }

                    // Checks if member should be displayed according to its accessibility
                    AccessibilityDomain.AccessibilityDomainType access = member.AccessibilityDomain.DomainType;
                    if (access == AccessibilityDomain.AccessibilityDomainType.PRIVATE)
                    {
                        continue;
                    }

                    // If we want only instance members, filter further
                    if (instanceVisible)
                    {
                        // Don't show nested types
                        if (member is ITypeElement)
                        {
                            continue;
                        }
                        // Don't show constructors
                        if (member is IConstructor)
                        {
                            continue;
                        }

                        // hide static, protected and "protected internal" members
                        if (member.IsStatic)
                        {
                            continue;
                        }
                        if (access == AccessibilityDomain.AccessibilityDomainType.PROTECTED)
                        {
                            continue;
                        }
                        if (access == AccessibilityDomain.AccessibilityDomainType.PROTECTED_AND_INTERNAL)
                        {
                            continue;
                        }
                    }
                    // It passed all filters! Create an envoy and add to collection
                    children.Add(new DeclaredElementEnvoy <ITypeMember>(member));
                }
            }

            return(children);
        }