protected override IReference[] GetReferences(ITreeNode element, IReference[] oldReferences)
        {
            if (!HasReference(element, null))
            {
                return(EmptyArray <IReference> .Instance);
            }

            var stringLiteral = (IJavaScriptLiteralExpression)element;
            var references    = PathReferenceUtil.CreatePathReferences(stringLiteral, stringLiteral, null,
                                                                       GetFolderPathReference, GetFileReference, node => node.GetStringValue(), node => node.GetUnquotedTreeTextRange('"', '\'').StartOffset.Offset);

            return(references);
        }
        public static ISymbolTable GetReferenceSymbolTable(IPathReference pathReference, bool useReferenceName, bool includeHttpHandlers = true)
        {
            var propertiesSearcher =
                pathReference.GetTreeNode().GetSolution().GetComponent <MSBuildPropertiesCache>();

            string productHomeDir = propertiesSearcher.GetProjectPropertyByName(pathReference.GetTreeNode().GetProject(),
                                                                                "ProductHomeDir");
            var basePath = new FileSystemPath(productHomeDir);

            if (basePath.IsEmpty)
            {
                return(EmptySymbolTable.INSTANCE);
            }

            FolderQualifierInfo folderQualifierInfo = null;
            IPsiServices        psiServices         = pathReference.GetTreeNode().GetPsiServices();
            var baseProjectFolder = psiServices.Solution.FindProjectItemsByLocation(basePath).FirstOrDefault() as IProjectFolder;

            if (baseProjectFolder != null)
            {
                folderQualifierInfo = new FolderQualifierInfo(baseProjectFolder);
            }

            FileSystemPath websiteRoot = GetRootPath(pathReference);
            IQualifier     qualifier   = pathReference.GetQualifier();

            if (useReferenceName)
            {
                PathDeclaredElement target = null;
                string name = pathReference.GetName();
                switch (name)
                {
                case PathDeclaredElement.CURRENT_DIR_NAME:
                    target = new PathDeclaredElement(PathDeclaredElement.CURRENT_DIR_NAME, psiServices, basePath);
                    break;

                case PathDeclaredElement.LEVEL_UP_NAME:
                    target = new PathDeclaredElement(PathDeclaredElement.LEVEL_UP_NAME, psiServices, basePath.Directory);
                    break;

                case PathDeclaredElement.ROOT_NAME:
                    if (qualifier != null)
                    {
                        goto default;
                    }
                    target = new PathDeclaredElement(PathDeclaredElement.ROOT_NAME, psiServices, websiteRoot);
                    break;

                default:
                    try
                    {
                        string parserGenOutputBase =
                            propertiesSearcher.GetProjectPropertyByName(pathReference.GetTreeNode().GetProject(), "ParserGenOutputBase");
                        FileSystemPath path = basePath.Combine(parserGenOutputBase + "\\" + name);
                        target = new PathDeclaredElement(name, psiServices, path);
                    }
                    catch (InvalidPathException)
                    {
                    }
                    catch (ArgumentException)
                    {
                    }
                    break;
                }
                var table = new SymbolTable(psiServices, folderQualifierInfo != null ? new SymbolTableDependencySet(folderQualifierInfo) : null);
                if (target != null)
                {
                    table.AddSymbol(target, EmptySubstitution.INSTANCE, 1);
                }
                return(table);
            }

            FileSystemPath rootPath              = (qualifier == null) ? websiteRoot : FileSystemPath.Empty;
            ISymbolTable   symbolTableByPath     = PathReferenceUtil.GetSymbolTableByPath(basePath, psiServices, basePath.Directory, rootPath, true);
            FileSystemPath basePathBeforeMapping = GetBasePathBeforeMapping(pathReference);

            if (!basePathBeforeMapping.IsNullOrEmpty())
            {
                IWebProjectPathMapping pathMapping = WebPathMappingManager.GetPathMapping(pathReference);
                List <FileSystemPath>  mappedPaths = pathMapping.GetAllPathPartsIn(basePathBeforeMapping).ToList();
                if (mappedPaths.Any())
                {
                    var mappedPathsTable = new SymbolTable(psiServices, folderQualifierInfo != null ? new SymbolTableDependencySet(folderQualifierInfo) : null);
                    foreach (FileSystemPath mappedPath in mappedPaths)
                    {
                        var declaredElement = new PathDeclaredElement(psiServices, mappedPath);
                        mappedPathsTable.AddSymbol(declaredElement, EmptySubstitution.INSTANCE, 1);
                    }
                    symbolTableByPath = symbolTableByPath.Merge(mappedPathsTable);
                }
            }

            if (!includeHttpHandlers)
            {
                return(symbolTableByPath);
            }

            var httpHandlersTable = new SymbolTable(psiServices);

            return(httpHandlersTable.Merge(symbolTableByPath));
        }
Exemple #3
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));
        }