Exemplo n.º 1
0
        public static void FindAllReferences(SymbolDefinition symbol, string localAssetPath)
        {
            if (symbol.kind == SymbolKind.Accessor || symbol.kind == SymbolKind.Constructor || symbol.kind == SymbolKind.Destructor)
            {
                symbol = symbol.parentSymbol;
            }
            if (symbol == null)
            {
                return;
            }

            symbol = symbol.GetGenericSymbol();

            var candidates = FindReferenceCandidates(symbol, localAssetPath);

            var searchOptions = new FindResultsWindow.SearchOptions {
                text      = symbol.name,
                matchWord = true,
                matchCase = true,
            };

            var candidateGuids = new string[candidates.Count];

            for (int i = 0; i < candidates.Count; i++)
            {
                candidateGuids[i] = AssetDatabase.AssetPathToGUID(candidates[i]);
            }

            var searchForVarRefs = symbol is TypeDefinitionBase && symbol.kind != SymbolKind.Delegate;

            if (searchForVarRefs)
            {
                searchOptions.altText1 = "var";

                var builtInTypesEnumerator = SymbolDefinition.builtInTypes.GetEnumerator();
                for (var i = 0; i < 16; i++)
                {
                    builtInTypesEnumerator.MoveNext();
                    var type = builtInTypesEnumerator.Current.Value;
                    if (type == symbol)
                    {
                        searchOptions.altText2 = builtInTypesEnumerator.Current.Key;
                        break;
                    }
                }
            }

            FindResultsWindow resultsWindow = FindResultsWindow.Create(
                "References to " + symbol.FullName,
                FindAllInSingleFile,
                candidateGuids,
                searchOptions,
                "References");

            resultsWindow.SetFilesValidator(ValidateFileForReferences);
            resultsWindow.SetResultsValidator(ValidateResultAsReference, symbol);
        }