1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import java.io.IOException ; 14 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.OperationCanceledException; 17 import org.eclipse.jdt.core.search.*; 18 import org.eclipse.jdt.internal.compiler.util.SimpleSet; 19 import org.eclipse.jdt.internal.core.index.*; 20 import org.eclipse.jdt.internal.core.search.IndexQueryRequestor; 21 22 25 public abstract class AndPattern extends JavaSearchPattern { 27 public AndPattern(int patternKind, int matchRule) { 28 super(patternKind, matchRule); 29 } 30 public void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor progressMonitor) throws IOException { 31 if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException(); 32 33 this.resetQuery(); 34 SimpleSet intersectedNames = null; 35 try { 36 index.startQuery(); 37 do { 38 SearchPattern pattern = ((InternalSearchPattern) this).currentPattern(); 39 EntryResult[] entries = ((InternalSearchPattern)pattern).queryIn(index); 40 if (entries == null) return; 41 42 SearchPattern decodedResult = pattern.getBlankPattern(); 43 SimpleSet newIntersectedNames = new SimpleSet(3); 44 for (int i = 0, l = entries.length; i < l; i++) { 45 if (progressMonitor != null && progressMonitor.isCanceled()) throw new OperationCanceledException(); 46 47 EntryResult entry = entries[i]; 48 decodedResult.decodeIndexKey(entry.getWord()); 49 if (pattern.matchesDecodedKey(decodedResult)) { 50 String [] names = entry.getDocumentNames(index); 51 if (intersectedNames != null) { 52 for (int j = 0, n = names.length; j < n; j++) 53 if (intersectedNames.includes(names[j])) 54 newIntersectedNames.add(names[j]); 55 } else { 56 for (int j = 0, n = names.length; j < n; j++) 57 newIntersectedNames.add(names[j]); 58 } 59 } 60 } 61 62 if (newIntersectedNames.elementSize == 0) return; 63 intersectedNames = newIntersectedNames; 64 } while (this.hasNextQuery()); 65 } finally { 66 index.stopQuery(); 67 } 68 69 String containerPath = index.containerPath; 70 Object [] names = intersectedNames.values; 71 for (int i = 0, l = names.length; i < l; i++) 72 if (names[i] != null) 73 ((InternalSearchPattern) this).acceptMatch((String ) names[i], containerPath, null, requestor, participant, scope); } 75 78 protected abstract boolean hasNextQuery(); 79 82 protected abstract void resetQuery(); 83 } 84 | Popular Tags |