Generate interface property annotations in interface class (not in DefaultImpls)
This commit is contained in:
@@ -58,8 +58,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.jetbrains.kotlin.codegen.AsmUtil.getDeprecatedAccessFlag;
|
import static org.jetbrains.kotlin.codegen.AsmUtil.getDeprecatedAccessFlag;
|
||||||
import static org.jetbrains.kotlin.codegen.AsmUtil.getVisibilityForBackingField;
|
import static org.jetbrains.kotlin.codegen.AsmUtil.getVisibilityForBackingField;
|
||||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isConstOrHasJvmFieldAnnotation;
|
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*;
|
||||||
import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isJvmInterface;
|
|
||||||
import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.FIELD_FOR_PROPERTY;
|
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.codegen.serialization.JvmSerializationBindings.SYNTHETIC_METHOD_FOR_PROPERTY;
|
||||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject;
|
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject;
|
||||||
@@ -274,8 +273,10 @@ public class PropertyCodegen {
|
|||||||
private void generateSyntheticMethodIfNeeded(@NotNull PropertyDescriptor descriptor, @NotNull Annotations annotations) {
|
private void generateSyntheticMethodIfNeeded(@NotNull PropertyDescriptor descriptor, @NotNull Annotations annotations) {
|
||||||
if (annotations.getAllAnnotations().isEmpty()) return;
|
if (annotations.getAllAnnotations().isEmpty()) return;
|
||||||
|
|
||||||
if (!isInterface(context.getContextDescriptor()) || kind == OwnerKind.DEFAULT_IMPLS) {
|
DeclarationDescriptor contextDescriptor = context.getContextDescriptor();
|
||||||
int flags = ACC_DEPRECATED | ACC_FINAL | ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC;
|
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);
|
Method syntheticMethod = getSyntheticMethodSignature(descriptor);
|
||||||
MethodVisitor mv = v.newMethod(JvmDeclarationOriginKt.OtherOrigin(descriptor), flags, syntheticMethod.getName(),
|
MethodVisitor mv = v.newMethod(JvmDeclarationOriginKt.OtherOrigin(descriptor), flags, syntheticMethod.getName(),
|
||||||
syntheticMethod.getDescriptor(), null, null);
|
syntheticMethod.getDescriptor(), null, null);
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ public final class A {
|
|||||||
private final @AnnField @AnnParameterField @AnnTypeField field a: int
|
private final @AnnField @AnnParameterField @AnnTypeField field a: int
|
||||||
private final @AnnField @AnnTypeField field x: int
|
private final @AnnField @AnnTypeField field x: int
|
||||||
public method <init>(@AnnParameterProperty @AnnParameterField p0: int): void
|
public method <init>(@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 getA(): int
|
||||||
public final method getX(): 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
|
@kotlin.annotation.Target
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ public final class A {
|
|||||||
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
|
public final @org.jetbrains.annotations.NotNull method getS(): java.lang.String
|
||||||
public final method getX(): int
|
public final method getX(): int
|
||||||
public final @AnnGetter method getY(): int
|
public final @AnnGetter method getY(): int
|
||||||
private synthetic deprecated final static @AnnProp @AnnProp2 method p$annotations(): void
|
private synthetic deprecated 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 @AnnDelegate method s$annotations(): void
|
||||||
public final @AnnSetter method setP(@AnnParam p0: int): void
|
public final @AnnSetter method setP(@AnnParam p0: int): void
|
||||||
public final @AnnSetter method setY(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
|
@java.lang.annotation.Retention
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
+21
@@ -163,6 +163,12 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("compiler/testData/codegen/java8/box/jvm8/noDelegation")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
@@ -189,6 +195,21 @@ public class BlackBoxWithJava8CodegenTestGenerated extends AbstractBlackBoxCodeg
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("compiler/testData/codegen/java8/box/mapGetOrDefault")
|
||||||
|
|||||||
-1
@@ -66,7 +66,6 @@ public class SyntheticMethodForAnnotatedPropertyGenTest extends CodegenTestCase
|
|||||||
}
|
}
|
||||||
assertTrue(method.isSynthetic());
|
assertTrue(method.isSynthetic());
|
||||||
int modifiers = method.getModifiers();
|
int modifiers = method.getModifiers();
|
||||||
assertTrue(Modifier.isFinal(modifiers));
|
|
||||||
assertTrue(Modifier.isStatic(modifiers));
|
assertTrue(Modifier.isStatic(modifiers));
|
||||||
assertTrue(Modifier.isPrivate(modifiers));
|
assertTrue(Modifier.isPrivate(modifiers));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user