Minimize
Table
Bug Overview
line | bug priority | bug | bug description | existing since | author |
---|
222 | medium | IL_INFINITE_LOOP | Diese Schleife terminiert nicht. Bitte Code überprüfen! Falls dies beabsichtigt ist und der Fehler soll ignoriert werden, dann //NOBUG verwenden. | 18.06.2012-10:31 | Unbekannt |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.groovy.syntax;
18
19 import org.codehaus.groovy.GroovyBugError;
20
21 import java.util.List;
22 import java.util.ArrayList;
23 import java.util.Collections;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public class Reduction extends CSTNode
41 {
42 public static final Reduction EMPTY = new Reduction();
43
44
45
46
47
48 private List elements = null;
49 private boolean marked = false;
50
51
52
53
54
55
56 public Reduction( Token root )
57 {
58 elements = new ArrayList();
59 set( 0, root );
60 }
61
62
63
64
65
66
67 private Reduction()
68 {
69 elements = Collections.EMPTY_LIST;
70 }
71
72
73
74
75
76
77
78 public static Reduction newContainer()
79 {
80 return new Reduction( Token.NULL );
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94 public boolean isEmpty()
95 {
96 return size() == 0;
97 }
98
99
100
101
102
103
104
105 public int size()
106 {
107 return elements.size();
108 }
109
110
111
112
113
114
115
116 public CSTNode get( int index )
117 {
118 CSTNode element = null;
119
120 if( index < size() )
121 {
122 element = (CSTNode)elements.get( index );
123 }
124
125 return element;
126 }
127
128
129
130
131
132
133
134
135
136 public Token getRoot()
137 {
138 if( size() > 0 )
139 {
140 return (Token)elements.get(0);
141 }
142 else
143 {
144 return null;
145 }
146 }
147
148
149
150
151
152
153
154 public void markAsExpression()
155 {
156 marked = true;
157 }
158
159
160
161
162
163
164
165 public boolean isAnExpression()
166 {
167 if( isA(Types.COMPLEX_EXPRESSION) )
168 {
169 return true;
170 }
171
172 return marked;
173 }
174
175
176
177
178
179
180
181
182
183
184
185
186 public CSTNode add( CSTNode element )
187 {
188 return set( size(), element );
189 }
190
191
192
193
194
195
196
197 public CSTNode set( int index, CSTNode element )
198 {
199
200 if( elements == null )
201 {
202 throw new GroovyBugError( "attempt to set() on a EMPTY Reduction" );
203 }
204
205 if( index == 0 && !(element instanceof Token) )
206 {
207
208
209
210
211
212 throw new GroovyBugError( "attempt to set() a non-Token as root of a Reduction" );
213 }
214
215
216
217
218
219 int count = elements.size();
220 if( index >= count )
221 {
IL_INFINITE_LOOP
223 {
224 elements.add( null );
225 }
226 }
227
228
229
230
231 elements.set( index, element );
232
233 return element;
234 }
235
236
237
238
239
240
241
242
243 public CSTNode remove( int index )
244 {
245 if( index < 1 )
246 {
247 throw new GroovyBugError( "attempt to remove() root node of Reduction" );
248 }
249
250 return (CSTNode)elements.remove( index );
251 }
252
253
254
255
256
257
258
259
260 public Reduction asReduction()
261 {
262 return this;
263 }
264
265 }
266