1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import java.io.IOException ; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jdt.core.search.*; 18 import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; 19 import org.eclipse.jdt.internal.compiler.util.Util; 20 import org.eclipse.jdt.internal.core.index.*; 21 import org.eclipse.jdt.internal.core.search.*; 22 23 26 public abstract class InternalSearchPattern { 27 28 31 IJavaElement focus; 32 33 int kind; 34 boolean mustResolve = true; 35 36 void acceptMatch(String relativePath, String containerPath, SearchPattern pattern, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope) { 37 38 if (scope instanceof JavaSearchScope) { 39 JavaSearchScope javaSearchScope = (JavaSearchScope) scope; 40 AccessRuleSet access = javaSearchScope.getAccessRuleSet(relativePath, containerPath); 43 if (access != JavaSearchScope.NOT_ENCLOSED) { String documentPath = documentPath(containerPath, relativePath); 45 if (!requestor.acceptIndexMatch(documentPath, pattern, participant, access)) 46 throw new OperationCanceledException(); 47 } 48 } else { 49 String documentPath = documentPath(containerPath, relativePath); 50 if (scope.encloses(documentPath)) 51 if (!requestor.acceptIndexMatch(documentPath, pattern, participant, null)) 52 throw new OperationCanceledException(); 53 54 } 55 } 56 SearchPattern currentPattern() { 57 return (SearchPattern) this; 58 } 59 String documentPath(String containerPath, String relativePath) { 60 String separator = Util.isArchiveFileName(containerPath) ? IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR : "/"; StringBuffer buffer = new StringBuffer (containerPath.length() + separator.length() + relativePath.length()); 62 buffer.append(containerPath); 63 buffer.append(separator); 64 buffer.append(relativePath); 65 return buffer.toString(); 66 } 67 70 void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor monitor) throws IOException { 71 if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException(); 72 try { 73 index.startQuery(); 74 SearchPattern pattern = currentPattern(); 75 EntryResult[] entries = ((InternalSearchPattern)pattern).queryIn(index); 76 if (entries == null) return; 77 78 SearchPattern decodedResult = pattern.getBlankPattern(); 79 String containerPath = index.containerPath; 80 for (int i = 0, l = entries.length; i < l; i++) { 81 if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException(); 82 83 EntryResult entry = entries[i]; 84 decodedResult.decodeIndexKey(entry.getWord()); 85 if (pattern.matchesDecodedKey(decodedResult)) { 86 String [] names = entry.getDocumentNames(index); 88 for (int j = 0, n = names.length; j < n; j++) 89 acceptMatch(names[j], containerPath, decodedResult, requestor, participant, scope); 90 } 91 } 92 } finally { 93 index.stopQuery(); 94 } 95 } 96 boolean isPolymorphicSearch() { 97 return false; 98 } 99 EntryResult[] queryIn(Index index) throws IOException { 100 SearchPattern pattern = (SearchPattern) this; 101 return index.query(pattern.getIndexCategories(), pattern.getIndexKey(), pattern.getMatchRule()); 102 } 103 104 } 105 | Popular Tags |