JVM IR: Mark annotation implementation classes as anonymous

And add tests to ensure that annotation implementation classes are
handled correctly in jvm-abi-gen.
This commit is contained in:
Steven Schäfer
2021-08-18 15:59:52 +02:00
committed by Alexander Udalov
parent 19660f11a7
commit 6d518c8e57
18 changed files with 128 additions and 4 deletions
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.codegen.CodegenTestUtil
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.Services
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
import kotlin.io.path.ExperimentalPathApi
@@ -52,6 +53,9 @@ abstract class BaseJvmAbiTest : TestCase() {
val javaDestinationDir: File
get() = if (name == null) workingDir.resolve("javaOut") else workingDir.resolve("$name/javaOut")
val directives: File
get() = workingDir.resolve("directives.txt")
override fun toString(): String =
"compilation '$name'"
}
@@ -77,6 +81,9 @@ abstract class BaseJvmAbiTest : TestCase() {
).toTypedArray()
destination = compilation.destinationDir.canonicalPath
useOldBackend = !useIrBackend
languageVersion = if (!compilation.directives.exists()) null else {
InTextDirectivesUtils.findStringWithPrefixes(compilation.directives.readText(), "// LANGUAGE_VERSION:")
}
}
val exitCode = compiler.exec(messageCollector, Services.EMPTY, args)
if (exitCode != ExitCode.OK || messageCollector.errors.isNotEmpty()) {
@@ -45,6 +45,11 @@ public class CompileAgainstJvmAbiTestGenerated extends AbstractCompileAgainstJvm
runTest("plugins/jvm-abi-gen/testData/compile/clinit/");
}
@TestMetadata("inlineAnnotationInstantiation")
public void testInlineAnnotationInstantiation() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/inlineAnnotationInstantiation/");
}
@TestMetadata("inlineAnonymousObject")
public void testInlineAnonymousObject() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/inlineAnonymousObject/");
@@ -45,6 +45,11 @@ public class IrCompileAgainstJvmAbiTestGenerated extends AbstractIrCompileAgains
runTest("plugins/jvm-abi-gen/testData/compile/clinit/");
}
@TestMetadata("inlineAnnotationInstantiation")
public void testInlineAnnotationInstantiation() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/inlineAnnotationInstantiation/");
}
@TestMetadata("inlineAnonymousObject")
public void testInlineAnonymousObject() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/inlineAnonymousObject/");
@@ -35,6 +35,16 @@ public class IrJvmAbiContentTestGenerated extends AbstractIrJvmAbiContentTest {
runTest("plugins/jvm-abi-gen/testData/content/annotation/");
}
@TestMetadata("annotationInstantiation")
public void testAnnotationInstantiation() throws Exception {
runTest("plugins/jvm-abi-gen/testData/content/annotationInstantiation/");
}
@TestMetadata("anonymousAnnotationInstantiation")
public void testAnonymousAnnotationInstantiation() throws Exception {
runTest("plugins/jvm-abi-gen/testData/content/anonymousAnnotationInstantiation/");
}
@TestMetadata("anonymousWhenMapping")
public void testAnonymousWhenMapping() throws Exception {
runTest("plugins/jvm-abi-gen/testData/content/anonymousWhenMapping/");
@@ -35,6 +35,16 @@ public class JvmAbiContentTestGenerated extends AbstractJvmAbiContentTest {
runTest("plugins/jvm-abi-gen/testData/content/annotation/");
}
@TestMetadata("annotationInstantiation")
public void testAnnotationInstantiation() throws Exception {
runTest("plugins/jvm-abi-gen/testData/content/annotationInstantiation/");
}
@TestMetadata("anonymousAnnotationInstantiation")
public void testAnonymousAnnotationInstantiation() throws Exception {
runTest("plugins/jvm-abi-gen/testData/content/anonymousAnnotationInstantiation/");
}
@TestMetadata("anonymousWhenMapping")
public void testAnonymousWhenMapping() throws Exception {
runTest("plugins/jvm-abi-gen/testData/content/anonymousWhenMapping/");
@@ -45,6 +45,11 @@ public class LegacyCompileAgainstJvmAbiTestGenerated extends AbstractLegacyCompi
runTest("plugins/jvm-abi-gen/testData/compile/clinit/");
}
@TestMetadata("inlineAnnotationInstantiation")
public void testInlineAnnotationInstantiation() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/inlineAnnotationInstantiation/");
}
@TestMetadata("inlineAnonymousObject")
public void testInlineAnonymousObject() throws Exception {
runTest("plugins/jvm-abi-gen/testData/compile/inlineAnonymousObject/");
@@ -35,6 +35,16 @@ public class LegacyJvmAbiContentTestGenerated extends AbstractLegacyJvmAbiConten
runTest("plugins/jvm-abi-gen/testData/content/annotation/");
}
@TestMetadata("annotationInstantiation")
public void testAnnotationInstantiation() throws Exception {
runTest("plugins/jvm-abi-gen/testData/content/annotationInstantiation/");
}
@TestMetadata("anonymousAnnotationInstantiation")
public void testAnonymousAnnotationInstantiation() throws Exception {
runTest("plugins/jvm-abi-gen/testData/content/anonymousAnnotationInstantiation/");
}
@TestMetadata("anonymousWhenMapping")
public void testAnonymousWhenMapping() throws Exception {
runTest("plugins/jvm-abi-gen/testData/content/anonymousWhenMapping/");
@@ -0,0 +1,7 @@
package app
import lib.*
fun runAppAndReturnOk(): String {
return a().value
}
@@ -0,0 +1,3 @@
// LANGUAGE_VERSION: 1.6
// IGNORE_BACKEND_LEGACY: JVM
// IGNORE_BACKEND: JVM
@@ -0,0 +1,5 @@
package lib
annotation class A(val value: String)
inline fun a() = A("OK")
@@ -0,0 +1,3 @@
// LANGUAGE_VERSION: 1.6
// IGNORE_BACKEND_LEGACY: JVM
// IGNORE_BACKEND: JVM
@@ -0,0 +1,23 @@
@java.lang.annotation.Retention(value=RUNTIME)
@kotlin.Metadata
public annotation class test/A {
// source: 'test.kt'
}
@kotlin.Metadata
public synthetic final class test/Test$annotationImpl$test_A$0 {
// source: 'test.kt'
enclosing class test/Test
inner (anonymous) class test/Test$annotationImpl$test_A$0
public method <init>(): void
public synthetic final method annotationType(): java.lang.Class
public final method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean
public final method hashCode(): int
public final @org.jetbrains.annotations.NotNull method toString(): java.lang.String
}
@kotlin.Metadata
public final class test/Test {
// source: 'test.kt'
inner (anonymous) class test/Test$annotationImpl$test_A$0
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method annotationInstantiation(): test.A
}
@@ -0,0 +1,7 @@
package test
annotation class A
class Test {
inline fun annotationInstantiation() = A()
}
@@ -0,0 +1 @@
// LANGUAGE_VERSION: 1.6
@@ -0,0 +1,11 @@
@java.lang.annotation.Retention(value=RUNTIME)
@kotlin.Metadata
public annotation class test/A {
// source: 'test.kt'
}
@kotlin.Metadata
public final class test/Test {
// source: 'test.kt'
public method <init>(): void
public final @org.jetbrains.annotations.NotNull method anonymousAnnotationInstantiation(): test.A
}
@@ -0,0 +1,7 @@
package test
annotation class A
class Test {
fun anonymousAnnotationInstantiation() = A()
}