KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > usage > transmogrify > DotIterator


1 // Transmogrify License
2
//
3
// Copyright (c) 2001, ThoughtWorks, Inc.
4
// All rights reserved.
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions
7
// are met:
8
// - Redistributions of source code must retain the above copyright notice,
9
// 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.ArrayList JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
35
36 /**
37  * An iterator for dot ('.') delimited tokens.
38  *
39  * @version 1.0
40  * @since 1.0
41  * @see Iterator
42  */

43 public class DotIterator implements Iterator JavaDoc {
44     Iterator JavaDoc _nodesIter;
45     List JavaDoc _nodes;
46
47     public DotIterator(SymTabAST topNode)
48     {
49         _nodes = new ArrayList JavaDoc();
50         makeNodes(topNode);
51         _nodesIter = _nodes.iterator();
52     }
53
54     private void makeNodes(SymTabAST node)
55     {
56         if (node.getType() == TokenTypes.DOT) {
57             SymTabAST left = (SymTabAST) node.getFirstChild();
58             SymTabAST right = (SymTabAST) left.getNextSibling();
59
60             makeNodes(left);
61             makeNodes(right);
62         }
63         else {
64             _nodes.add(node);
65         }
66     }
67
68     /**
69      * Returns true if the iteration has more elements. (In other words,
70      * returns true if next would return an element rather than throwing an
71      * exception.)
72      *
73      * @return <tt>true</tt> if the iterator has more elements.
74      */

75     public boolean hasNext()
76     {
77         return _nodesIter.hasNext();
78     }
79
80     /**
81      * Returns the next portion of the dotted name.
82      *
83      * @return the next node in the dotted name.
84      */

85     public Object JavaDoc next()
86     {
87         return _nodesIter.next();
88     }
89
90     /**
91      * Returns the next portion of the dotted name.
92      *
93      * @return the next node in the dotted name.
94      */

95     public SymTabAST nextNode()
96     {
97         return (SymTabAST) _nodesIter.next();
98     }
99
100     /**
101      * Unsupported operation.
102      *
103      */

104     public void remove()
105     {
106         throw new UnsupportedOperationException JavaDoc();
107     }
108 }
109
Popular Tags