blob: 8a57ef795239d423a0c6b9bbffa11624eff108ee (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
import scala.tools.partest.BytecodeTest
import scala.collection.JavaConverters._
package p1 {
package p2 {
object Singleton {
object Singleton {
object Singleton
}
}
}
}
class A1 {
class B1 {
@scala.beans.BeanInfo
class C1
}
}
class A2 {
class B2 {
class C2
}
def f: B2#C2 = null
}
object Test extends BytecodeTest {
import p1.p2._
def nested(c: Class[_]) = s" ${c.getName}: ${c.getDeclaredClasses.toList}"
def nprintln(s: String) = println("\n"+s)
def printInner(cname: String): Unit = {
val cnode = loadClassNode(cname)
println(cnode.innerClasses.asScala.toList.map(i => s"className[${i.name}] outerClassName[${i.outerName}] innerName[${i.innerName}] access[${i.access}]").mkString(" ", "\n ", ""))
}
def show() {
println("getClass on module gives module class")
println(" " + Singleton.Singleton.getClass)
nprintln("Nested module classes are found through reflection")
println(nested(Singleton.Singleton.getClass))
nprintln("Reflection can find direct nested classes (A1-B1-C1)")
println(nested(classOf[A1]))
println(nested(classOf[A1#B1]))
println(nested(classOf[A1#B1#C1]))
nprintln("Reflection can find direct nested classes (A2-B2-C2)")
println(nested(classOf[A2]))
println(nested(classOf[A2#B2]))
println(nested(classOf[A2#B2#C2]))
nprintln("Mirror classes have the same InnerClass attributes as the corresponding module class:")
printInner("p1.p2.Singleton") // mirror class
println("Module class")
printInner("p1.p2.Singleton$")
nprintln("An outer class has a InnerClass attribute for direct nested classes")
printInner("A1")
println("A nested class has an InnerClass attribute for itself (and also for its nested classes)")
printInner("A1$B1")
println("C1 is a nested class, so it has an InnerClass attribute for itself.\n"+
"Because that attribute leads to an entry for B1 in the constant pool, C1 needs an InnerClass attribute for B1.")
printInner("A1$B1$C1")
nprintln("The BeanInfo class has the same InnerClass attributes as the corresponding bean")
printInner("A1$B1$C1BeanInfo")
nprintln("Class A2 mentions class C2 in the constant pool (due to method f), therefore it needs an InnerClass attribute for C1")
printInner("A2")
println("B2")
printInner("A2$B2")
println("C2")
printInner("A2$B2$C2")
}
}
|