KickJava   Java API By Example, From Geeks To Geeks.

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


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.MultiStatus;
17
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.resources.IResourceProxy;
21 import org.eclipse.core.resources.ResourcesPlugin;
22
23 import org.eclipse.search.internal.core.text.FileNamePatternSearchScope;
24 import org.eclipse.search.internal.core.text.FilesOfScopeCalculator;
25
26 /**
27  * A {@link TextSearchScope} defines the scope of a search. The scope consists of all workbench resources that are accepted
28  * by {@link #contains(IResourceProxy)} and that either are a root element ({@link #getRoots()}) or have a root element
29  * in their parent chain.
30  *
31  * @see #newSearchScope(IResource[], java.util.regex.Pattern, boolean)
32  * @since 3.2
33  */

34 public abstract class TextSearchScope {
35     
36     
37     /**
38      * Creates a scope that consists of all files that match the <code>fileNamePattern</code> and that
39      * either are one of the roots, or have one of the roots in their parent chain.
40      * If <code>visitDerivedResources</code> is not enabled, all files that are marked derived or
41      * have a derived container in their parent chain are not part of the scope.
42      *
43      * @param rootResources the resources that are the roots of the scope
44      * @param fileNamePattern file name pattern for this scope.
45      * @param visitDerivedResources if set also derived folders and files are searched.
46      * @return a scope the search scope
47      */

48     public static TextSearchScope newSearchScope(IResource[] rootResources, Pattern JavaDoc fileNamePattern, boolean visitDerivedResources) {
49         FileNamePatternSearchScope scope= FileNamePatternSearchScope.newSearchScope(new String JavaDoc(), rootResources, visitDerivedResources);
50         scope.setFileNamePattern(fileNamePattern);
51         return scope;
52     }
53     
54     
55     /**
56      * Returns the resources that form the root. Roots can not contain each other. Root elements are only part of the
57      * scope if they are also accepted by {@link #contains(IResourceProxy)}.
58      *
59      * @return returns the set of root resources. The default behavior is to return the workspace root.
60      */

61     public IResource[] getRoots() {
62         return new IResource[] { ResourcesPlugin.getWorkspace().getRoot() };
63     }
64     
65     /**
66      * Returns if a given resource is part of the scope. If a container is not part of the scope, also all its members
67      * are not part of the scope.
68      *
69      * @param proxy the resource proxy to test.
70      * @return returns <code>true</code> if a resource is part of the scope. if <code>false</code> is returned the resource
71      * and all its children are not part of the scope.
72      */

73     public abstract boolean contains(IResourceProxy proxy);
74
75     
76     /**
77      * Evaluates all files in this scope.
78      *
79      * @param status a {@link MultiStatus} to collect the error status that occurred while collecting resources.
80      * @return returns the files in the scope.
81      */

82     public IFile[] evaluateFilesInScope(MultiStatus status) {
83         return new FilesOfScopeCalculator(this, status).process();
84     }
85
86     
87 }
88
Popular Tags