Lines 10-22
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.search; |
11 |
package org.eclipse.jdt.core.search; |
12 |
|
12 |
|
|
|
13 |
import java.io.IOException; |
14 |
|
15 |
import org.eclipse.core.runtime.IProgressMonitor; |
16 |
import org.eclipse.core.runtime.OperationCanceledException; |
13 |
import org.eclipse.jdt.core.*; |
17 |
import org.eclipse.jdt.core.*; |
14 |
import org.eclipse.jdt.core.compiler.*; |
18 |
import org.eclipse.jdt.core.compiler.*; |
15 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
19 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
|
|
20 |
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; |
16 |
import org.eclipse.jdt.internal.compiler.parser.Scanner; |
21 |
import org.eclipse.jdt.internal.compiler.parser.Scanner; |
17 |
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; |
22 |
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; |
18 |
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; |
23 |
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; |
19 |
import org.eclipse.jdt.internal.core.LocalVariable; |
24 |
import org.eclipse.jdt.internal.core.LocalVariable; |
|
|
25 |
import org.eclipse.jdt.internal.core.index.EntryResult; |
26 |
import org.eclipse.jdt.internal.core.index.Index; |
27 |
import org.eclipse.jdt.internal.core.search.IndexQueryRequestor; |
28 |
import org.eclipse.jdt.internal.core.search.JavaSearchScope; |
20 |
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; |
29 |
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; |
21 |
import org.eclipse.jdt.internal.core.search.matching.*; |
30 |
import org.eclipse.jdt.internal.core.search.matching.*; |
22 |
|
31 |
|
Lines 43-49
Link Here
|
43 |
* @see #createPattern(String, int, int, int) |
52 |
* @see #createPattern(String, int, int, int) |
44 |
* @since 3.0 |
53 |
* @since 3.0 |
45 |
*/ |
54 |
*/ |
46 |
public abstract class SearchPattern extends InternalSearchPattern { |
55 |
public abstract class SearchPattern { |
47 |
|
56 |
|
48 |
// Rules for pattern matching: (exact, prefix, pattern) [ | case sensitive] |
57 |
// Rules for pattern matching: (exact, prefix, pattern) [ | case sensitive] |
49 |
/** |
58 |
/** |
Lines 197-202
Link Here
|
197 |
|
206 |
|
198 |
private int matchRule; |
207 |
private int matchRule; |
199 |
|
208 |
|
|
|
209 |
/** |
210 |
* The focus element (used for reference patterns) |
211 |
* @noreference This field is not intended to be referenced by clients. |
212 |
*/ |
213 |
public IJavaElement focus; |
214 |
|
215 |
/** |
216 |
* @noreference This field is not intended to be referenced by clients. |
217 |
*/ |
218 |
public int kind; |
219 |
|
220 |
/** |
221 |
* @noreference This field is not intended to be referenced by clients. |
222 |
*/ |
223 |
public boolean mustResolve = true; |
224 |
|
200 |
/** |
225 |
/** |
201 |
* Creates a search pattern with the rule to apply for matching index keys. |
226 |
* Creates a search pattern with the rule to apply for matching index keys. |
202 |
* It can be exact match, prefix match, pattern match or regexp match. |
227 |
* It can be exact match, prefix match, pattern match or regexp match. |
Lines 244-250
Link Here
|
244 |
this.matchRule &= ~R_PREFIX_MATCH; |
269 |
this.matchRule &= ~R_PREFIX_MATCH; |
245 |
} |
270 |
} |
246 |
} |
271 |
} |
|
|
272 |
/** |
273 |
* @noreference This method is not intended to be referenced by clients. |
274 |
* @nooverride This method is not intended to be re-implemented or extended by clients. |
275 |
*/ |
276 |
public void acceptMatch(String relativePath, String containerPath, char separator, SearchPattern pattern, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope) { |
277 |
|
278 |
if (scope instanceof JavaSearchScope) { |
279 |
JavaSearchScope javaSearchScope = (JavaSearchScope) scope; |
280 |
// Get document path access restriction from java search scope |
281 |
// Note that requestor has to verify if needed whether the document violates the access restriction or not |
282 |
AccessRuleSet access = javaSearchScope.getAccessRuleSet(relativePath, containerPath); |
283 |
if (access != JavaSearchScope.NOT_ENCLOSED) { // scope encloses the document path |
284 |
StringBuffer documentPath = new StringBuffer(containerPath.length() + 1 + relativePath.length()); |
285 |
documentPath.append(containerPath); |
286 |
documentPath.append(separator); |
287 |
documentPath.append(relativePath); |
288 |
if (!requestor.acceptIndexMatch(documentPath.toString(), pattern, participant, access)) |
289 |
throw new OperationCanceledException(); |
290 |
} |
291 |
} else { |
292 |
StringBuffer buffer = new StringBuffer(containerPath.length() + 1 + relativePath.length()); |
293 |
buffer.append(containerPath); |
294 |
buffer.append(separator); |
295 |
buffer.append(relativePath); |
296 |
String documentPath = buffer.toString(); |
297 |
if (scope.encloses(documentPath)) |
298 |
if (!requestor.acceptIndexMatch(documentPath, pattern, participant, null)) |
299 |
throw new OperationCanceledException(); |
247 |
|
300 |
|
|
|
301 |
} |
302 |
} |
303 |
/** |
304 |
* @noreference This method is not intended to be referenced by clients. |
305 |
* @nooverride This method is not intended to be re-implemented or extended by clients. |
306 |
*/ |
307 |
public SearchPattern currentPattern() { |
308 |
return this; |
309 |
} |
248 |
/** |
310 |
/** |
249 |
* Answers true if the pattern matches the given name using CamelCase rules, or |
311 |
* Answers true if the pattern matches the given name using CamelCase rules, or |
250 |
* false otherwise. char[] CamelCase matching does NOT accept explicit wild-cards |
312 |
* false otherwise. char[] CamelCase matching does NOT accept explicit wild-cards |
Lines 1991-1996
Link Here
|
1991 |
// called from findIndexMatches(), override as necessary |
2053 |
// called from findIndexMatches(), override as necessary |
1992 |
} |
2054 |
} |
1993 |
/** |
2055 |
/** |
|
|
2056 |
* Query a given index for matching entries. Assumes the sender has opened the index and will close when finished. |
2057 |
* |
2058 |
* @noreference This method is not intended to be referenced by clients. |
2059 |
* @nooverride This method is not intended to be re-implemented or extended by clients. |
2060 |
*/ |
2061 |
public void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor monitor) throws IOException { |
2062 |
if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException(); |
2063 |
try { |
2064 |
index.startQuery(); |
2065 |
SearchPattern pattern = currentPattern(); |
2066 |
EntryResult[] entries = pattern.queryIn(index); |
2067 |
if (entries == null) return; |
2068 |
|
2069 |
SearchPattern decodedResult = pattern.getBlankPattern(); |
2070 |
String containerPath = index.containerPath; |
2071 |
char separator = index.separator; |
2072 |
for (int i = 0, l = entries.length; i < l; i++) { |
2073 |
if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException(); |
2074 |
|
2075 |
EntryResult entry = entries[i]; |
2076 |
decodedResult.decodeIndexKey(entry.getWord()); |
2077 |
if (pattern.matchesDecodedKey(decodedResult)) { |
2078 |
// TODO (kent) some clients may not need the document names |
2079 |
String[] names = entry.getDocumentNames(index); |
2080 |
for (int j = 0, n = names.length; j < n; j++) |
2081 |
acceptMatch(names[j], containerPath, separator, decodedResult, requestor, participant, scope); |
2082 |
} |
2083 |
} |
2084 |
} finally { |
2085 |
index.stopQuery(); |
2086 |
} |
2087 |
} |
2088 |
/** |
1994 |
* Returns a blank pattern that can be used as a record to decode an index key. |
2089 |
* Returns a blank pattern that can be used as a record to decode an index key. |
1995 |
* <p> |
2090 |
* <p> |
1996 |
* Implementors of this method should return a new search pattern that is going to be used |
2091 |
* Implementors of this method should return a new search pattern that is going to be used |
Lines 2044-2049
Link Here
|
2044 |
return this.matchRule; |
2139 |
return this.matchRule; |
2045 |
} |
2140 |
} |
2046 |
/** |
2141 |
/** |
|
|
2142 |
* @noreference This method is not intended to be referenced by clients. |
2143 |
* @nooverride This method is not intended to be re-implemented or extended by clients. |
2144 |
*/ |
2145 |
public boolean isPolymorphicSearch() { |
2146 |
return false; |
2147 |
} |
2148 |
/** |
2047 |
* Returns whether this pattern matches the given pattern (representing a decoded index key). |
2149 |
* Returns whether this pattern matches the given pattern (representing a decoded index key). |
2048 |
* <p> |
2150 |
* <p> |
2049 |
* This method should be re-implemented in subclasses that need to narrow down the |
2151 |
* This method should be re-implemented in subclasses that need to narrow down the |
Lines 2254-2259
Link Here
|
2254 |
} |
2356 |
} |
2255 |
|
2357 |
|
2256 |
/** |
2358 |
/** |
|
|
2359 |
* @noreference This method is not intended to be referenced by clients. |
2360 |
* @nooverride This method is not intended to be re-implemented or extended by clients. |
2361 |
*/ |
2362 |
public EntryResult[] queryIn(Index index) throws IOException { |
2363 |
return index.query(getIndexCategories(), getIndexKey(), getMatchRule()); |
2364 |
} |
2365 |
|
2366 |
/** |
2257 |
* @see java.lang.Object#toString() |
2367 |
* @see java.lang.Object#toString() |
2258 |
*/ |
2368 |
*/ |
2259 |
public String toString() { |
2369 |
public String toString() { |