1111import com .telerik .metadata .TreeNode .FieldInfo ;
1212import com .telerik .metadata .TreeNode .MethodInfo ;
1313import com .telerik .metadata .bcl .JarFile ;
14+ import com .telerik .metadata .desc .MetadataInfoAnnotationDescriptor ;
1415import com .telerik .metadata .desc .ClassDescriptor ;
1516import com .telerik .metadata .desc .FieldDescriptor ;
1617import com .telerik .metadata .desc .MethodDescriptor ;
@@ -94,12 +95,24 @@ private static void generate(ClassDescriptor clazz, TreeNode root) throws Except
9495 if (!isClassPublic (clazz )) {
9596 return ;
9697 }
97- TreeNode node = getOrCreateNode (root , clazz );
9898
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 );
100113 }
101114
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 {
103116 Map <String , MethodInfo > existingMethods = new HashMap <String , MethodInfo >();
104117 for (MethodInfo mi : node .instanceMethods ) {
105118 existingMethods .put (mi .name + mi .sig , mi );
@@ -114,6 +127,13 @@ private static void setNodeMembers(ClassDescriptor clazz, TreeNode node, TreeNod
114127 if (m .isSynthetic ())
115128 continue ;
116129
130+ if (hasClassMetadataInfo && !m .getName ().equals ("<init>" )) {
131+ MetadataInfoAnnotationDescriptor metadataInfo = m .getMetadataInfoAnnotation ();
132+ if ((metadataInfo != null ) && metadataInfo .skip ()) {
133+ continue ;
134+ }
135+ }
136+
117137 if (m .isPublic () || m .isProtected ()) {
118138 boolean isStatic = m .isStatic ();
119139
@@ -139,7 +159,7 @@ private static void setNodeMembers(ClassDescriptor clazz, TreeNode node, TreeNod
139159
140160 if (mi .signature != null ) {
141161 if (isStatic ) {
142- mi .declaringType = getOrCreateNode (root , clazz );
162+ mi .declaringType = getOrCreateNode (root , clazz , null );
143163 node .staticMethods .add (mi );
144164 } else {
145165 String sig = m .getName () + m .getSignature ();
@@ -174,10 +194,10 @@ private static void setFieldInfo(ClassDescriptor clazz, TreeNode node, TreeNode
174194 if (f .isStatic ()) {
175195 if (interfaceClass != null ) {
176196 // changes declaring type of static fields from implementing class to interface
177- fi .declaringType = getOrCreateNode (root , interfaceClass );
197+ fi .declaringType = getOrCreateNode (root , interfaceClass , null );
178198 }
179199 else {
180- fi .declaringType = getOrCreateNode (root , clazz );
200+ fi .declaringType = getOrCreateNode (root , clazz , null );
181201 }
182202 node .staticFields .add (fi );
183203 } else {
@@ -224,13 +244,13 @@ private static TreeNode getOrCreateNode(TreeNode root, TypeDescriptor type)
224244 } else {
225245 String name = ClassUtil .getCanonicalName (type .getSignature ());
226246 ClassDescriptor clazz = ClassRepo .findClass (name );
227- node = getOrCreateNode (root , clazz );
247+ node = getOrCreateNode (root , clazz , null );
228248 }
229249
230250 return node ;
231251 }
232252
233- private static TreeNode getOrCreateNode (TreeNode root , ClassDescriptor clazz ) throws Exception {
253+ private static TreeNode getOrCreateNode (TreeNode root , ClassDescriptor clazz , String predefinedSuperClassname ) throws Exception {
234254 if (ClassUtil .isPrimitive (clazz )) {
235255 return TreeNode .getPrimitive (clazz );
236256 }
@@ -297,11 +317,16 @@ private static TreeNode getOrCreateNode(TreeNode root, ClassDescriptor clazz) th
297317 }
298318 node = child ;
299319 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+ }
303328 if (baseClass != null ) {
304- node .baseClassNode = getOrCreateNode (root , baseClass );
329+ node .baseClassNode = getOrCreateNode (root , baseClass , null );
305330 copyBasePublicApi (baseClass , node , root );
306331 }
307332 }
@@ -312,7 +337,7 @@ private static TreeNode getOrCreateNode(TreeNode root, ClassDescriptor clazz) th
312337 private static void copyBasePublicApi (ClassDescriptor baseClass , TreeNode node ,
313338 TreeNode root ) throws Exception {
314339 while ((baseClass != null ) && !baseClass .isPublic ()) {
315- setNodeMembers (baseClass , node , root );
340+ setNodeMembers (baseClass , node , root , false );
316341 baseClass = ClassUtil .getSuperclass (baseClass );
317342 }
318343 }
@@ -349,7 +374,7 @@ private static TreeNode createArrayNode(TreeNode root, String className)
349374 if (clazz .isStatic ()) {
350375 child .nodeType |= TreeNode .Static ;
351376 }
352- child .arrayElement = getOrCreateNode (root , clazz );
377+ child .arrayElement = getOrCreateNode (root , clazz , null );
353378 }
354379 }
355380
0 commit comments