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.jdt.core.search.*; 17 import org.eclipse.jdt.internal.core.index.Index; 18 import org.eclipse.jdt.internal.core.search.IndexQueryRequestor; 19 import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; 20 21 public class OrPattern extends SearchPattern implements IIndexConstants { 22 23 protected SearchPattern[] patterns; 24 25 28 30 33 int matchCompatibility; 34 35 public OrPattern(SearchPattern leftPattern, SearchPattern rightPattern) { 36 super(Math.max(leftPattern.getMatchRule(), rightPattern.getMatchRule())); 37 ((InternalSearchPattern)this).kind = OR_PATTERN; 38 ((InternalSearchPattern)this).mustResolve = ((InternalSearchPattern) leftPattern).mustResolve || ((InternalSearchPattern) rightPattern).mustResolve; 39 40 SearchPattern[] leftPatterns = leftPattern instanceof OrPattern ? ((OrPattern) leftPattern).patterns : null; 41 SearchPattern[] rightPatterns = rightPattern instanceof OrPattern ? ((OrPattern) rightPattern).patterns : null; 42 int leftSize = leftPatterns == null ? 1 : leftPatterns.length; 43 int rightSize = rightPatterns == null ? 1 : rightPatterns.length; 44 this.patterns = new SearchPattern[leftSize + rightSize]; 45 46 if (leftPatterns == null) 47 this.patterns[0] = leftPattern; 48 else 49 System.arraycopy(leftPatterns, 0, this.patterns, 0, leftSize); 50 if (rightPatterns == null) 51 this.patterns[leftSize] = rightPattern; 52 else 53 System.arraycopy(rightPatterns, 0, this.patterns, leftSize, rightSize); 54 55 matchCompatibility = 0; 57 for (int i = 0, length = this.patterns.length; i < length; i++) { 58 matchCompatibility |= ((JavaSearchPattern) this.patterns[i]).matchCompatibility; 59 } 60 } 61 void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor progressMonitor) throws IOException { 62 try { 64 index.startQuery(); 65 for (int i = 0, length = this.patterns.length; i < length; i++) 66 ((InternalSearchPattern)this.patterns[i]).findIndexMatches(index, requestor, participant, scope, progressMonitor); 67 } finally { 68 index.stopQuery(); 69 } 70 } 71 72 public SearchPattern getBlankPattern() { 73 return null; 74 } 75 76 boolean isErasureMatch() { 77 return (this.matchCompatibility & R_ERASURE_MATCH) != 0; 78 } 79 80 boolean isPolymorphicSearch() { 81 for (int i = 0, length = this.patterns.length; i < length; i++) 82 if (((InternalSearchPattern) this.patterns[i]).isPolymorphicSearch()) return true; 83 return false; 84 } 85 86 90 public final boolean hasSignatures() { 91 boolean isErasureMatch = isErasureMatch(); 92 for (int i = 0, length = this.patterns.length; i < length && !isErasureMatch; i++) { 93 if (((JavaSearchPattern) this.patterns[i]).hasSignatures()) return true; 94 } 95 return false; 96 } 97 98 public String toString() { 99 StringBuffer buffer = new StringBuffer (); 100 buffer.append(this.patterns[0].toString()); 101 for (int i = 1, length = this.patterns.length; i < length; i++) { 102 buffer.append("\n| "); buffer.append(this.patterns[i].toString()); 104 } 105 return buffer.toString(); 106 } 107 } 108 | Popular Tags |