diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index e199ad3aaf8..40e17f495cc 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -58,8 +58,7 @@ import java.util.List; import static org.jetbrains.kotlin.codegen.AsmUtil.getDeprecatedAccessFlag; import static org.jetbrains.kotlin.codegen.AsmUtil.getVisibilityForBackingField; -import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isConstOrHasJvmFieldAnnotation; -import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isJvmInterface; +import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*; import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.FIELD_FOR_PROPERTY; import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.SYNTHETIC_METHOD_FOR_PROPERTY; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject; @@ -274,8 +273,10 @@ public class PropertyCodegen { private void generateSyntheticMethodIfNeeded(@NotNull PropertyDescriptor descriptor, @NotNull Annotations annotations) { if (annotations.getAllAnnotations().isEmpty()) return; - if (!isInterface(context.getContextDescriptor()) || kind == OwnerKind.DEFAULT_IMPLS) { - int flags = ACC_DEPRECATED | ACC_FINAL | ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC; + DeclarationDescriptor contextDescriptor = context.getContextDescriptor(); + if (!isInterface(contextDescriptor) || + (isJvm8Interface(contextDescriptor, state) ? kind != OwnerKind.DEFAULT_IMPLS : kind == OwnerKind.DEFAULT_IMPLS)) { + int flags = ACC_DEPRECATED | ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC; Method syntheticMethod = getSyntheticMethodSignature(descriptor); MethodVisitor mv = v.newMethod(JvmDeclarationOriginKt.OtherOrigin(descriptor), flags, syntheticMethod.getName(), syntheticMethod.getDescriptor(), null, null); diff --git a/compiler/testData/codegen/bytecodeListing/annotations/defaultTargets.txt b/compiler/testData/codegen/bytecodeListing/annotations/defaultTargets.txt index eb75c8d97dc..e55b1f3ceb0 100644 --- a/compiler/testData/codegen/bytecodeListing/annotations/defaultTargets.txt +++ b/compiler/testData/codegen/bytecodeListing/annotations/defaultTargets.txt @@ -3,10 +3,10 @@ public final class A { private final @AnnField @AnnParameterField @AnnTypeField field a: int private final @AnnField @AnnTypeField field x: int public method (@AnnParameterProperty @AnnParameterField p0: int): void - private synthetic deprecated final static @AnnProperty @AnnFieldProperty @AnnParameterProperty method a$annotations(): void + private synthetic deprecated static @AnnProperty @AnnFieldProperty @AnnParameterProperty method a$annotations(): void public final method getA(): int public final method getX(): int - private synthetic deprecated final static @AnnProperty @AnnFieldProperty method x$annotations(): void + private synthetic deprecated static @AnnProperty @AnnFieldProperty method x$annotations(): void } @kotlin.annotation.Target diff --git a/compiler/testData/codegen/bytecodeListing/annotations/onProperties.txt b/compiler/testData/codegen/bytecodeListing/annotations/onProperties.txt index db55ed8f13b..214faf2a1ae 100644 --- a/compiler/testData/codegen/bytecodeListing/annotations/onProperties.txt +++ b/compiler/testData/codegen/bytecodeListing/annotations/onProperties.txt @@ -11,11 +11,11 @@ public final class A { public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String public final method getX(): int public final @AnnGetter method getY(): int - private synthetic deprecated final static @AnnProp @AnnProp2 method p$annotations(): void - private synthetic deprecated final static @AnnProp @AnnProp2 @AnnDelegate method s$annotations(): void + private synthetic deprecated static @AnnProp @AnnProp2 method p$annotations(): void + private synthetic deprecated static @AnnProp @AnnProp2 @AnnDelegate method s$annotations(): void public final @AnnSetter method setP(@AnnParam p0: int): void public final @AnnSetter method setY(p0: int): void - private synthetic deprecated final static @AnnProp2 method x$annotations(): void + private synthetic deprecated static @AnnProp2 method x$annotations(): void } @java.lang.annotation.Retention diff --git a/compiler/testData/codegen/java8/box/jvm8/reflection/propertyAnnotations.kt b/compiler/testData/codegen/java8/box/jvm8/reflection/propertyAnnotations.kt new file mode 100644 index 00000000000..3953c299174 --- /dev/null +++ b/compiler/testData/codegen/java8/box/jvm8/reflection/propertyAnnotations.kt @@ -0,0 +1,21 @@ +// JVM_TARGET: 1.8 +// WITH_REFLECT + +annotation class Property(val value: String) +annotation class Accessor(val value: String) + +interface Z { + @Property("OK") + val z: String; + @Accessor("OK") + get() = "OK" +} + + +class Test : Z + +fun box() : String { + val value = (Z::z.annotations.single() as Property).value + if (value != "OK") return value + return (Z::z.getter.annotations.single() as Accessor).value +} \ No newline at end of file diff --git a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java index cff6c718f70..1855a28bde2 100644 --- a/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java +++ b/compiler/tests-java8/tests/org/jetbrains/kotlin/codegen/BlackBoxWithJava8CodegenTestGenerated.java @@ -163,6 +163,12 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg doTest(fileName); } + @TestMetadata("simpleProperty.kt") + public void testSimpleProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/simpleProperty.kt"); + doTest(fileName); + } + @TestMetadata("compiler/testData/codegen/java8/box/jvm8/noDelegation") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -189,6 +195,21 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg doTest(fileName); } } + + @TestMetadata("compiler/testData/codegen/java8/box/jvm8/reflection") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Reflection extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInReflection() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/java8/box/jvm8/reflection"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("propertyAnnotations.kt") + public void testPropertyAnnotations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/java8/box/jvm8/reflection/propertyAnnotations.kt"); + doTest(fileName); + } + } } @TestMetadata("compiler/testData/codegen/java8/box/mapGetOrDefault") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java index 7bc7b39731b..4cdb6f74f80 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/SyntheticMethodForAnnotatedPropertyGenTest.java @@ -66,7 +66,6 @@ public class SyntheticMethodForAnnotatedPropertyGenTest extends CodegenTestCase } assertTrue(method.isSynthetic()); int modifiers = method.getModifiers(); - assertTrue(Modifier.isFinal(modifiers)); assertTrue(Modifier.isStatic(modifiers)); assertTrue(Modifier.isPrivate(modifiers));