01: // Transmogrify License
02: //
03: // Copyright (c) 2001, ThoughtWorks, Inc.
04: // All rights reserved.
05: // Redistribution and use in source and binary forms, with or without
06: // modification, are permitted provided that the following conditions
07: // are met:
08: // - Redistributions of source code must retain the above copyright notice,
09: // this list of conditions and the following disclaimer.
10: // - Redistributions in binary form must reproduce the above copyright
11: // notice, this list of conditions and the following disclaimer in the
12: // documentation and/or other materials provided with the distribution.
13: // Neither the name of the ThoughtWorks, Inc. nor the names of its
14: // contributors may be used to endorse or promote products derived from this
15: // software without specific prior written permission.
16: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18: // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19: // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20: // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21: // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22: // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23: // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24: // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25: // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26: // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27:
28: package com.puppycrawl.tools.checkstyle.checks.usage.transmogrify;
29:
30: import java.util.Iterator;
31: import java.util.NoSuchElementException;
32:
33: /**
34: * An iterator for the children of a tree node.
35: *
36: * @version 1.0
37: * @since 1.0
38: * @see Iterator
39: */
40: public class SymTabASTIterator implements Iterator {
41: private SymTabAST _current;
42:
43: /**
44: * Creates a new <tt>SymTabASTIterator</tt>.
45: *
46: * @param parent the node whose children will be iterated over.
47: */
48: public SymTabASTIterator(SymTabAST parent) {
49: _current = (SymTabAST) parent.getFirstChild();
50: }
51:
52: /**
53: * Whether the node has another child. (In other words, returns
54: * <tt>true</tt> if <tt>next</tt> would return an element rather than
55: * throwing an exception.)
56: *
57: * @return the next child node.
58: */
59: public boolean hasNext() {
60: return (_current != null);
61: }
62:
63: /**
64: * The next child node.
65: *
66: * @return the next child node.
67: */
68: public Object next() {
69: if (!hasNext()) {
70: throw new NoSuchElementException();
71: }
72:
73: Object result = _current;
74: _current = (SymTabAST) _current.getNextSibling();
75:
76: return result;
77: }
78:
79: /**
80: * The next child node.
81: *
82: * @return the next child node.
83: */
84: public SymTabAST nextChild() {
85: return (SymTabAST) next();
86: }
87:
88: /**
89: * Unsupported operation
90: */
91: public void remove() {
92: throw new UnsupportedOperationException();
93: }
94: }
|