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

ReferencesFinder.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: c69477eb132c7bfc2cc76ee7bba50603a0ca8f36 (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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//// 
//// ReferenceFinder.cs
////  
//// Author:
////       Mike Krüger <mkrueger@novell.com>
//// 
//// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
//// 
//// 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 Mono.Addins;
//using MonoDevelop.Core;
//using MonoDevelop.Projects;
//using ICSharpCode.NRefactory.TypeSystem;
//using MonoDevelop.Ide.TypeSystem;
//using System.Threading.Tasks;
//
//namespace MonoDevelop.Ide.FindInFiles
//{
//	public abstract class ReferenceFinder
//	{
//		public bool IncludeDocumentation {
//			get;
//			set;
//		}
//		
//		/*
//		Project project;
//		protected Project Project {
//			get {
//				if (project == null)
//					project = Content.GetProject ();
//				return project;
//			}
//		}*/
//		
//		static List<ReferenceFinderCodon> referenceFinderCodons = new List<ReferenceFinderCodon> ();
//		
//		static ReferenceFinder ()
//		{
//			AddinManager.AddExtensionNodeHandler ("/MonoDevelop/Ide/ReferenceFinder", delegate(object sender, ExtensionNodeEventArgs args) {
//				var codon = (ReferenceFinderCodon)args.ExtensionNode;
//				switch (args.Change) {
//				case ExtensionChange.Add:
//					referenceFinderCodons.Add (codon);
//					break;
//				case ExtensionChange.Remove:
//					referenceFinderCodons.Remove (codon);
//					break;
//				}
//			});
//		}
//		
//		static ReferenceFinder GetReferenceFinder (string mimeType)
//		{
//			var codon = referenceFinderCodons.FirstOrDefault (c => c.SupportedMimeTypes.Any (mt => mt == mimeType));
//			return codon != null ? codon.CreateFinder () : null;
//		}
//		
//		public static IEnumerable<MemberReference> FindReferences (object member, bool searchForAllOverloads, IProgressMonitor monitor = null)
//		{
//			return FindReferences (IdeApp.ProjectOperations.CurrentSelectedSolution, member, searchForAllOverloads, RefactoryScope.Unknown, monitor);
//		}
//
//		public static IEnumerable<MemberReference> FindReferences (object member, bool searchForAllOverloads, RefactoryScope scope, IProgressMonitor monitor = null)
//		{
//			return FindReferences (IdeApp.ProjectOperations.CurrentSelectedSolution, member, searchForAllOverloads, scope, monitor);
//		}
//		
//		static SearchCollector.FileList GetFileList (string fileName)
//		{
//			var doc = IdeApp.Workbench.GetDocument (fileName);
//			if (doc != null)
//				return new SearchCollector.FileList (doc.Project, null, new [] { (FilePath)fileName });
//			return null;
//		}
//
//		static IEnumerable<SearchCollector.FileList> GetFileNames (Solution solution, object node, RefactoryScope scope, 
//		                                                           IProgressMonitor monitor, IEnumerable<object> searchNodes)
//		{
//			if (!(node is IField) && !(node is IParameter) && node is IVariable || scope == RefactoryScope.File) {
//				string fileName;
//				if (node is IEntity) {
//					fileName = ((IEntity)node).Region.FileName;
//				} else if (node is ITypeParameter) {
//					fileName = ((ITypeParameter)node).Region.FileName;
//				} else {
//					fileName = ((IVariable)node).Region.FileName;
//				}
//				var fileList =  GetFileList (fileName);
//				if (fileList != null)
//					yield return fileList;
//				yield break;
//			}
//			
//			if (node is ITypeParameter) {
//				var typeParameter = node as ITypeParameter;
//				if (typeParameter.Owner != null) {
//					yield return SearchCollector.CollectDeclaringFiles (typeParameter.Owner);
//					yield break;
//				}
//				var fileList =  GetFileList (typeParameter.Region.FileName);
//				if (fileList != null)
//					yield return fileList;
//				yield break;
//			}
//			var par = node as IParameter;
//			if (par != null) {
//				node = par.Owner;
//			}
//
//			var compilationProvider = (ICompilationProvider)node;
//			switch (scope) {
//			case RefactoryScope.DeclaringType:
//				var entity = (IEntity)compilationProvider;
//				if (entity.DeclaringTypeDefinition != null)
//					yield return SearchCollector.CollectDeclaringFiles (entity.DeclaringTypeDefinition);
//				else
//					yield return SearchCollector.CollectDeclaringFiles (entity);
//				break;
//			case RefactoryScope.Project:
//				var sourceProject = TypeSystemService.GetProject (compilationProvider.Compilation.MainAssembly.UnresolvedAssembly.Location);
//				foreach (var file in SearchCollector.CollectFiles (sourceProject, searchNodes))
//					yield return file;
//				break;
//			default:
//				var files = SearchCollector.CollectFiles (solution, searchNodes).ToList ();
//				if (monitor != null)
//					monitor.BeginTask (GettextCatalog.GetString ("Searching for references in solution..."), files.Count);
//				foreach (var file in files) {
//					if (monitor != null && monitor.IsCancelRequested)
//						yield break;
//					yield return file;
//					if (monitor != null)
//						monitor.Step (1);
//				}
//				if (monitor != null)
//					monitor.EndTask ();
//				break;
//			}
//		}
//		
//		public static List<Project> GetAllReferencingProjects (Solution solution, Project sourceProject)
//		{
//			var projects = new List<Project> ();
//			projects.Add (sourceProject);
//			foreach (var project in solution.GetAllProjects ()) {
//				if (project.GetReferencedItems (ConfigurationSelector.Default).Any (prj => prj == sourceProject))
//					projects.Add (project);
//			}
//			return projects;
//		}
//
//		public static IEnumerable<MemberReference> FindReferences (Solution solution, object member, bool searchForAllOverloads, RefactoryScope scope = RefactoryScope.Unknown, IProgressMonitor monitor = null)
//		{
//			yield break;
//
////			if (member == null)
////				yield break;
////			if (solution == null && member is IEntity) {
////				var project = TypeSystemService.GetProject ((member as IEntity).Compilation.MainAssembly.UnresolvedAssembly.Location);
////				if (project == null)
////					yield break;
////				solution = project.ParentSolution;
////			}
////			
////			IList<object> searchNodes = new [] { member };
////			if (member is ITypeParameter) {
////				// nothing
////			} else if (member is IType) {
////				searchNodes = CollectMembers ((IType)member).ToList<object> ();
////			} else if (member is IEntity) {
////				var e = (IEntity)member;
////				if (e.SymbolKind == SymbolKind.Destructor) {
////					foreach (var r in FindReferences (solution, e.DeclaringType, searchForAllOverloads, scope, monitor)) {
////						yield return r;
////					}
////					yield break;
////				}
////				if (member is IMember)
////					searchNodes = CollectMembers (solution, (IMember)member, scope, searchForAllOverloads).ToList<object> ();
////			}
////			// prepare references finder
////			var preparedFinders = new List<Tuple<ReferenceFinder, Project, IProjectContent, List<FilePath>>> ();
////			var curList = new List<FilePath> ();
////			int totalFiles = 0;
////			foreach (var info in GetFileNames (solution, member, scope, monitor, searchNodes)) {
////				string oldMime = null;
////				foreach (var file in info.Files) {
////					if (monitor != null && monitor.IsCancelRequested)
////						yield break;
////					
////					string mime = DesktopService.GetMimeTypeForUri (file);
////					if (mime != oldMime) {
////						var finder = GetReferenceFinder (mime);
////						if (finder == null)
////							continue;
////						
////						oldMime = mime;
////						
////						curList = new List<FilePath> ();
////						preparedFinders.Add (Tuple.Create (finder, info.Project, info.Content, curList));
////					}
////					curList.Add (file);
////					totalFiles++;
////				}
////			}
////			
////			// execute search
////			if (monitor != null)
////				monitor.BeginTask (GettextCatalog.GetString ("Analyzing files..."), totalFiles);
////			var foundOccurrences = new HashSet<Tuple<string, DomRegion>> ();
////			foreach (var tuple in preparedFinders) {
////				var finder = tuple.Item1;
////				foreach (var foundReference in finder.FindReferences (tuple.Item2, tuple.Item3, tuple.Item4, monitor, searchNodes)) {
////					if (monitor != null && monitor.IsCancelRequested)
////						yield break;
////					var tag = Tuple.Create (foundReference.FileName, foundReference.Region);
////					if (foundOccurrences.Contains (tag))
////						continue;
////					foundOccurrences.Add (tag);
////					yield return foundReference;
////				}
////			}
////			if (monitor != null)
////				monitor.EndTask ();
//		}
//
//		public abstract IEnumerable<MemberReference> FindReferences (Project project, IProjectContent content, IEnumerable<FilePath> files, IProgressMonitor monitor, IEnumerable<object> searchedMembers);
//
//		internal static IEnumerable<IMember> CollectMembers (Solution solution, IMember member, RefactoryScope scope, bool includeOverloads = true)
//		{
//			return MemberCollector.CollectMembers (solution, member, scope, includeOverloads);
//		}
//		
//		internal static IEnumerable<IEntity> CollectMembers (IType type)
//		{
//			var typeDefinition = type.GetDefinition ();
//			if (typeDefinition == null)
//				yield break;
//			yield return (IEntity)typeDefinition;
//			foreach (var c in typeDefinition.GetMembers (m => m.SymbolKind == SymbolKind.Constructor, GetMemberOptions.IgnoreInheritedMembers)) {
//				if (!c.IsSynthetic)
//					yield return c;
//			}
//
//			foreach (var m in type.GetMethods (m  => m.IsDestructor, GetMemberOptions.IgnoreInheritedMembers)) {
//				yield return m;
//			}
//		}
//
//
//		public enum RefactoryScope{ Unknown, File, DeclaringType, Solution, Project}
////		static RefactoryScope GetScope (object o)
////		{
////			IEntity node = o as IEntity;
////			if (node == null)
////				return RefactoryScope.File;
////			
////			// TODO: RefactoringsScope.Hierarchy
////			switch (node.Accessibility) {
////			case Accessibility.Public:
////			case Accessibility.Protected:
////			case Accessibility.ProtectedOrInternal:
////				if (node.DeclaringTypeDefinition != null) {
////					var scope = GetScope (node.DeclaringTypeDefinition);
////					if (scope != RefactoryScope.Solution)
////						return RefactoryScope.Project;
////				}
////				return RefactoryScope.Solution;
////			case Accessibility.Internal:
////			case Accessibility.ProtectedAndInternal:
////				return RefactoryScope.Project;
////			}
////			return RefactoryScope.DeclaringType;
////		}
//	}
//	
//	[ExtensionNode (Description="A reference finder. The specified class needs to inherit from MonoDevelop.Projects.CodeGeneration.ReferenceFinder")]
//	internal class ReferenceFinderCodon : TypeExtensionNode
//	{
//		[NodeAttribute("supportedmimetypes", "Mime types supported by this binding (to be shown in the Open File dialog)")]
//		string[] supportedMimetypes;
//		
//		public string[] SupportedMimeTypes {
//			get {
//				return supportedMimetypes;
//			}
//			set {
//				supportedMimetypes = value;
//			}
//		}
//		
//		public ReferenceFinder CreateFinder ()
//		{
//			return (ReferenceFinder)CreateInstance ();
//		}
//		
//		public override string ToString ()
//		{
//			return string.Format ("[ReferenceFinderCodon: SupportedMimeTypes={0}]", SupportedMimeTypes);
//		}
//	}
//}