001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Nikolay A. Kuznetsov
020: * @version $Revision: 1.14.2.2 $
021: */package java.util.regex;
022:
023: /**
024: * Base class for quantifiers.
025: *
026: * @author Nikolay A. Kuznetsov
027: * @version $Revision: 1.14.2.2 $
028: */
029: abstract class QuantifierSet extends AbstractSet {
030:
031: protected AbstractSet innerSet;
032:
033: public QuantifierSet(AbstractSet innerSet, AbstractSet next,
034: int type) {
035: super (next);
036: this .innerSet = innerSet;
037: setType(type);
038: }
039:
040: /**
041: * Returns the innerSet.
042: */
043: public AbstractSet getInnerSet() {
044: return innerSet;
045: }
046:
047: /**
048: * Sets an inner set.
049: * @param innerSet
050: * The innerSet to set.
051: */
052: public void setInnerSet(AbstractSet innerSet) {
053: this .innerSet = innerSet;
054: }
055:
056: public boolean first(AbstractSet set) {
057: return innerSet.first(set) || next.first(set);
058: }
059:
060: public boolean hasConsumed(MatchResultImpl mr) {
061: return true;
062: }
063:
064: /**
065: * This method is used for traversing nodes after the
066: * first stage of compilation.
067: */
068: public void processSecondPass() {
069: this .isSecondPassVisited = true;
070:
071: if (next != null) {
072:
073: if (!next.isSecondPassVisited) {
074:
075: /*
076: * Add here code to do during the pass
077: */
078: JointSet set = next.processBackRefReplacement();
079:
080: if (set != null) {
081: next.isSecondPassVisited = true;
082: next = (AbstractSet) set;
083: }
084:
085: /*
086: * End code to do during the pass
087: */
088: next.processSecondPass();
089: }
090: }
091:
092: if (innerSet != null) {
093:
094: if (!innerSet.isSecondPassVisited) {
095:
096: /*
097: * Add here code to do during the pass
098: */
099: JointSet set = innerSet.processBackRefReplacement();
100:
101: if (set != null) {
102: innerSet.isSecondPassVisited = true;
103: innerSet = (AbstractSet) set;
104: }
105:
106: /*
107: * End code to do during the pass
108: */
109: innerSet.processSecondPass();
110: } else {
111:
112: /*
113: * We reach node through innerSet but it is already traversed.
114: * You can see this situation for GroupQuantifierSet.innerset
115: * if we compile smth like "(a)+ when
116: * GroupQuantifierSet == GroupQuantifierSet.innerset.fSet.next
117: */
118:
119: /*
120: * Add here code to do during the pass
121: */
122: if (innerSet instanceof SingleSet
123: && ((FSet) ((JointSet) innerSet).fSet).isBackReferenced) {
124: innerSet = innerSet.next;
125: }
126:
127: /*
128: * End code to do during the pass
129: */
130: }
131: }
132: }
133: }
|