01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.core.search.matching;
11:
12: import org.eclipse.jdt.core.search.SearchPattern;
13:
14: public class AndPattern extends IntersectingPattern {
15: protected SearchPattern[] patterns;
16: int current;
17:
18: private static int combinedMatchRule(int matchRule, int matchRule2) {
19: int combined = matchRule & matchRule2;
20: int compatibility = combined & MATCH_COMPATIBILITY_MASK;
21: if (compatibility == 0) {
22: if ((matchRule & MATCH_COMPATIBILITY_MASK) == R_FULL_MATCH) {
23: compatibility = matchRule2;
24: } else if ((matchRule2 & MATCH_COMPATIBILITY_MASK) == R_FULL_MATCH) {
25: compatibility = matchRule;
26: } else {
27: compatibility = Math.min(matchRule
28: & MATCH_COMPATIBILITY_MASK, matchRule2
29: & MATCH_COMPATIBILITY_MASK);
30: }
31: }
32: return (combined & (R_EXACT_MATCH | R_PREFIX_MATCH
33: | R_PATTERN_MATCH | R_REGEXP_MATCH))
34: | (combined & R_CASE_SENSITIVE)
35: | compatibility
36: | (combined & R_CAMEL_CASE_MATCH);
37: }
38:
39: public AndPattern(SearchPattern leftPattern,
40: SearchPattern rightPattern) {
41: super (AND_PATTERN,
42: combinedMatchRule(leftPattern.getMatchRule(),
43: rightPattern.getMatchRule()));
44: ((InternalSearchPattern) this ).mustResolve = ((InternalSearchPattern) leftPattern).mustResolve
45: || ((InternalSearchPattern) rightPattern).mustResolve;
46:
47: SearchPattern[] leftPatterns = leftPattern instanceof AndPattern ? ((AndPattern) leftPattern).patterns
48: : null;
49: SearchPattern[] rightPatterns = rightPattern instanceof AndPattern ? ((AndPattern) rightPattern).patterns
50: : null;
51: int leftSize = leftPatterns == null ? 1 : leftPatterns.length;
52: int rightSize = rightPatterns == null ? 1
53: : rightPatterns.length;
54: this .patterns = new SearchPattern[leftSize + rightSize];
55:
56: if (leftPatterns == null)
57: this .patterns[0] = leftPattern;
58: else
59: System.arraycopy(leftPatterns, 0, this .patterns, 0,
60: leftSize);
61: if (rightPatterns == null)
62: this .patterns[leftSize] = rightPattern;
63: else
64: System.arraycopy(rightPatterns, 0, this .patterns, leftSize,
65: rightSize);
66:
67: // Store erasure match
68: matchCompatibility = getMatchRule() & MATCH_COMPATIBILITY_MASK;
69:
70: this .current = 0;
71: }
72:
73: /* (non-Javadoc)
74: * @see org.eclipse.jdt.internal.core.search.matching.InternalSearchPattern#currentPattern()
75: */
76: SearchPattern currentPattern() {
77: return this .patterns[this .current++];
78: }
79:
80: protected boolean hasNextQuery() {
81: return this .current < (this .patterns.length - 1);
82: }
83:
84: protected void resetQuery() {
85: this .current = 0;
86: }
87:
88: }
|