private ILookup <ISourceFile, ISourceFile> ReportFailuresForCycles() { var sourceFileGraph = this.sourceFilesByUri.Values .SelectMany(sourceFile => GetModuleDeclarations(sourceFile) .Where(this.sourceFilesByModuleDeclaration.ContainsKey) .Select(moduleDeclaration => this.sourceFilesByModuleDeclaration[moduleDeclaration]) .Distinct() .Select(referencedFile => (sourceFile, referencedFile))) .ToLookup(x => x.sourceFile, x => x.referencedFile); var cycles = CycleDetector <ISourceFile> .FindCycles(sourceFileGraph); foreach (var(moduleDeclaration, moduleSourceFile) in sourceFilesByModuleDeclaration) { if (cycles.TryGetValue(moduleSourceFile, out var cycle)) { if (cycle.Length == 1) { errorBuildersByModuleDeclaration[moduleDeclaration] = x => x.CyclicModuleSelfReference(); } else { errorBuildersByModuleDeclaration[moduleDeclaration] = x => x.CyclicModule(cycle.Select(x => x.FileUri.LocalPath)); } } } return(sourceFileGraph); }
private ImmutableDictionary <DeclaredSymbol, ImmutableArray <DeclaredSymbol> > FindCycles() { var symbolGraph = declarationAccessDict .SelectMany(kvp => kvp.Value.Select(x => bindings[x]).OfType <DeclaredSymbol>().Select(x => (kvp.Key, x))) .ToLookup(x => x.Item1, x => x.Item2); return(CycleDetector <DeclaredSymbol> .FindCycles(symbolGraph)); }
private void ReportFailuresForCycles() { var syntaxTreeGraph = syntaxTrees.Values.OfType <SyntaxTree>() .SelectMany(tree => GetModuleSyntaxes(tree).Where(moduleLookup.ContainsKey).Select(x => moduleLookup[x]).Distinct().Select(x => (tree, x))) .ToLookup(x => x.Item1, x => x.Item2); var cycles = CycleDetector <SyntaxTree> .FindCycles(syntaxTreeGraph); foreach (var kvp in moduleLookup) { if (cycles.TryGetValue(kvp.Value, out var cycle)) { if (cycle.Length == 1) { moduleFailureLookup[kvp.Key] = x => x.CyclicModuleSelfReference(); } else { moduleFailureLookup[kvp.Key] = x => x.CyclicModule(cycle.Select(x => x.FileUri.LocalPath)); } } } }