diff --git a/compiler/testData/loadJava8/compiledJava/InnerClassTypeAnnotation.java b/compiler/testData/loadJava8/compiledJava/InnerClassTypeAnnotation.java new file mode 100644 index 00000000000..f3f3a967e49 --- /dev/null +++ b/compiler/testData/loadJava8/compiledJava/InnerClassTypeAnnotation.java @@ -0,0 +1,21 @@ +package test; + +// SKIP_IN_RUNTIME_TEST + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +public class InnerClassTypeAnnotation { + + public class Inner { + public Inner(@Foo String foo) { + } + } + + @Retention(RetentionPolicy.CLASS) + @Target({ElementType.TYPE_USE}) + public @interface Foo {} + +} diff --git a/compiler/testData/loadJava8/compiledJava/InnerClassTypeAnnotation.txt b/compiler/testData/loadJava8/compiledJava/InnerClassTypeAnnotation.txt new file mode 100644 index 00000000000..0a331d40030 --- /dev/null +++ b/compiler/testData/loadJava8/compiledJava/InnerClassTypeAnnotation.txt @@ -0,0 +1,13 @@ +package test + +public open class InnerClassTypeAnnotation { + public constructor InnerClassTypeAnnotation() + + @kotlin.annotation.Retention(value = AnnotationRetention.BINARY) @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class Foo : kotlin.Annotation { + public constructor Foo() + } + + public open inner class Inner { + public constructor Inner(/*0*/ @test.InnerClassTypeAnnotation.Foo p0: @test.InnerClassTypeAnnotation.Foo kotlin.String!) + } +} diff --git a/compiler/tests-common/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt b/compiler/tests-common/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt index 04d634269ba..290a726d0b9 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt +++ b/compiler/tests-common/org/jetbrains/kotlin/jvm/runtime/AbstractJvmRuntimeDescriptorLoaderTest.kt @@ -186,10 +186,14 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() { private fun adaptJavaSource(text: String): String { val typeAnnotations = arrayOf("NotNull", "Nullable", "ReadOnly", "Mutable") - return typeAnnotations.fold(text) { text, annotation -> text.replace("@$annotation", "") }.replace( - "@interface", - "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @interface" - ) + val adaptedSource = typeAnnotations.fold(text) { text, annotation -> text.replace("@$annotation", "") } + if ("@Retention" !in adaptedSource) { + return adaptedSource.replace( + "@interface", + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @interface" + ) + } + return adaptedSource } private class SyntheticPackageViewForTest(override val module: ModuleDescriptor, diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java index 48afe0720e8..ea6361582ab 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/compiler/LoadJava8TestGenerated.java @@ -38,6 +38,12 @@ public class LoadJava8TestGenerated extends AbstractLoadJava8Test { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava8/compiledJava"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, true); } + @TestMetadata("InnerClassTypeAnnotation.java") + public void testInnerClassTypeAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/compiledJava/InnerClassTypeAnnotation.java"); + doTestCompiledJava(fileName); + } + @TestMetadata("MapRemove.java") public void testMapRemove() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/compiledJava/MapRemove.java"); diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java index c817f9abb0b..baf9e80e441 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/jvm/runtime/Jvm8RuntimeDescriptorLoaderTestGenerated.java @@ -36,6 +36,12 @@ public class Jvm8RuntimeDescriptorLoaderTestGenerated extends AbstractJvm8Runtim KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava8/compiledJava"), Pattern.compile("^(.+)\\.java$"), TargetBackend.ANY, true, "sam", "kotlinSignature/propagation"); } + @TestMetadata("InnerClassTypeAnnotation.java") + public void testInnerClassTypeAnnotation() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/compiledJava/InnerClassTypeAnnotation.java"); + doTest(fileName); + } + @TestMetadata("MapRemove.java") public void testMapRemove() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava8/compiledJava/MapRemove.java");