Exemplo n.º 1
0
    public static Dictionary <string, string[]> FindAllFolderDependent(string path, string dstAssetPath)
    {
        string[] assetPathsFromFolder            = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
        string   assetPath                       = "";
        Dictionary <string, string[]> tempRefDic = new Dictionary <string, string[]>();

        foreach (var tempPath in assetPathsFromFolder)
        {
            if (!tempPath.EndsWith(".meta"))
            {
                assetPath = FindReferences.GetRelativeAssetsPath(tempPath);
                string[]      a          = GetAssetDependencies(assetPath);
                List <string> filterPath = new List <string>();

                /* for (int j = 0; j < a.Length; j++)
                 * {
                 *   //过滤掉本身目录,过滤掉.shader .cs
                 *   if (a[j].Contains(dstAssetPath) || a[j].Contains(".cs") || a[j].Contains(".shader"))
                 *   {
                 *   }
                 *   else
                 *   {
                 *       filterPath.Add(a[j]);
                 *   }
                 * }
                 * if (filterPath.Count != 0)
                 * {
                 *   tempRefDic.Add(assetPath, filterPath.ToArray());
                 * }*/
                tempRefDic.Add(assetPath, a);
            }
        }

        return(tempRefDic);
    }
Exemplo n.º 2
0
            void FindIssuesInNode(AstNode anchor, AstNode node, string accessorName = "setter")
            {
                if (node == null || node.IsNull)
                {
                    return;
                }
                var localResolveResult = context.GetResolverStateBefore(node)
                                         .LookupSimpleNameOrTypeName("value", new List <IType>(), NameLookupMode.Expression) as LocalResolveResult;

                if (localResolveResult == null)
                {
                    return;
                }

                var  variable       = localResolveResult.Variable;
                bool referenceFound = false;
                var  findRef        = new FindReferences();
                var  syntaxTree     = (SyntaxTree)context.RootNode;

                findRef.FindLocalReferences(variable, context.UnresolvedFile, syntaxTree, context.Compilation, (n, entity) => {
                    if (n.StartLocation >= node.StartLocation && n.EndLocation <= node.EndLocation)
                    {
                        referenceFound = true;
                    }
                }, CancellationToken.None);

                if (!referenceFound)
                {
                    AddIssue(anchor, context.TranslateString("The " + accessorName + " does not use the 'value' parameter"));
                }
            }
Exemplo n.º 3
0
        bool HasDependency(RefactoringContext context, AstNode firstSearchNode, AstNode targetNode)
        {
            var referenceFinder = new FindReferences();
            var identifiers     = targetNode.Descendants
                                  .Where(n => n is IdentifierExpression)
                                  .Select <AstNode, IdentifierExpression>(node => (IdentifierExpression)node);

            foreach (var identifier in identifiers)
            {
                var resolveResult      = context.Resolve(identifier);
                var localResolveResult = resolveResult as LocalResolveResult;
                if (localResolveResult == null)
                {
                    continue;
                }
                bool referenceFound = false;
//				var variable = localResolveResult.Variable;
                var syntaxTree = context.RootNode as SyntaxTree;
                referenceFinder.FindLocalReferences(localResolveResult.Variable, context.UnresolvedFile, syntaxTree,
                                                    context.Compilation, (node, nodeResolveResult) => {
                    if (node.StartLocation > firstSearchNode.StartLocation && node.EndLocation < targetNode.StartLocation)
                    {
                        referenceFound = true;
                    }
                }, CancellationToken.None);
                if (referenceFound)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        void FindReferencesButtonClick(object sender, EventArgs e)
        {
            if (csharpTreeView.SelectedNode == null)
            {
                return;
            }

            SimpleProjectContent project = new SimpleProjectContent();
            var parsedFile = new TypeSystemConvertVisitor(project, "dummy.cs").Convert(compilationUnit);

            project.UpdateProjectContent(null, parsedFile);

            List <ITypeResolveContext> projects = new List <ITypeResolveContext>();

            projects.Add(project);
            projects.AddRange(builtInLibs.Value);

            using (var context = new CompositeTypeResolveContext(projects).Synchronize()) {
                CSharpResolver resolver = new CSharpResolver(context);

                AstNode node = (AstNode)csharpTreeView.SelectedNode.Tag;
                IResolveVisitorNavigator navigator = new NodeListResolveVisitorNavigator(new[] { node });
                ResolveVisitor           visitor   = new ResolveVisitor(resolver, parsedFile, navigator);
                visitor.Scan(compilationUnit);
                IEntity             entity;
                MemberResolveResult mrr = visitor.GetResolveResult(node) as MemberResolveResult;
                TypeResolveResult   trr = visitor.GetResolveResult(node) as TypeResolveResult;
                if (mrr != null)
                {
                    entity = mrr.Member;
                }
                else if (trr != null)
                {
                    entity = trr.Type.GetDefinition();
                }
                else
                {
                    return;
                }

                FindReferences         fr             = new FindReferences();
                int                    referenceCount = 0;
                FoundReferenceCallback callback       = delegate(AstNode matchNode, ResolveResult result) {
                    referenceCount++;
                };

                var searchScopes = fr.GetSearchScopes(entity);
                navigator = new CompositeResolveVisitorNavigator(searchScopes.Select(s => s.GetNavigator(callback)).ToArray());
                visitor   = new ResolveVisitor(resolver, parsedFile, navigator);
                visitor.Scan(compilationUnit);

                csharpTreeView.BeginUpdate();
                ShowResolveResultsInTree(csharpTreeView.Nodes, visitor);
                csharpTreeView.EndUpdate();

                MessageBox.Show("Found " + referenceCount + " references to " + entity.FullName);
            }
        }
Exemplo n.º 5
0
    //可视化使用
    public static void FindFolderDependentByArtToolsWindow(string path)
    {
        string dstAssetPath = FindReferences.GetRelativeAssetsPath(path);

        refDic = FindAllFolderDependent(path, dstAssetPath);
        Finddependent window = (Finddependent)EditorWindow.GetWindow(typeof(Finddependent));

        window.Show();
    }
    public ILPostProcessCompiledAssembly(ScriptAssembly scriptAssembly, string outputPath, FindReferences findReferences)
    {
        m_ScriptAssembly = scriptAssembly;
        Name             = Path.GetFileNameWithoutExtension(scriptAssembly.Filename);
        References       = scriptAssembly.GetAllReferences().Select(Path.GetFileName).ToArray();

        m_OutputPath     = outputPath;
        m_FindReferences = findReferences;
    }
Exemplo n.º 7
0
        public override void RenameTypeParameter(IType type, string name = null)
        {
            FindReferences refFinder = new FindReferences();

            refFinder.FindTypeParameterReferences(type,
                                                  _context.UnresolvedFile,
                                                  _context.RootNode as SyntaxTree,
                                                  _context.Compilation, (n, r) => Rename(n, name),
                                                  _context.CancellationToken);
        }
Exemplo n.º 8
0
            void Rename(IVariable variable, string name)
            {
                FindReferences refFinder = new FindReferences();

                refFinder.FindLocalReferences(variable,
                                              context.UnresolvedFile,
                                              context.RootNode as SyntaxTree,
                                              context.Compilation, (n, r) => Rename(n, name),
                                              context.CancellationToken);
            }
Exemplo n.º 9
0
        public override void Rename(ISymbol symbol, string name = null)
        {
            FindReferences refFinder = new FindReferences();

            refFinder.FindReferencesInFile(refFinder.GetSearchScopes(symbol),
                                           _context.UnresolvedFile,
                                           _context.RootNode as SyntaxTree,
                                           _context.Compilation, (n, r) => Rename(n, name),
                                           _context.CancellationToken);
        }
Exemplo n.º 10
0
            public override void Rename(IEntity entity, string name)
            {
                FindReferences refFinder = new FindReferences();

                refFinder.FindReferencesInFile(refFinder.GetSearchScopes(entity),
                                               context.UnresolvedFile,
                                               context.RootNode as SyntaxTree,
                                               context.Compilation, (n, r) => Rename(n, name),
                                               context.CancellationToken);
            }
            public override void RenameTypeParameter(IType type, string name = null)
            {
                FindReferences refFinder = new FindReferences();

                refFinder.FindTypeParameterReferences(type,
                                                      context.ParsedFile,
                                                      context.RootNode as CompilationUnit,
                                                      context.Compilation, (n, r) => Rename(n, name),
                                                      context.CancellationToken);
            }
            public override void Rename(IVariable variable, string name)
            {
                FindReferences refFinder = new FindReferences();

                refFinder.FindLocalReferences(variable,
                                              context.ParsedFile,
                                              context.RootNode as CompilationUnit,
                                              context.Compilation, (n, r) => Rename(n, name),
                                              context.CancellationToken);
            }
Exemplo n.º 13
0
 static void FindObjects()
 {
     if (null != Selection.activeObject)
     {
         FindReferences window = GetWindow <FindReferences>();
         window.Show();
         window.title          = "Find References";
         window.selectedObject = Selection.activeObject;
         SetReferenceList();
     }
 }
		bool IsReferenced(IVariable variable, AstNode node, SyntaxTree syntaxTree, RefactoringContext context)
		{
			int referencesFound = 0;
			var findRef = new FindReferences();
			findRef.FindLocalReferences(variable, context.UnresolvedFile, syntaxTree, context.Compilation, (n, entity) => {
				referencesFound++;
			}, CancellationToken.None);

			// One reference is the declaration, and that does not count
			return referencesFound > 1;
		}
Exemplo n.º 15
0
        bool HasDependencyCheck(FindReferences referenceFinder, LocalResolveResult localResolveResult)
        {
            bool result = false;

            referenceFinder.FindLocalReferences(localResolveResult.Variable, context.UnresolvedFile,
                                                (SyntaxTree)context.RootNode, context.Compilation,
                                                (node, resolveResult) => {
                result |= VariableHasBeenConverted(localResolveResult.Variable);
            }, CancellationToken.None);
            return(result);
        }
Exemplo n.º 16
0
 static private void OutputUnuse(Dictionary <string, System.Collections.Generic.List <string> > refDic)
 {
     if (showWin)
     {
         FindReferences window = (FindReferences)EditorWindow.GetWindow(typeof(FindReferences));
         window.Show();
     }
     else
     {
         OutputToExcel();
     }
 }
Exemplo n.º 17
0
 private void findReferences_Click(object sender, EventArgs e)
 {
     if (findReferencesForm == null)
     {
         findReferencesForm       = new FindReferences(new FindReferencesFunction(FindReferences), null);
         findReferencesForm.Owner = this;
     }
     else
     {
         findReferencesForm.Reload();
     }
     findReferencesForm.Show();
 }
Exemplo n.º 18
0
        private void FindReferencesButtonClick(object sender, EventArgs e)
        {
            if (csharpTreeView.SelectedNode == null)
            {
                return;
            }

            IProjectContent project        = new CSharpProjectContent();
            var             unresolvedFile = _syntaxTree.ToTypeSystem();

            project = project.AddOrUpdateFiles(unresolvedFile);
            project = project.AddAssemblyReferences(_builtInLibs.Value);

            ICompilation      compilation = project.CreateCompilation();
            CSharpAstResolver resolver    = new CSharpAstResolver(compilation, _syntaxTree, unresolvedFile);

            AstNode             node = (AstNode)csharpTreeView.SelectedNode.Tag;
            IEntity             entity;
            MemberResolveResult mrr = resolver.Resolve(node) as MemberResolveResult;
            TypeResolveResult   trr = resolver.Resolve(node) as TypeResolveResult;

            if (mrr != null)
            {
                entity = mrr.Member;
            }
            else if (trr != null)
            {
                entity = trr.Type.GetDefinition();
            }
            else
            {
                return;
            }

            FindReferences         fr             = new FindReferences();
            int                    referenceCount = 0;
            FoundReferenceCallback callback       = delegate(AstNode matchNode, ResolveResult result)
            {
                Debug.WriteLine(matchNode.StartLocation + " - " + matchNode + " - " + result);
                referenceCount++;
            };

            var searchScopes = fr.GetSearchScopes(entity);

            Debug.WriteLine("Find references to " + entity.ReflectionName);
            fr.FindReferencesInFile(searchScopes, unresolvedFile, _syntaxTree, compilation, callback, CancellationToken.None);

            MessageBox.Show("Found " + referenceCount + " references to " + entity.FullName);
        }
Exemplo n.º 19
0
        private List <AstNode> GetResolvedNodes(ResolveResultType type, AstNode node)
        {
            var           resolvedNodes = new List <AstNode>();
            ResolveResult resolveResult = _resolver.Resolve(node);

            if (resolveResult != null)
            {
                var findReferences = new FindReferences();
                FoundReferenceCallback callback = delegate(AstNode matchNode, ResolveResult result)
                {
                    resolvedNodes.Add(matchNode);
                };

                if (type == ResolveResultType.Local)
                {
                    var localResolveResult = resolveResult as LocalResolveResult;
                    if (localResolveResult != null)
                    {
                        findReferences.FindLocalReferences(localResolveResult.Variable, _unresolvedFile, SyntaxTree, _compilation, callback, CancellationToken.None);
                    }
                }
                else if (type == ResolveResultType.Member)
                {
                    var memberResolveResult = resolveResult as MemberResolveResult;
                    if (memberResolveResult != null)
                    {
                        var searchScopes = findReferences.GetSearchScopes(memberResolveResult.Member);
                        findReferences.FindReferencesInFile(searchScopes, _unresolvedFile, SyntaxTree, _compilation, callback, CancellationToken.None);
                    }
                }
                else if (type == ResolveResultType.Type)
                {
                    var typeResolveResult = resolveResult as TypeResolveResult;
                    if (typeResolveResult != null)
                    {
                        var searchScopes = findReferences.GetSearchScopes(typeResolveResult.Type.GetDefinition());
                        findReferences.FindReferencesInFile(searchScopes, _unresolvedFile, SyntaxTree, _compilation, callback, CancellationToken.None);
                    }
                }
            }
            else
            {
            }
            return(resolvedNodes);
        }
Exemplo n.º 20
0
            void DoLocalOperationOn(TestRefactoringContext localContext, IEnumerable <IEntity> entities, Action <RefactoringContext, Script, IEnumerable <AstNode> > callback)
            {
                List <AstNode> nodes     = new List <AstNode>();
                FindReferences refFinder = new FindReferences();

                refFinder.FindCallsThroughInterface = true;
                refFinder.FindReferencesInFile(refFinder.GetSearchScopes(entities),
                                               localContext.UnresolvedFile,
                                               localContext.RootNode as SyntaxTree,
                                               localContext.Compilation,
                                               (node, result) => {
                    nodes.Add(node);
                },
                                               CancellationToken.None);

                using (var script = localContext.StartScript()) {
                    callback(localContext, script, nodes);
                }
            }
        void ColorizeMatch(AstNode node, ResolveResult result)
        {
            var          identifierNode = FindReferences.GetNodeToReplace(node);
            TextLocation start, end;

            if (identifierNode != null && !identifierNode.IsNull)
            {
                start = identifierNode.StartLocation;
                end   = identifierNode.EndLocation;
            }
            else
            {
                start = node.StartLocation;
                end   = node.EndLocation;
            }
            currentReferences.Add(new TextSegment {
                StartOffset = editor.Document.GetOffset(start),
                EndOffset   = editor.Document.GetOffset(end)
            });
        }
Exemplo n.º 22
0
    public static string[] GetAssetDependencies(string assetPath)
    {
        if (!File.Exists(assetPath))
        {
            return(null);
        }
        string dstAssetPath = FindReferences.GetRelativeAssetsPath(assetPath);

        string[]      dependecies = AssetDatabase.GetDependencies(assetPath);
        List <string> filterPath  = new List <string>();

        for (int j = 0; j < dependecies.Length; j++)
        {
            if (dependecies[j].Contains("Assets/AssetsPackage") && !dependecies[j].Contains(dstAssetPath))
            {
                filterPath.Add(dependecies[j]);
            }
        }

        dependecies = filterPath.ToArray();
        return(dependecies);
    }
Exemplo n.º 23
0
        bool HasDependencyCheck(FindReferences referenceFinder, Expression expression)
        {
            var memberReferences = from exp in expression.DescendantsAndSelf
                                   let memberReference = exp as MemberReferenceExpression
                                                         where memberReference != null
                                                         select memberReference;

            foreach (var memberReference in memberReferences)
            {
                var resolveResult = context.Resolve(memberReference) as MemberResolveResult;
                if (resolveResult == null)
                {
                    continue;
                }
                var initializerPath = AccessPath.FromResolveResult(resolveResult);
                if (initializerPath != null && accessPaths.ContainsKey(initializerPath))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 24
0
            public override void Rename(ISymbol symbol, string name)
            {
                if (symbol.SymbolKind == SymbolKind.Variable || symbol.SymbolKind == SymbolKind.Parameter)
                {
                    Rename(symbol as IVariable, name);
                    return;
                }

                FindReferences refFinder = new FindReferences();

                foreach (var fileContext in context.projectContexts)
                {
                    using (var newScript = (TestScript)fileContext.StartScript()) {
                        refFinder.FindReferencesInFile(refFinder.GetSearchScopes(symbol),
                                                       fileContext.UnresolvedFile,
                                                       fileContext.RootNode as SyntaxTree,
                                                       fileContext.Compilation,
                                                       (n, r) => newScript.Rename(n, name),
                                                       context.CancellationToken);
                    }
                }
            }
Exemplo n.º 25
0
        bool HasDependency(FindReferences referenceFinder, Expression expression)
        {
            if (HasDependencyCheck(referenceFinder, expression))
            {
                return(true);
            }
            var queue = new Queue <ResolveResult>();

            queue.Enqueue(context.Resolve(expression));
            do
            {
                var result = queue.Dequeue();
                if (result is LocalResolveResult && HasDependencyCheck(referenceFinder, (LocalResolveResult)result))
                {
                    return(true);
                }
                foreach (var childResult in result.GetChildResults())
                {
                    queue.Enqueue(childResult);
                }
            } while (queue.Count > 0);
            return(false);
        }
        IResolveVisitorNavigator InitNavigator(ICompilation compilation)
        {
            if (currentSymbolReference == null || compilation == null)
            {
                return(null);
            }
            var            symbol         = currentSymbolReference.Resolve(compilation.TypeResolveContext);
            FindReferences findReferences = new FindReferences();

            if (symbol == null)
            {
                return(null);
            }
            var searchScopes = findReferences.GetSearchScopes(symbol);

            if (searchScopes.Count == 0)
            {
                return(null);
            }
            var navigators = new IResolveVisitorNavigator[searchScopes.Count];

            for (int i = 0; i < navigators.Length; i++)
            {
                navigators[i] = searchScopes[i].GetNavigator(compilation, ColorizeMatch);
            }
            IResolveVisitorNavigator combinedNavigator;

            if (searchScopes.Count == 1)
            {
                combinedNavigator = navigators[0];
            }
            else
            {
                combinedNavigator = new CompositeResolveVisitorNavigator(navigators);
            }
            return(combinedNavigator);
        }
Exemplo n.º 27
0
    public static void FindAssetsByRG(string path)
    {
        string[] assetPathsFromFolder = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);

        System.Collections.Generic.List <string> pathList = new System.Collections.Generic.List <string>();
        foreach (var tempPath in assetPathsFromFolder)
        {
            if (!tempPath.EndsWith(".meta"))
            {
                pathList.Add(AssetDatabase.AssetPathToGUID(FindReferences.GetRelativeAssetsPath(tempPath)));
            }
        }

        if (pathList.Count < 1)
        {
            EditorUtility.DisplayDialog("提示", "请选择要查找的资源", "确定");
            return;
        }

        //string appDataPath = Path.Combine(Application.dataPath, AddressableTools.Assets_Package );
        //for(int i=0;i<pathList.Count;i++)
        //{
        //    if(i == (pathList.Count - 1))
        //    {
        //        FindReferencesInProject2.FindByRG(pathList[i],appDataPath,true,false);
        //    }
        //    else if(i == 0)
        //    {
        //        FindReferencesInProject2.FindByRG(pathList[i],appDataPath,false,true);
        //    }
        //    else
        //    {
        //        FindReferencesInProject2.FindByRG(pathList[i],appDataPath,false,false);
        //    }
        //}
    }
        private static List <AstNode> ComputeMatchNodes(RefactoringContext context, VariableInitializer firstOrNullObject)
        {
            var referenceFinder = new FindReferences();
            var matchedNodes    = new List <AstNode>();

            var resolveResult = context.Resolver.Resolve(firstOrNullObject);
            var member        = resolveResult as MemberResolveResult;

            if (member == null)//not a member is unexpected case, so is better to return no match than to break the code
            {
                return(matchedNodes);
            }

            FoundReferenceCallback callback = (matchNode, result) => matchedNodes.Add(matchNode);

            var searchScopes = referenceFinder.GetSearchScopes(member.Member);

            referenceFinder.FindReferencesInFile(searchScopes,
                                                 context.UnresolvedFile,
                                                 context.RootNode as SyntaxTree,
                                                 context.Compilation, callback,
                                                 context.CancellationToken);
            return(matchedNodes);
        }
Exemplo n.º 29
0
        void TestFindReferences(IEntity entity)
        {
            if (IgnoreEntity(entity))
            {
                return;
            }
            FindReferences fr = new FindReferences();

            fr.FindTypeReferencesEvenIfAliased = true;

            Stopwatch w            = new Stopwatch();
            var       searchScopes = fr.GetSearchScopes(entity);

            foreach (var project in solution.Projects)
            {
                w.Restart();
                HashSet <AstNode> foundReferences = new HashSet <AstNode>();
                var interestingFiles = new HashSet <CSharpFile>();
                foreach (var searchScope in searchScopes)
                {
                    foreach (var unresolvedFile in fr.GetInterestingFiles(searchScope, project.Compilation))
                    {
                        var file = project.Files.Single(f => f.FileName == unresolvedFile.FileName);
                        Debug.Assert(file.UnresolvedTypeSystemForFile == unresolvedFile);

                        // Skip file if it doesn't contain the search term
                        if (searchScope.SearchTerm != null && file.OriginalText.IndexOf(searchScope.SearchTerm, StringComparison.Ordinal) < 0)
                        {
                            continue;
                        }

                        interestingFiles.Add(file);
                    }
                }
                foreach (var file in interestingFiles)
                {
                    fr.FindReferencesInFile(searchScopes, file.UnresolvedTypeSystemForFile, file.SyntaxTree, project.Compilation,
                                            delegate(AstNode node, ResolveResult result) {
                        foundReferences.Add(node);
                    }, CancellationToken.None);
                }
                w.Stop();
                if (timings.ContainsKey(entity.SymbolKind))
                {
                    timings[entity.SymbolKind] += w.Elapsed;
                }
                else
                {
                    timings[entity.SymbolKind] = w.Elapsed;
                }


                IEntity importedEntity = project.Compilation.Import(entity);

                HashSet <AstNode> expectedReferences;
                if (importedEntity == null || !referenceDict.TryGetValue(importedEntity, out expectedReferences))
                {
                    if (foundReferences.Any())
                    {
                        // There aren't any expected references stored, but we found some references anyways:
                        Console.WriteLine();
                        Console.WriteLine("Entity not in reference dictionary: " + entity);
                    }
                    return;
                }
                if (foundReferences.Except(expectedReferences).Any())
                {
                    Console.WriteLine();
                    Console.WriteLine("Reference mismatch for " + entity + ":");
                    var n = foundReferences.Except(expectedReferences).First();
                    Console.WriteLine("Found unexpected reference " + n + " (" + n.GetRegion() + ")");
                }
                if (expectedReferences.Except(foundReferences).Any())
                {
                    Console.WriteLine();
                    Console.WriteLine("Reference mismatch for " + entity + ":");
                    var n = expectedReferences.Except(foundReferences).First();
                    Console.WriteLine("Did not find expected reference " + n + " (" + n.GetRegion() + ")");
                }
            }

            if (entityCount.ContainsKey(entity.SymbolKind))
            {
                entityCount[entity.SymbolKind]++;
            }
            else
            {
                entityCount[entity.SymbolKind] = 1;
            }
        }
Exemplo n.º 30
0
        bool HasDependency(Expression expression)
        {
            var referenceFinder = new FindReferences();

            return(HasDependency(referenceFinder, expression));
        }