1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
package xjavadoc;
|
6
|
|
|
7
|
|
import java.util.ArrayList;
|
8
|
|
import java.util.List;
|
9
|
|
import java.util.Collections;
|
10
|
|
import java.util.Iterator;
|
11
|
|
import java.lang.reflect.Modifier;
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
abstract class AbstractExecutableMember extends MemberImpl implements XExecutableMember
|
20
|
|
{
|
21
|
|
|
22
|
|
|
23
|
|
|
24
|
|
|
25
|
|
private final static int MAX_ARRAY_SIZE = 6;
|
26
|
|
private final static Integer[] _dimensions = new Integer[MAX_ARRAY_SIZE];
|
27
|
|
|
28
|
|
|
29
|
|
|
30
|
|
|
31
|
|
|
32
|
|
private final static int PARAMETER_DATA_SIZE = 2;
|
33
|
|
|
34
|
|
|
35
|
|
|
36
|
|
|
37
|
|
|
38
|
|
private final static int INITIAL_PARAMETER_POOL_SIZE = 20;
|
39
|
|
private static ParameterImpl[] _parameterPool = new ParameterImpl[INITIAL_PARAMETER_POOL_SIZE];
|
40
|
|
private List _thrownExceptions;
|
41
|
|
private List _parameterData;
|
42
|
|
private String _nameWithSignature;
|
43
|
|
private String _signature;
|
44
|
|
private String _stringId;
|
45
|
|
|
46
|
|
static
|
47
|
|
{
|
48
|
18
|
for( int i = 0; i < MAX_ARRAY_SIZE; i++ )
|
49
|
|
{
|
50
|
108
|
_dimensions[i] = new Integer( i );
|
51
|
|
}
|
52
|
|
}
|
53
|
|
|
54
|
|
static
|
55
|
|
{
|
56
|
18
|
for( int i = 0; i < INITIAL_PARAMETER_POOL_SIZE; i++ )
|
57
|
|
{
|
58
|
360
|
_parameterPool[i] = new ParameterImpl();
|
59
|
|
}
|
60
|
|
}
|
61
|
|
|
62
|
9258
|
protected AbstractExecutableMember( AbstractClass containingClass, XTagFactory tagFactory )
|
63
|
|
{
|
64
|
9258
|
super( containingClass, tagFactory );
|
65
|
9258
|
if( containingClass == null )
|
66
|
|
{
|
67
|
0
|
throw new IllegalArgumentException( "containingClass can't be null" );
|
68
|
|
}
|
69
|
|
}
|
70
|
|
|
71
|
746
|
private final static String toString( XParameter parameter, boolean withParam )
|
72
|
|
{
|
73
|
746
|
if( parameter == null )
|
74
|
|
{
|
75
|
0
|
throw new IllegalStateException( "parameter can't be null!" );
|
76
|
|
}
|
77
|
|
|
78
|
746
|
StringBuffer sb = new StringBuffer( parameter.getType().getQualifiedName() );
|
79
|
|
|
80
|
746
|
Util.appendDimensionAsString( parameter.getDimension(), sb );
|
81
|
746
|
if( withParam )
|
82
|
|
{
|
83
|
0
|
sb.append( " " ).append( parameter.getName() );
|
84
|
|
}
|
85
|
746
|
return sb.toString();
|
86
|
|
}
|
87
|
|
|
88
|
|
|
89
|
|
|
90
|
|
|
91
|
|
|
92
|
|
|
93
|
0
|
public final boolean isNative()
|
94
|
|
{
|
95
|
0
|
return ( getModifierSpecifier() & Modifier.NATIVE ) != 0;
|
96
|
|
}
|
97
|
|
|
98
|
|
|
99
|
|
|
100
|
|
|
101
|
|
|
102
|
|
|
103
|
0
|
public final boolean isSynchronized()
|
104
|
|
{
|
105
|
0
|
return ( getModifierSpecifier() & Modifier.SYNCHRONIZED ) != 0;
|
106
|
|
}
|
107
|
|
|
108
|
|
|
109
|
|
|
110
|
|
|
111
|
|
|
112
|
|
|
113
|
3342
|
public final List getParameters()
|
114
|
|
{
|
115
|
3342
|
List parameters = null;
|
116
|
|
|
117
|
3342
|
if( _parameterData == null )
|
118
|
|
{
|
119
|
1950
|
parameters = EMPTY_LIST;
|
120
|
|
}
|
121
|
|
else
|
122
|
|
{
|
123
|
1392
|
int requiredSize = _parameterData.size() / 3;
|
124
|
|
|
125
|
1392
|
parameters = new ArrayList( requiredSize );
|
126
|
1392
|
if( _parameterPool.length < requiredSize )
|
127
|
|
{
|
128
|
|
|
129
|
0
|
ParameterImpl[] newPool = new ParameterImpl[requiredSize];
|
130
|
|
|
131
|
0
|
System.arraycopy( _parameterPool, 0, newPool, 0, _parameterPool.length );
|
132
|
0
|
for( int j = _parameterPool.length; j < newPool.length; j++ )
|
133
|
|
{
|
134
|
0
|
newPool[j] = new ParameterImpl();
|
135
|
|
}
|
136
|
0
|
_parameterPool = newPool;
|
137
|
|
}
|
138
|
|
|
139
|
1392
|
for( int i = 0; i < requiredSize; i++ )
|
140
|
|
{
|
141
|
1910
|
try
|
142
|
|
{
|
143
|
1910
|
_parameterPool[i].setState( this, i );
|
144
|
1910
|
parameters.add( _parameterPool[i] );
|
145
|
|
}
|
146
|
|
catch( IndexOutOfBoundsException e )
|
147
|
|
{
|
148
|
0
|
throw new IllegalStateException( "In member " + getName() + ". Tried to set " + i + "th parameter. Size was " + requiredSize );
|
149
|
|
}
|
150
|
|
}
|
151
|
|
}
|
152
|
3342
|
return Collections.unmodifiableList( parameters );
|
153
|
|
}
|
154
|
|
|
155
|
|
|
156
|
|
|
157
|
|
|
158
|
|
|
159
|
|
|
160
|
|
|
161
|
|
|
162
|
0
|
public final String getSignature( boolean withParam )
|
163
|
|
{
|
164
|
0
|
if( _signature == null )
|
165
|
|
{
|
166
|
0
|
_signature = appendSignature( new StringBuffer(), withParam ).toString();
|
167
|
|
}
|
168
|
0
|
return _signature;
|
169
|
|
}
|
170
|
|
|
171
|
|
|
172
|
|
|
173
|
|
|
174
|
|
|
175
|
|
|
176
|
|
|
177
|
|
|
178
|
3474
|
public final String getNameWithSignature( boolean withParam )
|
179
|
|
{
|
180
|
3474
|
if( _nameWithSignature == null )
|
181
|
|
{
|
182
|
1392
|
_nameWithSignature = appendSignature( new StringBuffer( getName() ), withParam ).toString();
|
183
|
|
}
|
184
|
3474
|
return _nameWithSignature;
|
185
|
|
}
|
186
|
|
|
187
|
0
|
public String getParameterTypes()
|
188
|
|
{
|
189
|
0
|
StringBuffer sb = new StringBuffer();
|
190
|
|
|
191
|
0
|
for( Iterator i = getParameters().iterator(); i.hasNext(); )
|
192
|
|
{
|
193
|
|
|
194
|
0
|
( ( XParameter ) i.next() ).getType();
|
195
|
|
}
|
196
|
|
|
197
|
0
|
boolean comma = false;
|
198
|
|
|
199
|
0
|
for( Iterator i = getParameters().iterator(); i.hasNext(); )
|
200
|
|
{
|
201
|
|
|
202
|
|
|
203
|
|
|
204
|
|
|
205
|
|
|
206
|
0
|
if( comma )
|
207
|
|
{
|
208
|
0
|
sb.append( ',' );
|
209
|
|
}
|
210
|
|
|
211
|
0
|
XParameter parameter = ( XParameter ) i.next();
|
212
|
|
|
213
|
0
|
sb.append( parameter.getType().getType() );
|
214
|
0
|
comma = true;
|
215
|
|
}
|
216
|
0
|
return sb.toString();
|
217
|
|
}
|
218
|
|
|
219
|
12
|
public List getThrownExceptions()
|
220
|
|
{
|
221
|
12
|
return _thrownExceptions == null ? EMPTY_LIST : Collections.unmodifiableList( getQualifiedExceptions() );
|
222
|
|
}
|
223
|
|
|
224
|
528
|
public XProgramElement getSuperElement( boolean forMethod )
|
225
|
|
{
|
226
|
528
|
XClass superclass = getContainingClass().getSuperclass();
|
227
|
|
|
228
|
528
|
while( superclass != null )
|
229
|
|
{
|
230
|
770
|
XExecutableMember superExecutableMember;
|
231
|
|
|
232
|
770
|
if( forMethod )
|
233
|
|
{
|
234
|
770
|
superExecutableMember = superclass.getMethod( getNameWithSignature( false ) );
|
235
|
|
}
|
236
|
|
else
|
237
|
|
{
|
238
|
|
|
239
|
0
|
superExecutableMember = superclass.getConstructor( getNameWithSignature( false ) );
|
240
|
|
}
|
241
|
770
|
if( superExecutableMember != null )
|
242
|
|
{
|
243
|
20
|
return superExecutableMember;
|
244
|
|
}
|
245
|
|
else
|
246
|
|
{
|
247
|
750
|
superclass = superclass.getSuperclass();
|
248
|
|
}
|
249
|
|
}
|
250
|
508
|
return null;
|
251
|
|
}
|
252
|
|
|
253
|
0
|
public boolean throwsException( String exception_class_name )
|
254
|
|
{
|
255
|
|
|
256
|
0
|
for( Iterator iterator = getThrownExceptions().iterator(); iterator.hasNext(); )
|
257
|
|
{
|
258
|
0
|
XClass exception = (XClass) iterator.next();
|
259
|
|
|
260
|
0
|
if( exception.getQualifiedName().equals( exception_class_name ) )
|
261
|
0
|
return true;
|
262
|
|
}
|
263
|
|
|
264
|
0
|
return false;
|
265
|
|
}
|
266
|
|
|
267
|
|
|
268
|
|
|
269
|
|
|
270
|
|
|
271
|
|
|
272
|
|
|
273
|
|
|
274
|
5730
|
public void addParameterData( String type, String name, int dimension )
|
275
|
|
{
|
276
|
5730
|
if( _parameterData == null )
|
277
|
|
{
|
278
|
3960
|
_parameterData = new ArrayList( PARAMETER_DATA_SIZE * 3 );
|
279
|
|
}
|
280
|
5730
|
_parameterData.add( type );
|
281
|
5730
|
_parameterData.add( name );
|
282
|
5730
|
_parameterData.add( _dimensions[dimension] );
|
283
|
|
}
|
284
|
|
|
285
|
762
|
public void addThrownException( String thrownException )
|
286
|
|
{
|
287
|
762
|
if( _thrownExceptions == null )
|
288
|
|
{
|
289
|
682
|
_thrownExceptions = new ArrayList();
|
290
|
|
}
|
291
|
762
|
_thrownExceptions.add( thrownException );
|
292
|
|
}
|
293
|
|
|
294
|
0
|
public boolean equals( Object o )
|
295
|
|
{
|
296
|
0
|
if( !( o.getClass() == getClass() ) )
|
297
|
|
{
|
298
|
0
|
return false;
|
299
|
|
}
|
300
|
|
|
301
|
0
|
AbstractExecutableMember other = ( AbstractExecutableMember ) o;
|
302
|
|
|
303
|
0
|
return stringId().equals( other.stringId() );
|
304
|
|
}
|
305
|
|
|
306
|
0
|
public int hashCode()
|
307
|
|
{
|
308
|
0
|
return stringId().hashCode();
|
309
|
|
}
|
310
|
|
|
311
|
0
|
public String toString()
|
312
|
|
{
|
313
|
0
|
return stringId();
|
314
|
|
}
|
315
|
|
|
316
|
|
protected abstract String buildStringId();
|
317
|
|
|
318
|
1884
|
final String getParameterType( int index )
|
319
|
|
{
|
320
|
1884
|
return ( String ) _parameterData.get( index * 3 );
|
321
|
|
}
|
322
|
|
|
323
|
388
|
final String getParameterName( int index )
|
324
|
|
{
|
325
|
388
|
return ( String ) _parameterData.get( index * 3 + 1 );
|
326
|
|
}
|
327
|
|
|
328
|
1138
|
final int getParameterDimension( int index )
|
329
|
|
{
|
330
|
1138
|
return ( ( Integer ) _parameterData.get( index * 3 + 2 ) ).intValue();
|
331
|
|
}
|
332
|
|
|
333
|
0
|
private List getQualifiedExceptions()
|
334
|
|
{
|
335
|
|
|
336
|
0
|
if( _thrownExceptions.get( 0 ) instanceof String )
|
337
|
|
{
|
338
|
0
|
List qualified_thrown_exceptions = new ArrayList();
|
339
|
|
|
340
|
0
|
for( Iterator iterator = _thrownExceptions.iterator(); iterator.hasNext(); )
|
341
|
|
{
|
342
|
0
|
String exception_class_name = ( String ) iterator.next();
|
343
|
|
|
344
|
0
|
qualified_thrown_exceptions.add( getContainingAbstractClass().qualify( exception_class_name ) );
|
345
|
|
}
|
346
|
|
|
347
|
0
|
_thrownExceptions = qualified_thrown_exceptions;
|
348
|
|
}
|
349
|
|
|
350
|
0
|
return _thrownExceptions;
|
351
|
|
}
|
352
|
|
|
353
|
|
|
354
|
|
|
355
|
|
|
356
|
|
|
357
|
|
|
358
|
0
|
private final String stringId()
|
359
|
|
{
|
360
|
0
|
if( _stringId == null )
|
361
|
|
{
|
362
|
0
|
_stringId = buildStringId();
|
363
|
|
}
|
364
|
0
|
return _stringId;
|
365
|
|
}
|
366
|
|
|
367
|
1392
|
private final StringBuffer appendSignature( StringBuffer sb, boolean withParam )
|
368
|
|
{
|
369
|
1392
|
sb.append( '(' );
|
370
|
|
|
371
|
1392
|
for( Iterator i = getParameters().iterator(); i.hasNext(); )
|
372
|
|
{
|
373
|
|
|
374
|
746
|
( ( XParameter ) i.next() ).getType();
|
375
|
|
}
|
376
|
|
|
377
|
1392
|
boolean comma = false;
|
378
|
|
|
379
|
1392
|
for( Iterator i = getParameters().iterator(); i.hasNext(); )
|
380
|
|
{
|
381
|
|
|
382
|
|
|
383
|
|
|
384
|
|
|
385
|
|
|
386
|
746
|
if( comma )
|
387
|
|
{
|
388
|
202
|
sb.append( ',' );
|
389
|
|
}
|
390
|
746
|
sb.append( toString( ( XParameter ) i.next(), withParam ) );
|
391
|
746
|
comma = true;
|
392
|
|
}
|
393
|
1392
|
return sb.append( ')' );
|
394
|
|
}
|
395
|
|
}
|
396
|
|
|