protected override void Run (object dataItem)
		{
			base.Run (dataItem);

			if (IdeApp.Workspace == null) return;
			if (IdeApp.Workbench.ActiveDocument == null || IdeApp.Workbench.ActiveDocument.FileName == FilePath.Null) return;

			var document = IdeApp.Workbench.ActiveDocument;

			ResolveResult resolveResult = null;
			object item = CurrentRefactoryOperationsHandler.GetItem (document, out resolveResult);

			IMethod method = item as IMethod;
			if (method == null)
				return;

			ISearchProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true, true);
			ThreadPool.QueueUserWorkItem((data) => 
			{
				try
				{
					ImplementationsFinder.Find(method, implementation =>
					{
						FileProvider fileProvider = new FileProvider(implementation.Region.FileName);
						TextDocument doc = new TextDocument();
						doc.Text = fileProvider.ReadString();
						int offset = doc.LocationToOffset(implementation.Region.BeginLine, implementation.Region.BeginColumn);
						while ((offset + implementation.Name.Length) < doc.TextLength)
						{
							if (doc.GetTextAt(offset, implementation.Name.Length) == implementation.Name)
							{
								break;
							}
							offset++;
						}

						monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult(fileProvider, offset, implementation.Name.Length));
					});
				}
				catch (Exception exception)
				{
					if (monitor != null)
					{
						monitor.ReportError("Error finding references", exception);
					}
					else
					{
						LoggingService.LogError("Error finding references", exception);
					}
				}
				finally
				{
					if (monitor != null)
					{
						monitor.Dispose();
					}
				}
			});
		}
Ejemplo n.º 2
0
		public IEnumerable<SearchResult> Search (FileProvider provider, string content, string pattern, FilterOptions filter)
		{
			if (string.IsNullOrEmpty (content))
				yield break;
			int idx = provider.SelectionStartPosition < 0 ? 0 : Math.Max (0, provider.SelectionStartPosition);
			var comparison = filter.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
			int end = provider.SelectionEndPosition < 0 ? content.Length : Math.Min (content.Length, provider.SelectionEndPosition);
			while ((idx = content.IndexOf (pattern, idx, end - idx, comparison)) >= 0) {
				if (!filter.WholeWordsOnly || FilterOptions.IsWholeWordAt (content, idx, pattern.Length)) {
					yield return new SearchResult (provider, idx, pattern.Length);
				}
				idx += pattern.Length;
			}
		}
Ejemplo n.º 3
0
		public void Replace (FileProvider provider, IEnumerable<SearchResult> searchResult, string replacePattern)
		{
			int delta = 0;
			foreach (var sr in searchResult) {
				provider.Replace (sr.Offset + delta, sr.Length, replacePattern);
				delta += replacePattern.Length - sr.Length;
			}
		}
Ejemplo n.º 4
0
		IEnumerable<SearchResult> FindAll (ProgressMonitor monitor, FileProvider provider, string content, string pattern, string replacePattern, FilterOptions filter)
		{
			if (string.IsNullOrEmpty (pattern))
				return Enumerable.Empty<SearchResult> ();

			if (filter.RegexSearch)
				return RegexSearch (monitor, provider, content, replacePattern, filter);

			return Search (provider, content, pattern, filter);
		}
Ejemplo n.º 5
0
		IEnumerable<SearchResult> RegexSearch (ProgressMonitor monitor, FileProvider provider, string content, string replacePattern, FilterOptions filter)
		{
			var results = new List<SearchResult> ();
			if (replacePattern == null) {
				foreach (Match match in regex.Matches (content)) {
					if (monitor.CancellationToken.IsCancellationRequested)
						break;
					if (provider.SelectionStartPosition > -1 && match.Index < provider.SelectionStartPosition)
						continue;
					if (provider.SelectionEndPosition > -1 && match.Index + match.Length > provider.SelectionEndPosition)
						continue;
					if (!filter.WholeWordsOnly || FilterOptions.IsWholeWordAt(content, match.Index, match.Length))
						results.Add(new SearchResult(provider, match.Index, match.Length));
				}
			} else {
				var matches = new List<Match> ();
				foreach (Match match in regex.Matches(content))
				{
					if (provider.SelectionStartPosition > -1 && match.Index < provider.SelectionStartPosition)
						continue;
					if (provider.SelectionEndPosition > -1 && match.Index + match.Length > provider.SelectionEndPosition)
						continue;
					matches.Add(match);
				}
				provider.BeginReplace (content);
				int delta = 0;
				for (int i = 0; !monitor.CancellationToken.IsCancellationRequested && i < matches.Count; i++) {
					Match match = matches[i];
					if (!filter.WholeWordsOnly || FilterOptions.IsWholeWordAt (content, match.Index, match.Length)) {
						string replacement = match.Result (replacePattern);
						results.Add (new SearchResult (provider, match.Index + delta, replacement.Length));
						provider.Replace (match.Index + delta, match.Length, replacement);
						delta += replacement.Length - match.Length;
					}
				}
				provider.EndReplace ();
			}
			return results;
		}
Ejemplo n.º 6
0
 public SearchResult(FileProvider fileProvider, int offset, int length)
 {
     FileProvider = fileProvider;
     Offset       = offset;
     Length       = length;
 }
		public IEnumerable<SearchResult> Search (FileProvider provider, string content, string pattern, string replacePattern, FilterOptions filter)
		{
			if (!filter.CaseSensitive) {
				pattern = pattern.ToUpper ();
				content = content.ToUpper ();
			}

			int plen = pattern.Length - 1;
			int delta = 0;
			int i = 0, end = content.Length - pattern.Length;
			if (provider.SelectionStartPosition > -1)
				i = provider.SelectionStartPosition;
			if (provider.SelectionEndPosition > -1)
				end = provider.SelectionEndPosition - pattern.Length;
			while (i <= end) {
				int j = plen;
				while (j >= 0 && pattern[j] == content[i + j])
					j--;

				if (j < 0) {
					int idx = i;
					if (!filter.WholeWordsOnly || FilterOptions.IsWholeWordAt (content, idx, pattern.Length)) {
						if (replacePattern != null) {
							yield return new SearchResult (provider, idx + delta, replacePattern.Length);
							
							provider.Replace (idx + delta, pattern.Length, replacePattern);
							delta += replacePattern.Length - pattern.Length;
						} else {
							yield return new SearchResult (provider, idx, pattern.Length);
						}
					}
					i += next[0];
				}
				else
					i += System.Math.Max (next[j + 1], j-occ[(int)content[i + j]]);
			}
		}
		public SearchResult (FileProvider fileProvider, int offset, int length)
		{
			this.FileProvider = fileProvider;
			this.Offset = offset;
			this.Length = length;
		}
Ejemplo n.º 9
0
		public IEnumerable<SearchResult> Search (FileProvider provider, string content, string pattern, string replacePattern, FilterOptions filter)
		{
			if (string.IsNullOrEmpty (content))
				yield break;
			int idx = provider.SelectionStartPosition < 0 ? 0 : Math.Max (0, provider.SelectionStartPosition);
			int delta = 0;
			var comparison = filter.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
			
			while ((idx = content.IndexOf (pattern, idx, content.Length - idx, comparison)) >= 0) {
				if (!filter.WholeWordsOnly || FilterOptions.IsWholeWordAt (content, idx, pattern.Length)) {
					if (replacePattern != null) {
						provider.Replace (idx + delta, pattern.Length, replacePattern);
						yield return new SearchResult (provider, idx + delta, replacePattern.Length);
						delta += replacePattern.Length - pattern.Length;
					} else {
						yield return new SearchResult (provider, idx, pattern.Length);
					}
				}
				idx += pattern.Length;
			}
		}
Ejemplo n.º 10
0
        public IEnumerable <SearchResult> Search(FileProvider provider, TextReader reader, string pattern, FilterOptions filter)
        {
            if (reader == null)
            {
                yield break;
            }
            int  i            = provider.SelectionStartPosition < 0 ? 0 : Math.Max(0, provider.SelectionStartPosition);
            var  buffer       = new RingBufferReader(reader, pattern.Length + 2);
            bool wasSeparator = true;

            if (!filter.CaseSensitive)
            {
                pattern = pattern.ToUpperInvariant();
            }
            while (true)
            {
                int next = buffer.Next();
                if (next < 0)
                {
                    yield break;
                }
                char ch = (char)next;
                if ((filter.CaseSensitive ? ch : char.ToUpperInvariant(ch)) == pattern [0] &&
                    (!filter.WholeWordsOnly || wasSeparator))
                {
                    bool isMatch = true;
                    for (int j = 1; j < pattern.Length; j++)
                    {
                        next = buffer.Next();
                        if (next < 0)
                        {
                            yield break;
                        }
                        if ((filter.CaseSensitive ? next : char.ToUpperInvariant((char)next)) != pattern [j])
                        {
                            buffer.TakeBack(j);
                            isMatch = false;
                            break;
                        }
                    }
                    if (isMatch)
                    {
                        if (filter.WholeWordsOnly)
                        {
                            next = buffer.Next();
                            if (next >= 0 && !FilterOptions.IsWordSeparator((char)next))
                            {
                                buffer.TakeBack(pattern.Length);
                                i++;
                                continue;
                            }
                            buffer.TakeBack(1);
                        }

                        yield return(new SearchResult(provider, i, pattern.Length));

                        i += pattern.Length - 1;
                    }
                }

                i++;
                if (filter.WholeWordsOnly)
                {
                    wasSeparator = FilterOptions.IsWordSeparator((char)ch);
                }
            }
        }
Ejemplo n.º 11
0
 public FileSearchResult(FileProvider provider, TextReader reader, List <SearchResult> results)
 {
     Provider = provider;
     Reader   = reader;
     Results  = results;
 }
Ejemplo n.º 12
0
		IEnumerable<SearchResult> FindAll (IProgressMonitor monitor, FileProvider provider, string pattern, string replacePattern, FilterOptions filter)
		{
			if (string.IsNullOrEmpty (pattern))
				return Enumerable.Empty<SearchResult> ();
			string content;
			try {
				TextReader reader = provider.Open ();
				if (reader == null)
					return Enumerable.Empty<SearchResult> ();
				content = reader.ReadToEnd ();
				reader.Close ();
			} catch (Exception e) {
				LoggingService.LogError ("Error while reading file", e);
				return Enumerable.Empty<SearchResult> ();
			}
			if (filter.RegexSearch)
				return RegexSearch (monitor, provider, content, replacePattern, filter);
			return Search (provider, content, pattern, replacePattern, filter);
		}
Ejemplo n.º 13
0
			public FileSearchResult (FileProvider provider, TextReader reader, List<SearchResult> results)
			{
				Provider = provider;
				Reader = reader;
				Results = results;
			}
Ejemplo n.º 14
0
		public IEnumerable<SearchResult> Search (FileProvider provider, TextReader reader, string pattern, FilterOptions filter)
		{
			if (reader == null)
				yield break;
			int i = provider.SelectionStartPosition < 0 ? 0 : Math.Max (0, provider.SelectionStartPosition);
			var buffer = new RingBufferReader(reader, pattern.Length + 2);
			bool wasSeparator = true;
			if (!filter.CaseSensitive)
				pattern = pattern.ToUpperInvariant ();
			while (true) {
				int next = buffer.Next ();
				if (next < 0)
					yield break;
				char ch = (char)next;
				if ((filter.CaseSensitive ? ch : char.ToUpperInvariant (ch)) == pattern [0] &&
				    (!filter.WholeWordsOnly || wasSeparator)) {
					bool isMatch = true;
					for (int j = 1; j < pattern.Length; j++) {
						next = buffer.Next ();
						if (next < 0)
							yield break;
						if ((filter.CaseSensitive ? next : char.ToUpperInvariant ((char)next)) != pattern [j]) {
							buffer.TakeBack (j);
							isMatch = false;
							break;
						}
					}
					if (isMatch) {
						if (filter.WholeWordsOnly) {
							next = buffer.Next ();
							if (next >= 0 && !FilterOptions.IsWordSeparator ((char)next)) {
								buffer.TakeBack (pattern.Length);
								i++;
								continue;
							}
							buffer.TakeBack (1);
						}

						yield return new SearchResult (provider, i, pattern.Length);
						i += pattern.Length - 1;
					}
				}

				i++;
				if (filter.WholeWordsOnly) {
					wasSeparator = FilterOptions.IsWordSeparator ((char)ch);
				}
			}
		}
Ejemplo n.º 15
0
		public void GoToDeclaration ()
		{
			if (item is CompoundType) {
				CompoundType compoundType = (CompoundType)item;
				monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true);
				using (monitor) {
					foreach (IType part in compoundType.Parts) {
						FileProvider provider = new FileProvider (part.CompilationUnit.FileName);
						Mono.TextEditor.Document doc = new Mono.TextEditor.Document ();
						System.IO.TextReader textReader = provider.Open ();
						doc.Text = textReader.ReadToEnd ();
						textReader.Close ();
						int position = doc.LocationToOffset (part.Location.Line, part.Location.Column);
						while (position + part.Name.Length < doc.Length) {
							if (doc.GetTextAt (position, part.Name.Length) == part.Name)
								break;
							position++;
						}
						monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult (provider, position, part.Name.Length));
					}
					
				}
				
				return;
			}
			IdeApp.ProjectOperations.JumpToDeclaration (item);
		}
		IEnumerable<SearchResult> FindAll (IProgressMonitor monitor, FileProvider provider, string pattern, string replacePattern, FilterOptions filter)
		{
			if (string.IsNullOrEmpty (pattern))
				return new SearchResult[0];
			string content;
			try {
				TextReader reader = provider.Open ();
				content = reader.ReadToEnd ();
				reader.Close ();
			} catch (Exception) {
				return new SearchResult[0];
			}
			if (filter.RegexSearch)
				return RegexSearch (monitor, provider, content, pattern, replacePattern, filter);
			return Search (provider, content, pattern, replacePattern, filter);
		}
Ejemplo n.º 17
0
		public SearchResult (FileProvider fileProvider, int offset, int length)
		{
			FileProvider = fileProvider;
			Offset = offset;
			Length = length;
		}
Ejemplo n.º 18
0
 public SearchResult(FileProvider fileProvider, int offset, int length)
 {
     this.FileProvider = fileProvider;
     this.Offset       = offset;
     this.Length       = length;
 }