11
11
import com .telerik .metadata .TreeNode .FieldInfo ;
12
12
import com .telerik .metadata .TreeNode .MethodInfo ;
13
13
import com .telerik .metadata .bcl .JarFile ;
14
+ import com .telerik .metadata .desc .MetadataInfoAnnotationDescriptor ;
14
15
import com .telerik .metadata .desc .ClassDescriptor ;
15
16
import com .telerik .metadata .desc .FieldDescriptor ;
16
17
import com .telerik .metadata .desc .MethodDescriptor ;
@@ -94,12 +95,24 @@ private static void generate(ClassDescriptor clazz, TreeNode root) throws Except
94
95
if (!isClassPublic (clazz )) {
95
96
return ;
96
97
}
97
- TreeNode node = getOrCreateNode (root , clazz );
98
98
99
- setNodeMembers (clazz , node , root );
99
+ MetadataInfoAnnotationDescriptor metadataInfo = clazz .getMetadataInfoAnnotation ();
100
+ boolean hasClassMetadataInfo = metadataInfo != null ;
101
+ String predefinedSuperClassname = null ;
102
+ if (hasClassMetadataInfo ) {
103
+ if (metadataInfo .skip ()) {
104
+ return ;
105
+ } else {
106
+ predefinedSuperClassname = metadataInfo .getSuperClassname ();
107
+ }
108
+ }
109
+
110
+ TreeNode node = getOrCreateNode (root , clazz , predefinedSuperClassname );
111
+
112
+ setNodeMembers (clazz , node , root , hasClassMetadataInfo );
100
113
}
101
114
102
- private static void setNodeMembers (ClassDescriptor clazz , TreeNode node , TreeNode root ) throws Exception {
115
+ private static void setNodeMembers (ClassDescriptor clazz , TreeNode node , TreeNode root , boolean hasClassMetadataInfo ) throws Exception {
103
116
Map <String , MethodInfo > existingMethods = new HashMap <String , MethodInfo >();
104
117
for (MethodInfo mi : node .instanceMethods ) {
105
118
existingMethods .put (mi .name + mi .sig , mi );
@@ -114,6 +127,13 @@ private static void setNodeMembers(ClassDescriptor clazz, TreeNode node, TreeNod
114
127
if (m .isSynthetic ())
115
128
continue ;
116
129
130
+ if (hasClassMetadataInfo && !m .getName ().equals ("<init>" )) {
131
+ MetadataInfoAnnotationDescriptor metadataInfo = m .getMetadataInfoAnnotation ();
132
+ if ((metadataInfo != null ) && metadataInfo .skip ()) {
133
+ continue ;
134
+ }
135
+ }
136
+
117
137
if (m .isPublic () || m .isProtected ()) {
118
138
boolean isStatic = m .isStatic ();
119
139
@@ -139,7 +159,7 @@ private static void setNodeMembers(ClassDescriptor clazz, TreeNode node, TreeNod
139
159
140
160
if (mi .signature != null ) {
141
161
if (isStatic ) {
142
- mi .declaringType = getOrCreateNode (root , clazz );
162
+ mi .declaringType = getOrCreateNode (root , clazz , null );
143
163
node .staticMethods .add (mi );
144
164
} else {
145
165
String sig = m .getName () + m .getSignature ();
@@ -174,10 +194,10 @@ private static void setFieldInfo(ClassDescriptor clazz, TreeNode node, TreeNode
174
194
if (f .isStatic ()) {
175
195
if (interfaceClass != null ) {
176
196
// changes declaring type of static fields from implementing class to interface
177
- fi .declaringType = getOrCreateNode (root , interfaceClass );
197
+ fi .declaringType = getOrCreateNode (root , interfaceClass , null );
178
198
}
179
199
else {
180
- fi .declaringType = getOrCreateNode (root , clazz );
200
+ fi .declaringType = getOrCreateNode (root , clazz , null );
181
201
}
182
202
node .staticFields .add (fi );
183
203
} else {
@@ -224,13 +244,13 @@ private static TreeNode getOrCreateNode(TreeNode root, TypeDescriptor type)
224
244
} else {
225
245
String name = ClassUtil .getCanonicalName (type .getSignature ());
226
246
ClassDescriptor clazz = ClassRepo .findClass (name );
227
- node = getOrCreateNode (root , clazz );
247
+ node = getOrCreateNode (root , clazz , null );
228
248
}
229
249
230
250
return node ;
231
251
}
232
252
233
- private static TreeNode getOrCreateNode (TreeNode root , ClassDescriptor clazz ) throws Exception {
253
+ private static TreeNode getOrCreateNode (TreeNode root , ClassDescriptor clazz , String predefinedSuperClassname ) throws Exception {
234
254
if (ClassUtil .isPrimitive (clazz )) {
235
255
return TreeNode .getPrimitive (clazz );
236
256
}
@@ -297,11 +317,16 @@ private static TreeNode getOrCreateNode(TreeNode root, ClassDescriptor clazz) th
297
317
}
298
318
node = child ;
299
319
if (node .baseClassNode == null ) {
300
- ClassDescriptor baseClass = clazz .isInterface () ? ClassUtil
301
- .getClassByName ("java.lang.Object" ) : ClassUtil
302
- .getSuperclass (clazz );
320
+ ClassDescriptor baseClass = null ;
321
+ if (predefinedSuperClassname != null ) {
322
+ baseClass = ClassUtil .getClassByName (predefinedSuperClassname );
323
+ } else {
324
+ baseClass = clazz .isInterface ()
325
+ ? ClassUtil .getClassByName ("java.lang.Object" )
326
+ : ClassUtil .getSuperclass (clazz );
327
+ }
303
328
if (baseClass != null ) {
304
- node .baseClassNode = getOrCreateNode (root , baseClass );
329
+ node .baseClassNode = getOrCreateNode (root , baseClass , null );
305
330
copyBasePublicApi (baseClass , node , root );
306
331
}
307
332
}
@@ -312,7 +337,7 @@ private static TreeNode getOrCreateNode(TreeNode root, ClassDescriptor clazz) th
312
337
private static void copyBasePublicApi (ClassDescriptor baseClass , TreeNode node ,
313
338
TreeNode root ) throws Exception {
314
339
while ((baseClass != null ) && !baseClass .isPublic ()) {
315
- setNodeMembers (baseClass , node , root );
340
+ setNodeMembers (baseClass , node , root , false );
316
341
baseClass = ClassUtil .getSuperclass (baseClass );
317
342
}
318
343
}
@@ -349,7 +374,7 @@ private static TreeNode createArrayNode(TreeNode root, String className)
349
374
if (clazz .isStatic ()) {
350
375
child .nodeType |= TreeNode .Static ;
351
376
}
352
- child .arrayElement = getOrCreateNode (root , clazz );
377
+ child .arrayElement = getOrCreateNode (root , clazz , null );
353
378
}
354
379
}
355
380
0 commit comments