@@ -2,17 +2,7 @@ package checks
2
2
3
3
import reflect .ClassTag
4
4
5
- /* This test checks whether InnerClasses and EnclosingMethod sections in generated class files are correct
6
- * for different possibilities of nesting of classes in other classes, objects and methods (the attributes are accessed via java reflection).
7
- * Names of nested definitions are derived from the name of their enclosing definition by appending a letter following the scheme below:
8
- * A - a class without a companion object
9
- * B - an object without a companion class
10
- * C - a class with its companion object
11
- * D - a method
12
- * Additionally a number may be added to avoid clashes between definitions from classes and their companion objects
13
- * (1 - defined in the companion class; 2 - defined in the companion object),
14
- * e.g. ACD2 - a method inside the companion object of a class inside a top level class
15
- */
5
+
16
6
trait Checks :
17
7
val expectedTopLevelChecksCount : Int
18
8
val expectedMemberChecksCount : Int
@@ -30,22 +20,25 @@ trait Checks:
30
20
assert(localChecksCount == expectedLocalChecksCount,
31
21
s " local checks: expected $expectedLocalChecksCount but was $localChecksCount" )
32
22
23
+ // The methods below rely on the naming convention described in TestCases.scala
24
+
33
25
/** Check JVM class properties of a top level class */
34
- def checkTopLevel [ ThisClass ]( using thisTag : ClassTag [ ThisClass ] ) =
35
- val cls = thisTag.runtimeClass
26
+ def checkTopLevel ( self : AnyRef ) =
27
+ val cls = self.getClass
36
28
assert(cls.getEnclosingClass == null , s " Top level class $cls should have no enclosing class " )
37
29
assert(cls.getDeclaringClass == null , s " Top level class $cls should have no declaring class " )
38
30
assert(cls.getEnclosingMethod == null , s " Top level class $cls should have no enclosing method " )
39
31
topLevelChecksCount += 1
40
32
41
33
/** Check JVM class properties of a member class (defined directly inside another class) */
42
- def checkMember [ ThisClass , EnclosingClass ]( using thisTag : ClassTag [ ThisClass ], enclosingTag : ClassTag [ EnclosingClass ] ) =
43
- val cls = thisTag.runtimeClass
34
+ def checkMember ( self : AnyRef , outer : AnyRef ) =
35
+ val cls = self.getClass
44
36
def className = cls.simpleName
45
37
def enclosingClassName = cls.getEnclosingClass.simpleName
46
38
def declaringClassName = cls.getDeclaringClass.simpleName
47
- val expectedEnclosingClassName = enclosingTag.runtimeClass.simpleName match
48
- case " B$" => " B" // classes defined directly in top level objects should be moved to their companion/mirror classes
39
+ // Classes defined directly in top level objects should be moved to their companion/mirror classes
40
+ val expectedEnclosingClassName = outer.getClass.simpleName match
41
+ case " B$" => " B"
49
42
case " C$" => " C"
50
43
case name => name
51
44
assert(cls.getEnclosingClass != null ,
@@ -59,12 +52,12 @@ trait Checks:
59
52
memberChecksCount += 1
60
53
61
54
/** Check JVM class properties of a local class (defined directly inside a method) */
62
- def checkLocal [ ThisClass , EnclosingClass ]( using thisTag : ClassTag [ ThisClass ], enclosingTag : ClassTag [ EnclosingClass ] ) =
63
- val cls = thisTag.runtimeClass
55
+ def checkLocal ( self : AnyRef , outer : AnyRef ) =
56
+ val cls = self.getClass
64
57
def className = cls.simpleName
65
58
def enclosingClassName = cls.getEnclosingClass.simpleName
66
- def meth = cls.getEnclosingMethod
67
- val expectedEnclosingClassName = enclosingTag.runtimeClass .simpleName
59
+ def method = cls.getEnclosingMethod
60
+ val expectedEnclosingClassName = outer.getClass .simpleName
68
61
// extracting method name basing on the described naming convention
69
62
// $1 gets added during lambdaLift in case of a method defined inside another method
70
63
val expectedEnclosingMethodName =
@@ -77,10 +70,10 @@ trait Checks:
77
70
s " The enclosing class of class $className should be $expectedEnclosingClassName but was $enclosingClassName" )
78
71
assert(cls.getDeclaringClass == null ,
79
72
s " Local class $className should have no declaring class " )
80
- assert(meth != null ,
73
+ assert(method != null ,
81
74
s " Local class $className should have an enclosing method " )
82
- assert(meth .getName == expectedEnclosingMethodName,
83
- s " The enclosing method of class $className should be $expectedEnclosingMethodName but was ${meth .getName}" )
75
+ assert(method .getName == expectedEnclosingMethodName,
76
+ s " The enclosing method of class $className should be $expectedEnclosingMethodName but was ${method .getName}" )
84
77
localChecksCount += 1
85
78
86
79
extension (cls : Class [? ])
0 commit comments