Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SearchCollector.cs « MonoDevelop.Ide.FindInFiles « MonoDevelop.Ide « core « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 053d55449f4ca02b9e0e1deea9bde2957adfbb8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//// 
//// SearchCollector.cs
////  
//// Author:
////       Mansheng Yang <lightyang0@gmail.com>
//// 
//// Copyright (c) 2012 Mansheng Yang
//// 
//// Permission is hereby granted, free of charge, to any person obtaining a copy
//// of this software and associated documentation files (the "Software"), to deal
//// in the Software without restriction, including without limitation the rights
//// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//// copies of the Software, and to permit persons to whom the Software is
//// furnished to do so, subject to the following conditions:
//// 
//// The above copyright notice and this permission notice shall be included in
//// all copies or substantial portions of the Software.
//// 
//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//// THE SOFTWARE.
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using ICSharpCode.NRefactory.TypeSystem;
//using MonoDevelop.Core;
//using MonoDevelop.Projects;
//using MonoDevelop.Ide.TypeSystem;
//
//namespace MonoDevelop.Ide.FindInFiles
//{
//	public class SearchCollector
//	{
//		
//		public class FileList
//		{
//			public Project Project
//			{
//				get;
//				private set;
//			}
//
//			public IProjectContent Content
//			{
//				get;
//				private set;
//			}
//
//			public IEnumerable<FilePath> Files
//			{
//				get;
//				private set;
//			}
//
//			public FileList (Project project, IProjectContent content, IEnumerable<FilePath> files)
//			{
//				Project = project;
//				Content = content;
//				Files = files;
//			}
//		}
//
//		public static IEnumerable<Project> CollectProjects (Solution solution, IEnumerable<object> entities)
//		{
//			return new SearchCollector (solution, null, entities).CollectProjects ();
//		}
//
//		public static IEnumerable<FileList> CollectFiles (Project project, IEnumerable<object> entities)
//		{
//			return new SearchCollector (project.ParentSolution, project, entities).CollectFiles ();
//		}
//
//		public static IEnumerable<FileList> CollectFiles (Solution solution, IEnumerable<object> entities)
//		{
//			return new SearchCollector (solution, null, entities).CollectFiles ();
//		}
//		
//		static IEnumerable<Project> GetAllReferencingProjects (Solution solution, string assemblyName)
//		{
//			return solution.GetAllProjects ().Where (
//				project => TypeSystemService.GetCompilation (project).Assemblies.Any (a => a.AssemblyName == assemblyName));
//		}
//
//		static FileList CollectDeclaringFiles (IEntity entity, IEnumerable<string> fileNames)
//		{
//			var project = TypeSystemService.GetProject (entity);
//			var paths = fileNames.Distinct().Select (p => (FilePath)p);
// 			return new SearchCollector.FileList (project, TypeSystemService.GetProjectContext (project), paths);
//		}
//		
//		public static FileList CollectDeclaringFiles (IEntity entity)
//		{
//			if (entity is ITypeDefinition)
//				return CollectDeclaringFiles (entity, (entity as ITypeDefinition).Parts.Select (p => p.Region.FileName));
//			if (entity is IMethod)
//				return CollectDeclaringFiles (entity, (entity as IMethod).Parts.Select (p => p.Region.FileName));
//			return CollectDeclaringFiles (entity, new [] { entity.Region.FileName });
//		}
//		
//		Project searchProject;
//		bool searchProjectAdded; // if the searchProject is added, we can stop collecting
//		Solution solution;
//		IEnumerable<object> entities;
//		bool projectOnly; // only collect projects
//		
//		IDictionary<Project, ISet<string>> collectedFiles = new Dictionary<Project, ISet<string>> ();
//		ISet<Project> collectedProjects = new HashSet<Project> ();
//		
//		ISet<string> searchedAssemblies = new HashSet<string> ();
//		ISet<Project> searchedProjects = new HashSet<Project> ();
//
//		/// <param name="searchProject">the project to search. use to null to search the whole solution</param>
//		SearchCollector (Solution solution, Project searchProject, IEnumerable<object> entities)
//		{
//			this.solution = solution;
//			this.searchProject = searchProject;
//			this.entities = entities;
//		}
//
//		IEnumerable<Project> CollectProjects ()
//		{
//			projectOnly = true;
//			foreach (var o in entities) {
//				var entity = o as IEntity;
//				if (entity != null) {
//					Collect (TypeSystemService.GetProject (entity), entity);
//					continue;
//				}
//				var par = o as IParameter;
//				if (par != null) {
//					Collect (TypeSystemService.GetProject (par.Owner), par.Owner);
//					continue;
//				}
//			}
//			return collectedProjects;
//		}
//
//		IEnumerable<FileList> CollectFiles ()
//		{
//			projectOnly = false;
//			foreach (var o in entities) {
//				if (o is INamespace) {
//					Collect (null, null);
//					continue;
//				}
//
//				var par = o as IParameter;
//				if (par != null) {
//					if (par.Owner != null) {
//						Collect (TypeSystemService.GetProject (par.Owner), par.Owner);
//					} else {
//						Collect (IdeApp.Workbench.ActiveDocument.Project, null);
//					}
//				} else {
//					var entity = o as IEntity;
//					if (entity == null)
//						continue;
//					Collect (TypeSystemService.GetProject (entity), entity);
//				}
//
//				if (searchProjectAdded) break;
//			}
//			foreach (var project in collectedProjects)
//				yield return new FileList (project, TypeSystemService.GetProjectContext (project), project.Files.Where (f => f.BuildAction == BuildAction.Compile).Select (f => f.FilePath));
//			
//			foreach (var files in collectedFiles)
//				yield return new FileList (files.Key, TypeSystemService.GetProjectContext (files.Key), files.Value.Select (f => (FilePath)f));
//		}
//
//		void AddProject (Project project)
//		{
//			if (project == null)
//				throw new ArgumentNullException ("project");
//
//			searchProjectAdded = (project == searchProject);
//
//			// remove duplicate files
//			if (collectedProjects.Add (project)) 
//				collectedFiles.Remove (project);
//		}
//
//		void AddFiles (Project project, IEnumerable<string> files)
//		{
//			if (project == null)
//				throw new ArgumentNullException ("project");
//
//			if (collectedProjects.Contains (project))
//				return;
//
//			ISet<string> fileSet;
//			if (!collectedFiles.TryGetValue (project, out fileSet)) {
//				fileSet = new HashSet<string> ();
//				collectedFiles[project] = fileSet;
//			}
//
//			foreach (var file in files)
//				fileSet.Add (file);
//		}
//
//		void Collect (Project sourceProject, IEntity entity, bool searchInProject = false)
//		{
//			if (searchedProjects.Contains(sourceProject))
//				return;
//			
//			if (searchProject != null && sourceProject != searchProject) {
//				// searching for a entity not defined in the project
//				AddProject (searchProject);
//				return;
//			}
//			
//			if (sourceProject == null) {
//				if (entity == null) {
//					foreach (var project in solution.GetAllProjects ())
//						AddProject (project);
//					return;
//				}
//				// entity is defined in a referenced assembly
//				var assemblyName = entity.ParentAssembly.AssemblyName;
//				if (!searchedAssemblies.Add (assemblyName)) 
//					return;
//				foreach (var project in GetAllReferencingProjects (solution, assemblyName))
//					AddProject (project);
//
//				return;
//			}
//
//			if (entity == null) {
//				AddProject (sourceProject);
//				return;
//			}
//
//			var declaringType = entity.DeclaringTypeDefinition;
//			// TODO: possible optimization for protected
//			switch (entity.Accessibility) {
//			case Accessibility.Public:
//			case Accessibility.Protected:
//			case Accessibility.ProtectedOrInternal:
//			case Accessibility.Internal:
//			case Accessibility.ProtectedAndInternal:
//
//				if (declaringType != null)
//					Collect (sourceProject, entity.DeclaringTypeDefinition, searchInProject);
//				else if (searchProject != null || searchInProject)
//					AddProject (sourceProject);
//				else {
//					foreach (var project in ReferenceFinder.GetAllReferencingProjects (solution, sourceProject)) {
//						if (entity.Accessibility == Accessibility.Internal || entity.Accessibility == Accessibility.ProtectedAndInternal) {
//							var wrapper = TypeSystemService.GetProjectContentWrapper (project);
//							if (wrapper == null)
//								continue;
//							if (!entity.ParentAssembly.InternalsVisibleTo (wrapper.Compilation.MainAssembly))
//								continue;
//						}
//						AddProject (project);
//					}
//				}
//				break;
//			default: // private
//				if (projectOnly)
//					AddProject (sourceProject);
//				else if (declaringType != null)
//					AddFiles (sourceProject, declaringType.Parts.Select (p => p.Region.FileName));
//				break;
//			}
//		}
//	}
//}
//