@@ -23,16 +23,14 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames
23
23
import org.jetbrains.kotlin.load.kotlin.FileBasedKotlinClass
24
24
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
25
25
import org.jetbrains.kotlin.psi.KtFile
26
- import org.jetbrains.kotlin.resolve.jvm.JvmClassName
27
26
import org.jetbrains.kotlin.test.InTextDirectivesUtils
28
27
import org.jetbrains.org.objectweb.asm.*
29
28
import org.jetbrains.org.objectweb.asm.tree.MethodNode
30
29
import java.util.*
31
- import kotlin.properties.Delegates
32
30
33
31
object InlineTestUtil {
34
32
private val KOTLIN_MULTIFILE_CLASS_DESC =
35
- " L " + AsmUtil .internalNameByFqNameWithoutInnerClasses (JvmAnnotationNames .KOTLIN_MULTIFILE_CLASS ) + " ; "
33
+ AsmUtil .asmDescByFqNameWithoutInnerClasses (JvmAnnotationNames .KOTLIN_MULTIFILE_CLASS )
36
34
37
35
fun checkNoCallsToInline (files : Iterable <OutputFile >, sourceFiles : List <KtFile >) {
38
36
val inlineInfo = obtainInlineInfo(files)
@@ -42,16 +40,16 @@ object InlineTestUtil {
42
40
val notInlinedCalls = checkInlineMethodNotInvoked(files, inlineMethods)
43
41
assert (notInlinedCalls.isEmpty()) { " All inline methods should be inlined but:\n " + notInlinedCalls.joinToString(" \n " ) }
44
42
45
-
46
- val skipParameterChecking =
47
- sourceFiles.asSequence().filter {
48
- InTextDirectivesUtils .isDirectiveDefined(it.text, " NO_CHECK_LAMBDA_INLINING" )
49
- }.any()
43
+ val skipParameterChecking = sourceFiles.any {
44
+ InTextDirectivesUtils .isDirectiveDefined(it.text, " NO_CHECK_LAMBDA_INLINING" )
45
+ }
50
46
51
47
if (! skipParameterChecking) {
52
48
val notInlinedParameters = checkParametersInlined(files, inlineInfo)
53
- assert (notInlinedParameters.isEmpty()) { " All inline parameters should be inlined but:\n ${notInlinedParameters.joinToString(" \n " )} \n " +
54
- " but if you have not inlined lambdas or anonymous objects enable NO_CHECK_LAMBDA_INLINING directive" }
49
+ assert (notInlinedParameters.isEmpty()) {
50
+ " All inline parameters should be inlined but:\n ${notInlinedParameters.joinToString(" \n " )} \n " +
51
+ " but if you have not inlined lambdas or anonymous objects enable NO_CHECK_LAMBDA_INLINING directive"
52
+ }
55
53
}
56
54
}
57
55
@@ -110,7 +108,7 @@ object InlineTestUtil {
110
108
if (inlinedMethods.contains(methodCall)) {
111
109
val fromCall = MethodInfo (className, this .name, this .desc)
112
110
113
- // skip delegation to trait impl from child class
111
+ // skip delegation to interface DefaultImpls from child class
114
112
if (methodCall.owner.endsWith(JvmAbi .DEFAULT_IMPLS_SUFFIX ) && fromCall.owner != methodCall.owner) {
115
113
return
116
114
}
@@ -129,42 +127,37 @@ object InlineTestUtil {
129
127
val inlinedMethods = inlineInfo.inlineMethods
130
128
val notInlinedParameters = ArrayList <NotInlinedParameter >()
131
129
for (file in files) {
132
- val kotlinClassHeader = getClassHeader(file)
133
- if (isClassOrPackagePartKind(kotlinClassHeader)) {
134
- val cr = ClassReader (file.asByteArray())
135
-
136
- cr.accept(object : ClassVisitorWithName () {
137
-
138
- override fun visitMethod (access : Int , name : String , desc : String , signature : String? , exceptions : Array <String >? ): MethodVisitor ? {
139
- JvmClassName .byInternalName(className).fqNameForClassNameWithoutDollars
140
- val declaration = MethodInfo (className, name, desc)
141
- // do not check anonymous object creation in inline functions and in package facades
142
- if (declaration in inlinedMethods) {
143
- return null
144
- }
130
+ if (! isClassOrPackagePartKind(getClassHeader(file))) continue
145
131
146
- return object : MethodNode (Opcodes .ASM5 , access, name, desc, signature, exceptions) {
147
- private fun isInlineParameterLikeOwner (owner : String ) = owner.contains(" $" ) && ! isTopLevelOrInnerOrPackageClass(owner, inlineInfo)
132
+ ClassReader (file.asByteArray()).accept(object : ClassVisitorWithName () {
133
+ override fun visitMethod (access : Int , name : String , desc : String , signature : String? , exceptions : Array <String >? ): MethodVisitor ? {
134
+ val declaration = MethodInfo (className, name, desc)
135
+ // do not check anonymous object creation in inline functions and in package facades
136
+ if (declaration in inlinedMethods) {
137
+ return null
138
+ }
148
139
149
- override fun visitMethodInsn (opcode : Int , owner : String , name : String , desc : String , itf : Boolean ) {
150
- if (" <init>" .equals(name) && isInlineParameterLikeOwner(owner)) {
151
- /* constuctor creation*/
152
- val fromCall = MethodInfo (className, this .name, this .desc)
153
- notInlinedParameters.add(NotInlinedParameter (owner, fromCall))
154
- }
140
+ return object : MethodNode (Opcodes .ASM5 , access, name, desc, signature, exceptions) {
141
+ private fun isInlineParameterLikeOwner (owner : String ) =
142
+ " $" in owner && ! isTopLevelOrInnerOrPackageClass(owner, inlineInfo)
143
+
144
+ override fun visitMethodInsn (opcode : Int , owner : String , name : String , desc : String , itf : Boolean ) {
145
+ if (" <init>" .equals(name) && isInlineParameterLikeOwner(owner)) {
146
+ val fromCall = MethodInfo (className, this .name, this .desc)
147
+ notInlinedParameters.add(NotInlinedParameter (owner, fromCall))
155
148
}
149
+ }
156
150
157
- override fun visitFieldInsn (opcode : Int , owner : String , name : String , desc : String ) {
158
- if (opcode == Opcodes .GETSTATIC && isInlineParameterLikeOwner(owner)) {
159
- val fromCall = MethodInfo (className, this .name, this .desc)
160
- notInlinedParameters.add(NotInlinedParameter (owner, fromCall))
161
- }
162
- super .visitFieldInsn(opcode, owner, name, desc)
151
+ override fun visitFieldInsn (opcode : Int , owner : String , name : String , desc : String ) {
152
+ if (opcode == Opcodes .GETSTATIC && isInlineParameterLikeOwner(owner)) {
153
+ val fromCall = MethodInfo (className, this .name, this .desc)
154
+ notInlinedParameters.add(NotInlinedParameter (owner, fromCall))
163
155
}
156
+ super .visitFieldInsn(opcode, owner, name, desc)
164
157
}
165
158
}
166
- }, 0 )
167
- }
159
+ }
160
+ }, 0 )
168
161
}
169
162
170
163
return notInlinedParameters
@@ -202,9 +195,8 @@ object InlineTestUtil {
202
195
203
196
private data class MethodInfo (val owner : String , val name : String , val desc : String )
204
197
205
- open private class ClassVisitorWithName () : ClassVisitor(Opcodes .ASM5 ) {
206
-
207
- var className: String by Delegates .notNull()
198
+ private open class ClassVisitorWithName : ClassVisitor (Opcodes .ASM5 ) {
199
+ lateinit var className: String
208
200
209
201
override fun visit (version : Int , access : Int , name : String , signature : String? , superName : String? , interfaces : Array <String >? ) {
210
202
className = name
0 commit comments