1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
package xjavadoc;
|
6
|
|
|
7
|
|
import java.lang.reflect.Constructor;
|
8
|
|
import java.lang.reflect.AccessibleObject;
|
9
|
|
import java.lang.reflect.Method;
|
10
|
|
import java.util.List;
|
11
|
|
import java.util.Arrays;
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
final class BinaryClass extends AbstractClass
|
21
|
|
{
|
22
|
|
public static int instanceCount = 0;
|
23
|
|
|
24
|
|
private final static List _primitiveTypes = Arrays.asList( new String[]{
|
25
|
|
"java.lang.Boolean",
|
26
|
|
"java.lang.Byte",
|
27
|
|
"java.lang.Character",
|
28
|
|
"java.lang.Double",
|
29
|
|
"java.lang.Float",
|
30
|
|
"java.lang.Integer",
|
31
|
|
"java.lang.Long",
|
32
|
|
"java.lang.Short",
|
33
|
|
"java.lang.String"
|
34
|
|
} );
|
35
|
|
private final Class _clazz;
|
36
|
|
|
37
|
|
private boolean _isSuperclassSet = false;
|
38
|
|
|
39
|
|
private boolean _isInterfacesSet = false;
|
40
|
684
|
public BinaryClass( XJavaDoc xJavaDoc, Class clazz )
|
41
|
|
{
|
42
|
684
|
super( xJavaDoc, null );
|
43
|
684
|
_clazz = clazz;
|
44
|
684
|
setQualifiedName( clazz.getName() );
|
45
|
684
|
setContainingPackage( Util.getPackageNameFor( clazz.getName() ) );
|
46
|
|
|
47
|
684
|
addModifier( clazz.getModifiers() );
|
48
|
|
|
49
|
|
|
50
|
|
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
684
|
if( "true".equals( System.getProperty( "xjavadoc.compiledmethods" ) ) )
|
57
|
|
{
|
58
|
13
|
setMethods( _clazz );
|
59
|
13
|
setConstructors( _clazz );
|
60
|
|
}
|
61
|
684
|
instanceCount++;
|
62
|
|
}
|
63
|
|
|
64
|
519
|
private static int getDimension( Class c )
|
65
|
|
{
|
66
|
519
|
return c.getName().lastIndexOf( '[' ) + 1;
|
67
|
|
}
|
68
|
|
|
69
|
519
|
private static String getTypeName( Class c )
|
70
|
|
{
|
71
|
519
|
return c.getComponentType() != null ? c.getComponentType().getName() : c.getName();
|
72
|
|
}
|
73
|
|
|
74
|
387
|
public XClass getSuperclass()
|
75
|
|
{
|
76
|
387
|
setSuperclassMaybe();
|
77
|
387
|
return super.getSuperclass();
|
78
|
|
}
|
79
|
|
|
80
|
150
|
public List getInterfaces()
|
81
|
|
{
|
82
|
150
|
setInterfacesMaybe();
|
83
|
150
|
return super.getInterfaces();
|
84
|
|
}
|
85
|
|
|
86
|
|
|
87
|
|
|
88
|
|
|
89
|
|
|
90
|
|
|
91
|
0
|
public boolean isWriteable()
|
92
|
|
{
|
93
|
0
|
return false;
|
94
|
|
}
|
95
|
49
|
public boolean isImplementingInterface( String full_qualified_type_name, boolean superclasses )
|
96
|
|
{
|
97
|
49
|
return isClassImplementingInterface( _clazz, full_qualified_type_name, superclasses );
|
98
|
|
}
|
99
|
|
|
100
|
0
|
public boolean isSubclassOf( String full_qualified_type_name, boolean superclasses )
|
101
|
|
{
|
102
|
0
|
Class superclass = _clazz.getSuperclass();
|
103
|
|
|
104
|
0
|
if( superclass == null )
|
105
|
0
|
return false;
|
106
|
0
|
do
|
107
|
|
{
|
108
|
0
|
if( superclass.getName().equals( full_qualified_type_name ) )
|
109
|
0
|
return true;
|
110
|
|
|
111
|
0
|
superclass = superclass.getSuperclass();
|
112
|
0
|
}while ( superclasses == true && superclass != null );
|
113
|
|
|
114
|
0
|
return false;
|
115
|
|
}
|
116
|
|
|
117
|
0
|
public boolean isPrimitive()
|
118
|
|
{
|
119
|
0
|
return _primitiveTypes.contains( getQualifiedName() );
|
120
|
|
}
|
121
|
|
|
122
|
|
|
123
|
|
|
124
|
|
|
125
|
0
|
public void setDirty()
|
126
|
|
{
|
127
|
|
|
128
|
|
}
|
129
|
|
|
130
|
|
|
131
|
|
|
132
|
|
|
133
|
|
|
134
|
|
|
135
|
0
|
public boolean saveNeeded()
|
136
|
|
{
|
137
|
0
|
return false;
|
138
|
|
}
|
139
|
|
|
140
|
90
|
private boolean isClassImplementingInterface( Class cur_class, String full_qualified_type_name, boolean superclasses )
|
141
|
|
{
|
142
|
90
|
do
|
143
|
|
{
|
144
|
90
|
Class[] interfaces = cur_class.getInterfaces();
|
145
|
|
|
146
|
90
|
for( int i = 0; i < interfaces.length; i++ )
|
147
|
|
{
|
148
|
42
|
Class intf = interfaces[i];
|
149
|
|
|
150
|
42
|
if( intf.getName().equals( full_qualified_type_name ) || isClassImplementingInterface( intf, full_qualified_type_name, superclasses ) )
|
151
|
1
|
return true;
|
152
|
|
}
|
153
|
|
|
154
|
89
|
cur_class = cur_class.getSuperclass();
|
155
|
89
|
}while ( superclasses == true && cur_class != null );
|
156
|
|
|
157
|
89
|
return false;
|
158
|
|
}
|
159
|
|
|
160
|
387
|
private void setSuperclassMaybe()
|
161
|
|
{
|
162
|
387
|
if( !_isSuperclassSet )
|
163
|
|
{
|
164
|
83
|
Class superclass = _clazz.getSuperclass();
|
165
|
|
|
166
|
83
|
if( superclass != null )
|
167
|
|
{
|
168
|
15
|
setSuperclass( superclass.getName() );
|
169
|
|
}
|
170
|
83
|
_isSuperclassSet = true;
|
171
|
|
}
|
172
|
|
}
|
173
|
|
|
174
|
150
|
private void setInterfacesMaybe()
|
175
|
|
{
|
176
|
150
|
if( !_isInterfacesSet )
|
177
|
|
{
|
178
|
81
|
Class[] interfaces = _clazz.getInterfaces();
|
179
|
|
|
180
|
81
|
for( int i = 0; i < interfaces.length; i++ )
|
181
|
|
{
|
182
|
49
|
addInterface( interfaces[i].getName() );
|
183
|
|
}
|
184
|
81
|
_isInterfacesSet = true;
|
185
|
|
}
|
186
|
|
}
|
187
|
|
|
188
|
|
|
189
|
|
|
190
|
|
|
191
|
|
|
192
|
|
|
193
|
13
|
private void setConstructors( Class clazz )
|
194
|
|
{
|
195
|
13
|
Constructor[] constructors = clazz.getDeclaredConstructors();
|
196
|
|
|
197
|
13
|
for( int i = 0; i < constructors.length; i++ )
|
198
|
|
{
|
199
|
28
|
ConstructorImpl constructor = new ConstructorImpl( this, null );
|
200
|
|
|
201
|
28
|
constructor.addModifier( constructors[i].getModifiers() );
|
202
|
28
|
populateExecutableMember( constructor, constructors[i] );
|
203
|
28
|
addConstructor( constructor );
|
204
|
|
}
|
205
|
|
}
|
206
|
|
|
207
|
|
|
208
|
|
|
209
|
|
|
210
|
|
|
211
|
|
|
212
|
13
|
private void setMethods( Class clazz )
|
213
|
|
{
|
214
|
13
|
Method[] methods = clazz.getDeclaredMethods();
|
215
|
|
|
216
|
13
|
for( int i = 0; i < methods.length; i++ )
|
217
|
|
{
|
218
|
|
|
219
|
218
|
if( !"<clinit>".equals( methods[i].getName() ) )
|
220
|
|
{
|
221
|
218
|
MethodImpl method = new MethodImpl( this, null );
|
222
|
|
|
223
|
218
|
method.setName( methods[i].getName() );
|
224
|
|
|
225
|
218
|
method.addModifier( methods[i].getModifiers() );
|
226
|
218
|
populateExecutableMember( method, methods[i] );
|
227
|
|
|
228
|
218
|
Class returnType = methods[i].getReturnType();
|
229
|
|
|
230
|
218
|
String typeName = getTypeName( returnType );
|
231
|
218
|
int dimension = getDimension( returnType );
|
232
|
|
|
233
|
218
|
method.setReturnType( typeName );
|
234
|
218
|
method.setReturnDimension( dimension );
|
235
|
218
|
addMethod( method );
|
236
|
|
}
|
237
|
|
}
|
238
|
|
}
|
239
|
|
|
240
|
246
|
private void populateExecutableMember( AbstractExecutableMember executableMember, AccessibleObject accessibleObject )
|
241
|
|
{
|
242
|
246
|
Class[] parameters;
|
243
|
246
|
Class[] exceptions;
|
244
|
|
|
245
|
|
|
246
|
246
|
if( accessibleObject instanceof Constructor )
|
247
|
|
{
|
248
|
28
|
parameters = ( ( Constructor ) accessibleObject ).getParameterTypes();
|
249
|
28
|
exceptions = ( ( Constructor ) accessibleObject ).getExceptionTypes();
|
250
|
|
}
|
251
|
|
else
|
252
|
|
{
|
253
|
|
|
254
|
218
|
parameters = ( ( Method ) accessibleObject ).getParameterTypes();
|
255
|
218
|
exceptions = ( ( Method ) accessibleObject ).getExceptionTypes();
|
256
|
|
}
|
257
|
246
|
for( int i = parameters.length - 1; i >= 0; i-- )
|
258
|
|
{
|
259
|
301
|
String typeName = getTypeName( parameters[i] );
|
260
|
301
|
int dimension = getDimension( parameters[i] );
|
261
|
|
|
262
|
301
|
executableMember.addParameterData( typeName, "p" + i, dimension );
|
263
|
|
}
|
264
|
246
|
for( int i = exceptions.length - 1; i >= 0; i-- )
|
265
|
|
{
|
266
|
126
|
executableMember.addThrownException( exceptions[i].getName() );
|
267
|
|
}
|
268
|
|
}
|
269
|
|
}
|
270
|
|
|