Esempio n. 1
0
        private void AddTokensToSymbolTable(ITreeNode tokenTypeClassFQNameNode)
        {
            myTokenTypeClassFqName = tokenTypeClassFQNameNode.GetText();
            myTokenTypeClassFqName = myTokenTypeClassFqName.Substring(1, myTokenTypeClassFqName.Length - 2);
            ICollection <ITypeElement> classes =
                GetPsiServices().Symbols.GetSymbolScope(GetPsiModule(), this.GetResolveContext(), false, true).GetTypeElementsByCLRName(
                    myTokenTypeClassFqName);
            IEnumerator <ITypeElement> enumerator = classes.GetEnumerator();

            if (enumerator.MoveNext())
            {
                var tokenTypeClass = enumerator.Current as IClass;
                if (tokenTypeClass != null)
                {
                    IList <IDeclaredElement> elements = new List <IDeclaredElement>();
                    AddTokenElements(tokenTypeClass, elements);
                    while ((tokenTypeClass != null) && (tokenTypeClass.GetBaseClassType() != null) && (tokenTypeClass.GetBaseClassType().GetTypeElement() as IClass != null))
                    {
                        tokenTypeClass = tokenTypeClass.GetBaseClassType().GetTypeElement() as IClass;
                        AddTokenElements(tokenTypeClass, elements);
                    }
                    ISymbolTable tokenSymbolTable = ResolveUtil.CreateSymbolTable(elements, 0);
                    myRuleSymbolTable = myRuleSymbolTable.Merge(tokenSymbolTable);
                }
            }
        }
Esempio n. 2
0
        public ISymbolTable CreateOptionSymbolTable(bool ifFileReal)
        {
            if (ifFileReal)
            {
                IList <IDeclaredElement> optionDeclaredElements = new List <IDeclaredElement>();
                foreach (string name in OptionDeclaredElements.FileOptionNames)
                {
                    IDeclaredElement element = new OptionPropertyDeclaredElement(GetSourceFile(), name,
                                                                                 GetSourceFile().GetPsiServices());
                    optionDeclaredElements.Add(element);
                }

                if (optionDeclaredElements.Count > 0)
                {
                    myOptionSymbolTable = ResolveUtil.CreateSymbolTable(optionDeclaredElements, 0);
                }

                optionDeclaredElements = new List <IDeclaredElement>();
                foreach (string name in OptionDeclaredElements.RuleOptionNames)
                {
                    IDeclaredElement element = new OptionPropertyDeclaredElement(GetSourceFile(), name,
                                                                                 GetSourceFile().GetPsiServices());
                    optionDeclaredElements.Add(element);
                }

                if (optionDeclaredElements.Count > 0)
                {
                    myOptionSymbolTable = myOptionSymbolTable.Merge(ResolveUtil.CreateSymbolTable(optionDeclaredElements, 0));
                }
                return(myOptionSymbolTable);
            }
            return(EmptySymbolTable.INSTANCE);
        }
Esempio n. 3
0
        private void AddTokensToSymbolTable(ITreeNode tokenTypeClassFQNameNode)
        {
            myTokenTypeClassFqName = tokenTypeClassFQNameNode.GetText();
            myTokenTypeClassFqName = myTokenTypeClassFqName.Substring(1, myTokenTypeClassFqName.Length - 2);
            ICollection <ITypeElement> classes =
                GetPsiServices().CacheManager.GetDeclarationsCache(GetPsiModule(), false, true).GetTypeElementsByCLRName(
                    myTokenTypeClassFqName);
            IEnumerator <ITypeElement> enumerator = classes.GetEnumerator();

            if (enumerator.MoveNext())
            {
                var tokenTypeClass = enumerator.Current as IClass;
                if (tokenTypeClass != null)
                {
                    IEnumerable <IField>     fields   = tokenTypeClass.Fields;
                    IList <IDeclaredElement> elements = new List <IDeclaredElement>();
                    foreach (IField field in fields)
                    {
                        if (field.IsReadonly && field.IsStatic)
                        {
                            elements.Add(field);
                        }
                    }
                    ISymbolTable tokenSymbolTable = ResolveUtil.CreateSymbolTable(elements, 0);
                    myRuleSymbolTable = myRuleSymbolTable.Merge(tokenSymbolTable);
                }
            }
        }
Esempio n. 4
0
        public override ISymbolTable GetReferenceSymbolTable(bool useReferenceName)
        {
            string       name        = GetName();
            IProject     project     = myOwner.GetProject();
            ISymbolTable symbolTable = EmptySymbolTable.INSTANCE;

            foreach (JetTuple <string, string, MvcUtil.DeterminationKind, ICollection <IClass> > tuple in names)
            {
                ISymbolTable symbolTable2;
                if (tuple.C == MvcUtil.DeterminationKind.ImplicitByContainingMember)
                {
                    symbolTable2 = (from @class in tuple.D
                                    where @class != null && @class.IsValid()
                                    select GetReferenceSymbolTable(@class, useReferenceName ? name : null, mvcKind, version, tuple.A)).Merge();
                }
                else
                {
                    symbolTable2 = GetReferenceSymbolTable(psiServices, tuple.A, tuple.B, useReferenceName ? name : null, mvcKind, project, version);
                }
                if (useReferenceName && symbolTable2.GetAllSymbolInfos().IsEmpty() &&
                    name.IndexOfAny(FileSystemDefinition.InvalidPathChars) == -1)
                {
                    var symbolTable3 = new SymbolTable(psiServices);
                    try
                    {
                        bool hasExtension = Path.HasExtension(name);

                        foreach (string location in mvcCache.GetLocations(project, MvcUtil.GetViewLocationType(mvcKind, tuple.A)))
                        {
                            string path = string.Format(location, name, tuple.B, tuple.A);
                            if (hasExtension)
                            {
                                path = Path.ChangeExtension(path, null);
                            }
                            symbolTable3.AddSymbol(new PathDeclaredElement(psiServices, FileSystemPath.Parse(path)));
                        }
                    }
                    catch (InvalidPathException)
                    {
                    }
                    symbolTable2 = symbolTable3;
                }
                symbolTable = symbolTable.Merge(symbolTable2);
            }

            return(symbolTable.Distinct());
        }
Esempio n. 5
0
        private ISymbolTable CreatePathSymbolTable()
        {
            IList <IDeclaredElement> pathDeclaredElements = new List <IDeclaredElement>();
            var child = Paths as ITreeNode;

            if (child != null)
            {
                child = child.FirstChild;
                while (child != null)
                {
                    var pathDeclaration = child as PathDeclaration;
                    if (pathDeclaration != null)
                    {
                        pathDeclaredElements.Add(pathDeclaration);
                    }
                    child = child.NextSibling;
                }
            }

            myPathSymbolTable = ResolveUtil.CreateSymbolTable(pathDeclaredElements, 0);
            myPathSymbolTable = myPathSymbolTable.Merge(FileRuleSymbolTable);

            return(myPathSymbolTable);
        }
        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));
        }
Esempio n. 7
0
    private ISymbolTable CreatePathSymbolTable()
    {
      IList<IDeclaredElement> pathDeclaredElements = new List<IDeclaredElement>();
      var child = Paths as ITreeNode;
      if (child != null)
      {
        child = child.FirstChild;
        while (child != null)
        {
          var pathDeclaration = child as PathDeclaration;
          if (pathDeclaration != null)
          {
            pathDeclaredElements.Add(pathDeclaration);
          }
          child = child.NextSibling;
        }
      }

      myPathSymbolTable = ResolveUtil.CreateSymbolTable(pathDeclaredElements, 0);
      myPathSymbolTable = myPathSymbolTable.Merge(FileRuleSymbolTable);

      return myPathSymbolTable;
    }
Esempio n. 8
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));
        }