Skip to content

Commit f88abc5

Browse files
committed
Minor, cleanup InlineTestUtil.kt
1 parent d50a531 commit f88abc5

File tree

1 file changed

+35
-43
lines changed

1 file changed

+35
-43
lines changed

compiler/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames
2323
import org.jetbrains.kotlin.load.kotlin.FileBasedKotlinClass
2424
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
2525
import org.jetbrains.kotlin.psi.KtFile
26-
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
2726
import org.jetbrains.kotlin.test.InTextDirectivesUtils
2827
import org.jetbrains.org.objectweb.asm.*
2928
import org.jetbrains.org.objectweb.asm.tree.MethodNode
3029
import java.util.*
31-
import kotlin.properties.Delegates
3230

3331
object InlineTestUtil {
3432
private val KOTLIN_MULTIFILE_CLASS_DESC =
35-
"L" + AsmUtil.internalNameByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_MULTIFILE_CLASS) + ";"
33+
AsmUtil.asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_MULTIFILE_CLASS)
3634

3735
fun checkNoCallsToInline(files: Iterable<OutputFile>, sourceFiles: List<KtFile>) {
3836
val inlineInfo = obtainInlineInfo(files)
@@ -42,16 +40,16 @@ object InlineTestUtil {
4240
val notInlinedCalls = checkInlineMethodNotInvoked(files, inlineMethods)
4341
assert(notInlinedCalls.isEmpty()) { "All inline methods should be inlined but:\n" + notInlinedCalls.joinToString("\n") }
4442

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+
}
5046

5147
if (!skipParameterChecking) {
5248
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+
}
5553
}
5654
}
5755

@@ -110,7 +108,7 @@ object InlineTestUtil {
110108
if (inlinedMethods.contains(methodCall)) {
111109
val fromCall = MethodInfo(className, this.name, this.desc)
112110

113-
//skip delegation to trait impl from child class
111+
//skip delegation to interface DefaultImpls from child class
114112
if (methodCall.owner.endsWith(JvmAbi.DEFAULT_IMPLS_SUFFIX) && fromCall.owner != methodCall.owner) {
115113
return
116114
}
@@ -129,42 +127,37 @@ object InlineTestUtil {
129127
val inlinedMethods = inlineInfo.inlineMethods
130128
val notInlinedParameters = ArrayList<NotInlinedParameter>()
131129
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
145131

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+
}
148139

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))
155148
}
149+
}
156150

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))
163155
}
156+
super.visitFieldInsn(opcode, owner, name, desc)
164157
}
165158
}
166-
}, 0)
167-
}
159+
}
160+
}, 0)
168161
}
169162

170163
return notInlinedParameters
@@ -202,9 +195,8 @@ object InlineTestUtil {
202195

203196
private data class MethodInfo(val owner: String, val name: String, val desc: String)
204197

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
208200

209201
override fun visit(version: Int, access: Int, name: String, signature: String?, superName: String?, interfaces: Array<String>?) {
210202
className = name

0 commit comments

Comments
 (0)