KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > core > text > TextSearchEngine


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.search.core.text;
13
14 import java.util.regex.Pattern JavaDoc;
15
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18
19 import org.eclipse.core.resources.IFile;
20
21 import org.eclipse.search.internal.core.text.TextSearchVisitor;
22 import org.eclipse.search.internal.ui.SearchPlugin;
23
24 /**
25  * A {@link TextSearchEngine} searches the content of a workspace file resources
26  * for matches to a given search pattern.
27  * <p>
28  * {@link #create()} gives access to an instance of the search engine. By default this is the default
29  * text search engine (see {@link #createDefault()}) but extensions can offer more sophisticated
30  * search engine implementations.
31  * </p>
32  * @since 3.2
33  */

34 public abstract class TextSearchEngine {
35     
36     /**
37      * Creates an instance of the search engine. By default this is the default text search engine (see {@link #createDefault()}),
38      * but extensions can offer more sophisticated search engine implementations.
39      * @return the created {@link TextSearchEngine}.
40      */

41     public static TextSearchEngine create() {
42         return SearchPlugin.getDefault().getTextSearchEngineRegistry().getPreferred();
43     }
44     
45     /**
46      * Creates the default, built-in, text search engine that implements a brute-force search, not using
47      * any search index.
48      * Note that clients should always use the search engine provided by {@link #create()}.
49      * @return an instance of the default text search engine {@link TextSearchEngine}.
50      */

51     public static TextSearchEngine createDefault() {
52         return new TextSearchEngine() {
53             public IStatus search(TextSearchScope scope, TextSearchRequestor requestor, Pattern JavaDoc searchPattern, IProgressMonitor monitor) {
54                 return new TextSearchVisitor(requestor, searchPattern).search(scope, monitor);
55             }
56             
57             public IStatus search(IFile[] scope, TextSearchRequestor requestor, Pattern JavaDoc searchPattern, IProgressMonitor monitor) {
58                  return new TextSearchVisitor(requestor, searchPattern).search(scope, monitor);
59             }
60         };
61     }
62         
63     /**
64      * Uses a given search pattern to find matches in the content of workspace file resources. If a file is open in an editor, the
65      * editor buffer is searched.
66
67      * @param requestor the search requestor that gets the search results
68      * @param scope the scope defining the resources to search in
69      * @param searchPattern The search pattern used to find matches in the file contents.
70      * @param monitor the progress monitor to use
71      * @return the status containing information about problems in resources searched.
72      */

73     public abstract IStatus search(TextSearchScope scope, TextSearchRequestor requestor, Pattern JavaDoc searchPattern, IProgressMonitor monitor);
74
75     /**
76      * Uses a given search pattern to find matches in the content of workspace file resources. If a file is open in an editor, the
77      * editor buffer is searched.
78
79      * @param requestor the search requestor that gets the search results
80      * @param scope the files to search in
81      * @param searchPattern The search pattern used to find matches in the file contents.
82      * @param monitor the progress monitor to use
83      * @return the status containing information about problems in resources searched.
84      */

85     public abstract IStatus search(IFile[] scope, TextSearchRequestor requestor, Pattern JavaDoc searchPattern, IProgressMonitor monitor);
86     
87 }
88
Popular Tags