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.EntityType)) {
timings[entity.EntityType] += w.Elapsed;
} else {
timings[entity.EntityType] = 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.EntityType)) {
entityCount[entity.EntityType]++;
} else {
entityCount[entity.EntityType] = 1;
}
}