KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > search > JavaSearchParticipant


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.jdt.internal.core.search;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.jdt.core.search.*;
15 import org.eclipse.jdt.internal.core.search.indexing.BinaryIndexer;
16 import org.eclipse.jdt.internal.core.search.indexing.SourceIndexer;
17 import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
18
19 /**
20  * A search participant describes a particular extension to a generic search mechanism, allowing thus to
21  * perform combined search actions which will involve all required participants
22  *
23  * A search scope defines which participants are involved.
24  *
25  * A search participant is responsible for holding index files, and selecting the appropriate ones to feed to
26  * index queries. It also can map a document path to an actual document (note that documents could live outside
27  * the workspace or no exist yet, and thus aren't just resources).
28  */

29 public class JavaSearchParticipant extends SearchParticipant {
30     
31     IndexSelector indexSelector;
32     
33     /* (non-Javadoc)
34      * @see org.eclipse.jdt.core.search.SearchParticipant#beginSearching()
35      */

36     public void beginSearching() {
37         super.beginSearching();
38         this.indexSelector = null;
39     }
40
41     /* (non-Javadoc)
42      * @see org.eclipse.jdt.core.search.SearchParticipant#doneSearching()
43      */

44     public void doneSearching() {
45         this.indexSelector = null;
46         super.doneSearching();
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.jdt.core.search.SearchParticipant#getName()
51      */

52     public String JavaDoc getDescription() {
53         return "Java"; //$NON-NLS-1$
54
}
55     
56     /* (non-Javadoc)
57      * @see org.eclipse.jdt.core.search.SearchParticipant#getDocument(String)
58      */

59     public SearchDocument getDocument(String JavaDoc documentPath) {
60         return new JavaSearchDocument(documentPath, this);
61     }
62
63     /* (non-Javadoc)
64      * @see org.eclipse.jdt.core.search.SearchParticipant#indexDocument(SearchDocument)
65      */

66     public void indexDocument(SearchDocument document, IPath indexPath) {
67         // TODO must verify that the document + indexPath match, when this is not called from scheduleDocumentIndexing
68
document.removeAllIndexEntries(); // in case the document was already indexed
69

70         String JavaDoc documentPath = document.getPath();
71         if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(documentPath)) {
72             new SourceIndexer(document).indexDocument();
73         } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(documentPath)) {
74             new BinaryIndexer(document).indexDocument();
75         }
76     }
77     
78     /* (non-Javadoc)
79      * @see SearchParticipant#locateMatches(SearchDocument[], SearchPattern, IJavaSearchScope, SearchRequestor, IProgressMonitor)
80      */

81     public void locateMatches(SearchDocument[] indexMatches, SearchPattern pattern,
82             IJavaSearchScope scope, SearchRequestor requestor, IProgressMonitor monitor) throws CoreException {
83         
84         MatchLocator matchLocator =
85             new MatchLocator(
86                 pattern,
87                 requestor,
88                 scope,
89                 monitor
90         );
91
92         /* eliminating false matches and locating them */
93         if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
94         matchLocator.locateMatches(indexMatches);
95         
96
97         if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
98         
99         matchLocator.locatePackageDeclarations(this);
100     }
101
102     /* (non-Javadoc)
103      * @see org.eclipse.jdt.core.search.SearchParticipant#selectIndexes(org.eclipse.jdt.core.search.SearchQuery, org.eclipse.jdt.core.search.SearchContext)
104      */

105     public IPath[] selectIndexes(
106         SearchPattern pattern,
107         IJavaSearchScope scope) {
108         
109         if (this.indexSelector == null) {
110             this.indexSelector = new IndexSelector(scope, pattern);
111         }
112         return this.indexSelector.getIndexLocations();
113     }
114     
115 }
116
Popular Tags