Deserialize annotations on property accessors
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.asm4.commons.Method;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.jet.descriptors.serialization.JavaProtoBufUtil;
|
||||
@@ -47,7 +48,13 @@ public class JavaSerializerExtension extends SerializerExtension {
|
||||
}
|
||||
else if (callable instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor property = (PropertyDescriptor) callable;
|
||||
// TODO
|
||||
Type type = typeMapper.mapType(property.getType());
|
||||
Method getter =
|
||||
property.getGetter() == null ? null : typeMapper.mapGetterSignature(property, OwnerKind.IMPLEMENTATION).getAsmMethod();
|
||||
Method setter =
|
||||
property.getSetter() == null ? null : typeMapper.mapSetterSignature(property, OwnerKind.IMPLEMENTATION).getAsmMethod();
|
||||
|
||||
JavaProtoBufUtil.savePropertySignature(proto, type, null /* TODO */, getter, setter, nameTable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+49
-3
@@ -39,12 +39,33 @@ public class JavaProtoBufUtil {
|
||||
return new Deserializer(nameResolver).methodSignature(signature).toString();
|
||||
}
|
||||
|
||||
public static void saveMethodSignature(
|
||||
@Nullable
|
||||
public static String loadPropertyGetterSignature(@NotNull ProtoBuf.Callable proto, @NotNull NameResolver nameResolver) {
|
||||
if (!proto.hasExtension(JavaProtoBuf.propertySignature)) return null;
|
||||
JavaProtoBuf.JavaPropertySignature propertySignature = proto.getExtension(JavaProtoBuf.propertySignature);
|
||||
return new Deserializer(nameResolver).methodSignature(propertySignature.getGetter()).toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String loadPropertySetterSignature(@NotNull ProtoBuf.Callable proto, @NotNull NameResolver nameResolver) {
|
||||
if (!proto.hasExtension(JavaProtoBuf.propertySignature)) return null;
|
||||
JavaProtoBuf.JavaPropertySignature propertySignature = proto.getExtension(JavaProtoBuf.propertySignature);
|
||||
return new Deserializer(nameResolver).methodSignature(propertySignature.getSetter()).toString();
|
||||
}
|
||||
|
||||
public static void saveMethodSignature(@NotNull ProtoBuf.Callable.Builder proto, @NotNull Method method, @NotNull NameTable nameTable) {
|
||||
proto.setExtension(JavaProtoBuf.methodSignature, new Serializer(nameTable).methodSignature(method));
|
||||
}
|
||||
|
||||
public static void savePropertySignature(
|
||||
@NotNull ProtoBuf.Callable.Builder proto,
|
||||
@NotNull Method method,
|
||||
@NotNull Type type,
|
||||
@Nullable String fieldName,
|
||||
@Nullable Method getter,
|
||||
@Nullable Method setter,
|
||||
@NotNull NameTable nameTable
|
||||
) {
|
||||
proto.setExtension(JavaProtoBuf.methodSignature, new Serializer(nameTable).methodSignature(method));
|
||||
proto.setExtension(JavaProtoBuf.propertySignature, new Serializer(nameTable).propertySignature(type, fieldName, getter, setter));
|
||||
}
|
||||
|
||||
private static class Serializer {
|
||||
@@ -69,6 +90,31 @@ public class JavaProtoBufUtil {
|
||||
return signature.build();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JavaProtoBuf.JavaPropertySignature propertySignature(
|
||||
@NotNull Type type,
|
||||
@Nullable String fieldName,
|
||||
@Nullable Method getter,
|
||||
@Nullable Method setter
|
||||
) {
|
||||
JavaProtoBuf.JavaPropertySignature.Builder signature = JavaProtoBuf.JavaPropertySignature.newBuilder();
|
||||
|
||||
signature.setType(type(type));
|
||||
|
||||
if (fieldName != null) {
|
||||
signature.setFieldName(nameTable.getSimpleNameIndex(Name.guess(fieldName)));
|
||||
}
|
||||
|
||||
if (getter != null) {
|
||||
signature.setGetter(methodSignature(getter));
|
||||
}
|
||||
if (setter != null) {
|
||||
signature.setSetter(methodSignature(setter));
|
||||
}
|
||||
|
||||
return signature.build();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JavaProtoBuf.JavaType type(@NotNull Type givenType) {
|
||||
JavaProtoBuf.JavaType.Builder builder = JavaProtoBuf.JavaType.newBuilder();
|
||||
|
||||
+4
-1
@@ -206,7 +206,10 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
|
||||
switch (kind) {
|
||||
case FUNCTION:
|
||||
return JavaProtoBufUtil.loadMethodSignature(proto, nameResolver);
|
||||
// TODO: getters, setters
|
||||
case PROPERTY_GETTER:
|
||||
return JavaProtoBufUtil.loadPropertyGetterSignature(proto, nameResolver);
|
||||
case PROPERTY_SETTER:
|
||||
return JavaProtoBufUtil.loadPropertySetterSignature(proto, nameResolver);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
annotation class Anno
|
||||
|
||||
class Class {
|
||||
val property: Int
|
||||
[Anno] get() = 42
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package test
|
||||
|
||||
internal final annotation class Anno : jet.Annotation {
|
||||
/*primary*/ public constructor Anno()
|
||||
}
|
||||
|
||||
internal final class Class {
|
||||
/*primary*/ public constructor Class()
|
||||
internal final val property: jet.Int
|
||||
test.Anno() internal final fun <get-property>(): jet.Int
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
annotation class Anno
|
||||
|
||||
class Class {
|
||||
var property: Int = 42
|
||||
[Anno] set(value) { }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package test
|
||||
|
||||
internal final annotation class Anno : jet.Annotation {
|
||||
/*primary*/ public constructor Anno()
|
||||
}
|
||||
|
||||
internal final class Class {
|
||||
/*primary*/ public constructor Class()
|
||||
internal final var property: jet.Int
|
||||
internal final fun <get-property>(): jet.Int
|
||||
test.Anno() internal final fun <set-property>(/*0*/ value: jet.Int): jet.Unit
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
annotation class Anno
|
||||
|
||||
val property: Int
|
||||
[Anno] get() = 42
|
||||
@@ -0,0 +1,8 @@
|
||||
package test
|
||||
|
||||
internal val property: jet.Int
|
||||
test.Anno() internal fun <get-property>(): jet.Int
|
||||
|
||||
internal final annotation class Anno : jet.Annotation {
|
||||
/*primary*/ public constructor Anno()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package test
|
||||
|
||||
annotation class Anno
|
||||
|
||||
var property: Int = 42
|
||||
[Anno] set(value) { }
|
||||
@@ -0,0 +1,9 @@
|
||||
package test
|
||||
|
||||
internal var property: jet.Int
|
||||
internal fun <get-property>(): jet.Int
|
||||
test.Anno() internal fun <set-property>(/*0*/ value: jet.Int): jet.Unit
|
||||
|
||||
internal final annotation class Anno : jet.Annotation {
|
||||
/*primary*/ public constructor Anno()
|
||||
}
|
||||
+20
@@ -55,6 +55,16 @@ public class DescriptorSerializationTestGenerated extends AbstractDescriptorSeri
|
||||
doTest("compiler/testData/loadKotlin/annotations/classMembers/Function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Getter.kt")
|
||||
public void testGetter() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/annotations/classMembers/Getter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Setter.kt")
|
||||
public void testSetter() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/annotations/classMembers/Setter.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/annotations/classes")
|
||||
@@ -116,6 +126,16 @@ public class DescriptorSerializationTestGenerated extends AbstractDescriptorSeri
|
||||
doTest("compiler/testData/loadKotlin/annotations/packageMembers/Function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Getter.kt")
|
||||
public void testGetter() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/annotations/packageMembers/Getter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Setter.kt")
|
||||
public void testSetter() throws Exception {
|
||||
doTest("compiler/testData/loadKotlin/annotations/packageMembers/Setter.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
|
||||
@@ -55,6 +55,16 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
doTestWithAccessors("compiler/testData/loadKotlin/annotations/classMembers/Function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Getter.kt")
|
||||
public void testGetter() throws Exception {
|
||||
doTestWithAccessors("compiler/testData/loadKotlin/annotations/classMembers/Getter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Setter.kt")
|
||||
public void testSetter() throws Exception {
|
||||
doTestWithAccessors("compiler/testData/loadKotlin/annotations/classMembers/Setter.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/annotations/classes")
|
||||
@@ -116,6 +126,16 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
||||
doTestWithAccessors("compiler/testData/loadKotlin/annotations/packageMembers/Function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Getter.kt")
|
||||
public void testGetter() throws Exception {
|
||||
doTestWithAccessors("compiler/testData/loadKotlin/annotations/packageMembers/Getter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Setter.kt")
|
||||
public void testSetter() throws Exception {
|
||||
doTestWithAccessors("compiler/testData/loadKotlin/annotations/packageMembers/Setter.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
|
||||
+20
@@ -57,6 +57,16 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/annotations/classMembers/Function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Getter.kt")
|
||||
public void testGetter() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/annotations/classMembers/Getter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Setter.kt")
|
||||
public void testSetter() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/annotations/classMembers/Setter.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/loadKotlin/annotations/classes")
|
||||
@@ -118,6 +128,16 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/annotations/packageMembers/Function.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Getter.kt")
|
||||
public void testGetter() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/annotations/packageMembers/Getter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Setter.kt")
|
||||
public void testSetter() throws Exception {
|
||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/annotations/packageMembers/Setter.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
|
||||
Reference in New Issue
Block a user