KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search > internal > core > text > FilesOfScopeCalculator


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 package org.eclipse.search.internal.core.text;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
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.IResourceProxyVisitor;
22
23 import org.eclipse.search.core.text.TextSearchScope;
24
25 public class FilesOfScopeCalculator implements IResourceProxyVisitor {
26
27     private final TextSearchScope fScope;
28     private final MultiStatus fStatus;
29     private ArrayList JavaDoc fFiles;
30
31     public FilesOfScopeCalculator(TextSearchScope scope, MultiStatus status) {
32         fScope= scope;
33         fStatus= status;
34     }
35
36     public boolean visit(IResourceProxy proxy) {
37         boolean inScope= fScope.contains(proxy);
38
39         if (inScope && proxy.getType() == IResource.FILE) {
40             fFiles.add(proxy.requestResource());
41         }
42         return inScope;
43     }
44
45     public IFile[] process() {
46         fFiles= new ArrayList JavaDoc();
47         try {
48             IResource[] roots= fScope.getRoots();
49             for (int i= 0; i < roots.length; i++) {
50                 try {
51                     IResource resource= roots[i];
52                     if (resource.isAccessible()) {
53                         resource.accept(this, 0);
54                     }
55                 } catch (CoreException ex) {
56                     // report and ignore
57
fStatus.add(ex.getStatus());
58                 }
59             }
60             return (IFile[]) fFiles.toArray(new IFile[fFiles.size()]);
61         } finally {
62             fFiles= null;
63         }
64     }
65 }
66
Popular Tags