Class TextSearchRequestor
TextSearchEngine.search(TextSearchScope, TextSearchRequestor, java.util.regex.Pattern, org.eclipse.core.runtime.IProgressMonitor)
and implement the acceptPatternMatch(TextSearchMatchAccess)
method, and possibly override other life cycle methods.
The search engine calls beginReporting()
when a search starts,
then calls acceptFile(IFile)
for a file visited.
If acceptFile(IFile)
returns true
reportBinaryFile(IFile)
is
called if the file could be binary followed by
acceptPatternMatch(TextSearchMatchAccess)
for each pattern match found
in this file. The end of the search is signaled with a call to endReporting()
.
Note that acceptFile(IFile)
is called for all files in the search scope,
even if no match can be found.
TextSearchEngine.search(TextSearchScope, TextSearchRequestor, java.util.regex.Pattern, org.eclipse.core.runtime.IProgressMonitor)
can perform parallel processing.
To support parallel processing, subclasses of this class must synchronize access
to any shared data accumulated by or accessed by overrides of the acceptFile(IFile)
,
reportBinaryFile(IFile)
and acceptPatternMatch(TextSearchMatchAccess)
methods, and override the canRunInParallel()
method to return true.
The order of the search results is unspecified and may vary from request to request; when displaying results, clients should not rely on the order but should instead arrange the results in an order that would be more meaningful to the user.
- Since:
- 3.2
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
acceptFile
(IFile file) Notification sent before search starts in the given file.boolean
acceptPatternMatch
(TextSearchMatchAccess matchAccess) Accepts the given search match and decides if the search should continue for this file.void
Notification sent before starting the search action.boolean
Reports whether this TextSearchRequestor supports executing the text search algorithm in parallel.void
Notification sent after having completed the search action.void
flushMatches
(IFile file) Notification that the matches of the given file should be flushed.boolean
reportBinaryFile
(IFile file) Notification sent that a file might contain binary context.
-
Constructor Details
-
TextSearchRequestor
public TextSearchRequestor()
-
-
Method Details
-
beginReporting
public void beginReporting()Notification sent before starting the search action. Typically, this would tell a search requestor to clear previously recorded search results.The default implementation of this method does nothing. Subclasses may override.
-
endReporting
public void endReporting()Notification sent after having completed the search action. Typically, this would tell a search requestor collector that no more results will be forthcoming in this search.The default implementation of this method does nothing. Subclasses may override.
-
acceptFile
Notification sent before search starts in the given file. This method is called for all files that are contained in the search scope. Implementors can decide if the file content should be searched for search matches or not.The default behaviour is to search the file for matches.
If
canRunInParallel()
returns true, this method may be called in parallel by different threads, so any access or updates to collections of results or other shared state must be synchronized.- Parameters:
file
- the file resource to be searched.- Returns:
- If false, no pattern matches will be reported for the content of this file.
- Throws:
CoreException
- implementors can throw aCoreException
if accessing the resource fails or another problem prevented the processing of the search match.
-
flushMatches
Notification that the matches of the given file should be flushed. The default behaviour is to ignore this notification. Implementors can use this notification to update the progress after a file was searched. Otherwise the progress may not be visible until all files have been searched.- Parameters:
file
- the file that was just processed.- Since:
- 3.14
-
reportBinaryFile
Notification sent that a file might contain binary context. It is the choice of the search engine to report binary files and it is the heuristic of the search engine to decide that a file could be binary. Implementors can decide if the file content should be searched for search matches or not.This call is sent after calls {link
acceptFile(IFile)
that returntrue
and before any matches reported for this file withacceptPatternMatch(TextSearchMatchAccess)
.If
canRunInParallel()
returns true, this method may be called in parallel by different threads, so any access or updates to collections of results or other shared state must be synchronized.The default behaviour is to skip binary files
- Parameters:
file
- the file that might be binary- Returns:
- If false, no pattern matches will be reported for the content of this file.
-
acceptPatternMatch
Accepts the given search match and decides if the search should continue for this file.If
canRunInParallel()
returns true, this method may be called in parallel by different threads, so any access or updates to collections of results or other shared state must be synchronized.- Parameters:
matchAccess
- gives access to information of the match found. The matchAccess is not a value object. Its value might change after this method is finished, and the element might be reused.- Returns:
- If false is returned no further matches will be reported for this file.
- Throws:
CoreException
- implementors can throw aCoreException
if accessing the resource fails or another problem prevented the processing of the search match.
-
canRunInParallel
public boolean canRunInParallel()Reports whether this TextSearchRequestor supports executing the text search algorithm in parallel.Subclasses should override this method and return true if they desire faster search results and their
acceptFile(IFile)
,reportBinaryFile(IFile)
andacceptPatternMatch(TextSearchMatchAccess)
methods are thread-safe.The default behavior is to not use parallelism when running a text search.
- Returns:
- If true, the text search will be run in parallel.
- Since:
- 3.10
-