public CSharpSymbolSearch(IProject project, ISymbol entity) { this.project = project; compilation = SD.ParserService.GetCompilation(project); var relatedSymbols = GetRelatedSymbols(entity); if ((relatedSymbols != null) && relatedSymbols.Any()) { searchScopes = relatedSymbols.SelectMany(e => fr.GetSearchScopes(e)).ToList(); } else { searchScopes = fr.GetSearchScopes(entity); } searchScopesPerFile = new Dictionary <string, IList <IFindReferenceSearchScope> >(); for (int i = 0; i < searchScopes.Count; i++) { var thisSearchScope = searchScopes[i]; var interestingFiles = fr.GetInterestingFiles(thisSearchScope, compilation).Select(f => f.FileName); foreach (var file in interestingFiles) { if (!searchScopesPerFile.ContainsKey(file)) { searchScopesPerFile[file] = new List <IFindReferenceSearchScope>(); } searchScopesPerFile[file].Add(thisSearchScope); workAmount++; } } workAmountInverse = 1.0 / workAmount; }
public CSharpSymbolSearch(IProject project, ISymbol entity) { this.project = project; searchScopes = fr.GetSearchScopes(entity); compilation = SD.ParserService.GetCompilation(project); interestingFileNames = new IList <string> [searchScopes.Count]; for (int i = 0; i < searchScopes.Count; i++) { interestingFileNames[i] = fr.GetInterestingFiles(searchScopes[i], compilation).Select(f => f.FileName).ToList(); workAmount += interestingFileNames[i].Count; } workAmountInverse = 1.0 / workAmount; }
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; } }