private static void FindDerivedSymbols(ITypeDefinition cls, IMember member, Action <ISearchProgressMonitor, IEntity> reportFunction) { Solution currentSelectedSolution = IdeApp.ProjectOperations.CurrentSelectedSolution; if (currentSelectedSolution != null) { Project project = TypeSystemService.GetProject(cls); if (project != null) { IEnumerable <Project> referencingProjects = ReferenceFinder.GetAllReferencingProjects(currentSelectedSolution, project); if (FindDerivedSymbolsHelper._lookupFunction == null) { FindDerivedSymbolsHelper._lookupFunction = new Func <Project, ICompilation> (TypeSystemService.GetCompilation); } List <ICompilation> list = (from c in referencingProjects.Select(FindDerivedSymbolsHelper._lookupFunction) where c != null select c).ToList <ICompilation> (); Parallel.ForEach <ICompilation> (list, delegate(ICompilation comp) { try { FindDerivedSymbolsHelper.SearchCompilation(null, comp, cls, member, reportFunction); } catch (Exception ex) { LoggingService.LogInternalError(ex); } }); } } }
public static void FindDerivedClasses(ITypeDefinition cls) { var solution = IdeApp.ProjectOperations.CurrentSelectedSolution; if (solution == null) { return; } var sourceProject = TypeSystemService.GetProject(cls); if (sourceProject == null) { return; } var projects = ReferenceFinder.GetAllReferencingProjects(solution, sourceProject); ThreadPool.QueueUserWorkItem(delegate { using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true)) { var cache = new Dictionary <string, TextEditorData> (); Parallel.ForEach(projects, p => { var comp = TypeSystemService.GetCompilation(p); if (comp == null) { return; } var importedType = comp.Import(cls); if (importedType == null) { return; } foreach (var type in comp.MainAssembly.GetAllTypeDefinitions()) { if (!type.IsDerivedFrom(importedType)) { continue; } TextEditorData textFile; if (!cache.TryGetValue(type.Region.FileName, out textFile)) { cache [type.Region.FileName] = textFile = TextFileProvider.Instance.GetTextEditorData(type.Region.FileName); } int position = textFile.LocationToOffset(type.Region.BeginLine, type.Region.BeginColumn); monitor.ReportResult(new MonoDevelop.Ide.FindInFiles.SearchResult(new FileProvider(type.Region.FileName, p), position, 0)); } }); foreach (var tf in cache.Values) { if (tf.Parent == null) { tf.Dispose(); } } } }); }
static void FindDerivedSymbols(ITypeDefinition cls, IMember member) { var solution = IdeApp.ProjectOperations.CurrentSelectedSolution; if (solution == null) { return; } var sourceProject = TypeSystemService.GetProject(cls); if (sourceProject == null) { return; } var compilations = ReferenceFinder.GetAllReferencingProjects(solution, sourceProject) .Select(TypeSystemService.GetCompilation).Where(c => c != null).ToList(); using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true)) { var label = member == null ? GettextCatalog.GetString("Searching for derived classes in solution...") : GettextCatalog.GetString("Searching for derived members in solution..."); monitor.BeginTask(label, compilations.Count); Parallel.ForEach(compilations, comp => { try { SearchCompilation(monitor, comp, cls, member); } catch (Exception ex) { LoggingService.LogInternalError(ex); monitor.ReportError("Unhandled error while searching", ex); } monitor.Step(1); }); monitor.EndTask(); }; }
public static void FindDerivedClasses(ITypeDefinition cls) { var solution = IdeApp.ProjectOperations.CurrentSelectedSolution; if (solution == null) { return; } var sourceProject = TypeSystemService.GetProject(cls); if (sourceProject == null) { return; } var projects = ReferenceFinder.GetAllReferencingProjects(solution, sourceProject); ThreadPool.QueueUserWorkItem(delegate { using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true)) { var cache = new Dictionary <string, TextEditorData> (); Parallel.ForEach(projects, p => { var comp = TypeSystemService.GetCompilation(p); if (comp == null) { return; } var importedType = comp.Import(cls); if (importedType == null) { return; } foreach (var type in comp.MainAssembly.GetAllTypeDefinitions()) { if (!type.IsDerivedFrom(importedType)) { continue; } TextEditorData textFile; if (!cache.TryGetValue(type.Region.FileName, out textFile)) { cache [type.Region.FileName] = textFile = TextFileProvider.Instance.GetTextEditorData(type.Region.FileName); } int position = textFile.LocationToOffset(type.Region.Begin); string keyword; switch (type.Kind) { case TypeKind.Interface: keyword = "interface"; break; case TypeKind.Struct: keyword = "struct"; break; case TypeKind.Delegate: keyword = "delegate"; break; case TypeKind.Enum: keyword = "enum"; break; default: keyword = "class"; break; } while (position < textFile.Length - keyword.Length) { if (textFile.GetTextAt(position, keyword.Length) == keyword) { position += keyword.Length; while (position < textFile.Length && textFile.GetCharAt(position) == ' ' || textFile.GetCharAt(position) == '\t') { position++; } break; } position++; } monitor.ReportResult(new MonoDevelop.Ide.FindInFiles.SearchResult(new FileProvider(type.Region.FileName, p), position, 0)); } }); foreach (var tf in cache.Values) { if (tf.Parent == null) { tf.Dispose(); } } } }); }