diff --git a/compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt b/compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt new file mode 100644 index 00000000000..269d1a46d59 --- /dev/null +++ b/compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt @@ -0,0 +1,48 @@ +// !LANGUAGE: +UseGetterNameForPropertyAnnotationsMethodOnJvm +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// FULL_JDK + +import java.lang.reflect.Modifier +import kotlin.test.* + +annotation class Anno(val value: String) + +class A { + @Anno("OK") val property: Int + get() = 42 +} + +interface T { + @Anno("OK") val property: Int +} + +@Anno("OK") val property: Int + get() = 42 + +fun check(clazz: Class<*>, expected: Boolean = true) { + for (method in clazz.getDeclaredMethods()) { + if (method.getName() == "getProperty\$annotations") { + if (!expected) { + fail("Synthetic method for annotated property found, but not expected: $method") + } + assertTrue(method.isSynthetic()) + assertTrue(Modifier.isStatic(method.modifiers)) + assertTrue(Modifier.isPublic(method.modifiers)) + assertEquals("[@Anno(value=OK)]", method.declaredAnnotations.toList().toString()) + return + } + } + if (expected) { + fail("Synthetic method for annotated property expected, but not found") + } +} + +fun box(): String { + check(Class.forName("A")) + check(Class.forName("SyntheticMethodForPropertyKt")) + check(Class.forName("T"), expected = false) + check(Class.forName("T\$DefaultImpls")) + return "OK" +} diff --git a/compiler/testData/codegen/properties/syntheticMethod/inClass.kt b/compiler/testData/codegen/properties/syntheticMethod/inClass.kt deleted file mode 100644 index 9f0b73b7e06..00000000000 --- a/compiler/testData/codegen/properties/syntheticMethod/inClass.kt +++ /dev/null @@ -1,7 +0,0 @@ -@Retention(AnnotationRetention.RUNTIME) -annotation class SomeAnnotation(val value: String) - -class A { - @SomeAnnotation("OK") val property: Int - get() = 42 -} diff --git a/compiler/testData/codegen/properties/syntheticMethod/inTrait.kt b/compiler/testData/codegen/properties/syntheticMethod/inTrait.kt deleted file mode 100644 index 17f9b9a95bd..00000000000 --- a/compiler/testData/codegen/properties/syntheticMethod/inTrait.kt +++ /dev/null @@ -1,6 +0,0 @@ -@Retention(AnnotationRetention.RUNTIME) -annotation class SomeAnnotation(val value: String) - -interface T { - @SomeAnnotation("OK") val property: Int -} diff --git a/compiler/testData/codegen/properties/syntheticMethod/topLevel.kt b/compiler/testData/codegen/properties/syntheticMethod/topLevel.kt deleted file mode 100644 index f18feb4bea3..00000000000 --- a/compiler/testData/codegen/properties/syntheticMethod/topLevel.kt +++ /dev/null @@ -1,5 +0,0 @@ -@Retention(AnnotationRetention.RUNTIME) -annotation class SomeAnnotation(val value: String) - -@SomeAnnotation("OK") val property: Int - get() = 42 diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java index 83f97b8cab3..8d90d7021bc 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java @@ -383,11 +383,6 @@ public abstract class CodegenTestCase extends KtUsefulTestCase { throw new UnsupportedOperationException(); } - @NotNull - protected GeneratedClassLoader generateAndCreateClassLoader() { - return generateAndCreateClassLoader(true); - } - @NotNull protected GeneratedClassLoader generateAndCreateClassLoader(boolean reportProblems) { if (initializedClassLoader != null) { diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 3cf11f8f4cb..543a96bf6ef 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -181,6 +181,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt"); } + @TestMetadata("syntheticMethodForProperty.kt") + public void testSyntheticMethodForProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt"); + } + @TestMetadata("typeAnnotationOnJdk6.kt") public void testTypeAnnotationOnJdk6() throws Exception { runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 68724f752bb..69b12348048 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -186,6 +186,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt"); } + @TestMetadata("syntheticMethodForProperty.kt") + public void testSyntheticMethodForProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt"); + } + @TestMetadata("typeAnnotationOnJdk6.kt") public void testTypeAnnotationOnJdk6() throws Exception { runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java deleted file mode 100644 index 48647ec48ff..00000000000 --- a/compiler/tests/org/jetbrains/kotlin/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.codegen; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.load.java.JvmAbi; -import org.jetbrains.kotlin.test.ConfigurationKind; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -public class SyntheticMethodForAnnotatedPropertyGenTest extends CodegenTestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); - } - - @NotNull - @Override - protected String getPrefix() { - return "properties/syntheticMethod"; - } - - private static final String TEST_SYNTHETIC_METHOD_NAME = JvmAbi.getSyntheticMethodNameForAnnotatedProperty("property"); - - public void testInClass() { - loadFile(); - assertAnnotatedSyntheticMethodExistence(true, generateClass("A")); - } - - public void testTopLevel() { - loadFile(); - Class a = generateClass("TopLevelKt"); - assertAnnotatedSyntheticMethodExistence(true, a); - } - - public void testInTrait() throws ClassNotFoundException { - loadFile(); - GeneratedClassLoader loader = generateAndCreateClassLoader(); - assertAnnotatedSyntheticMethodExistence(false, loader.loadClass("T")); - assertAnnotatedSyntheticMethodExistence(true, loader.loadClass("T" + JvmAbi.DEFAULT_IMPLS_SUFFIX)); - } - - private static void assertAnnotatedSyntheticMethodExistence(boolean expected, @NotNull Class clazz) { - for (Method method : clazz.getDeclaredMethods()) { - if (TEST_SYNTHETIC_METHOD_NAME.equals(method.getName())) { - if (!expected) { - fail("Synthetic method for annotated property found, but not expected: " + method); - } - assertTrue(method.isSynthetic()); - int modifiers = method.getModifiers(); - assertTrue(Modifier.isStatic(modifiers)); - assertTrue(Modifier.isPublic(modifiers)); - - Annotation[] annotations = method.getDeclaredAnnotations(); - assertSize(1, annotations); - assertEquals("@SomeAnnotation(value=OK)", annotations[0].toString()); - return; - } - } - if (expected) { - fail("Synthetic method for annotated property expected, but not found: " + TEST_SYNTHETIC_METHOD_NAME); - } - } -} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 2cfac38b1ba..fa96accd7e6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -181,6 +181,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt"); } + @TestMetadata("syntheticMethodForProperty.kt") + public void testSyntheticMethodForProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt"); + } + @TestMetadata("typeAnnotationOnJdk6.kt") public void testTypeAnnotationOnJdk6() throws Exception { runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 2a453b20757..e01bb07e218 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -181,6 +181,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt"); } + @TestMetadata("syntheticMethodForProperty.kt") + public void testSyntheticMethodForProperty() throws Exception { + runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt"); + } + @TestMetadata("typeAnnotationOnJdk6.kt") public void testTypeAnnotationOnJdk6() throws Exception { runTest("compiler/testData/codegen/box/annotations/typeAnnotationOnJdk6.kt");