JVM: Write signature for annotation parameter
This commit is contained in:
@@ -166,10 +166,15 @@ public class PropertyCodegen {
|
||||
}
|
||||
|
||||
public void generateConstructorPropertyAsMethodForAnnotationClass(JetParameter p, PropertyDescriptor descriptor) {
|
||||
Type type = typeMapper.mapAnnotationParameterType(descriptor);
|
||||
JvmMethodSignature signature = typeMapper.mapAnnotationParameterSignature(descriptor);
|
||||
String name = p.getName();
|
||||
assert name != null : "Annotation parameter has no name: " + p.getText();
|
||||
MethodVisitor mv = v.newMethod(OtherOrigin(p, descriptor), ACC_PUBLIC | ACC_ABSTRACT, name, "()" + type.getDescriptor(), null, null);
|
||||
MethodVisitor mv = v.newMethod(
|
||||
OtherOrigin(p, descriptor), ACC_PUBLIC | ACC_ABSTRACT, name,
|
||||
signature.getAsmMethod().getDescriptor(),
|
||||
signature.getGenericsSignature(),
|
||||
null
|
||||
);
|
||||
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||
JetExpression defaultValue = p.getDefaultValue();
|
||||
|
||||
@@ -241,8 +241,12 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type mapAnnotationParameterType(@NotNull PropertyDescriptor descriptor) {
|
||||
return mapType(descriptor.getType(), null, JetTypeMapperMode.VALUE_FOR_ANNOTATION);
|
||||
public JvmMethodSignature mapAnnotationParameterSignature(@NotNull PropertyDescriptor descriptor) {
|
||||
BothSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
sw.writeReturnType();
|
||||
mapType(descriptor.getType(), sw, JetTypeMapperMode.VALUE_FOR_ANNOTATION);
|
||||
sw.writeReturnTypeEnd();
|
||||
return sw.makeJvmMethodSignature(descriptor.getName().asString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -353,14 +357,9 @@ public class JetTypeMapper {
|
||||
return asmType;
|
||||
}
|
||||
|
||||
if (kind.isForAnnotation() && KotlinBuiltIns.isKClass((ClassDescriptor) descriptor)) {
|
||||
if (signatureVisitor != null) {
|
||||
signatureVisitor.writeAsmType(AsmTypes.JAVA_CLASS_TYPE);
|
||||
}
|
||||
return AsmTypes.JAVA_CLASS_TYPE;
|
||||
}
|
||||
|
||||
Type asmType = computeAsmType((ClassDescriptor) descriptor.getOriginal());
|
||||
Type asmType = kind.isForAnnotation() && KotlinBuiltIns.isKClass((ClassDescriptor) descriptor) ?
|
||||
AsmTypes.JAVA_CLASS_TYPE :
|
||||
computeAsmType((ClassDescriptor) descriptor.getOriginal());
|
||||
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed);
|
||||
return asmType;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class Ann(val arg: Array<out Class<out KClass<*>>>)
|
||||
|
||||
// method: Ann::arg
|
||||
// jvm signature: ()[Ljava/lang/Class;
|
||||
// generic signature: ()[Ljava/lang/Class<+Lkotlin/reflect/KClass<*>;>;
|
||||
@@ -0,0 +1,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class Ann(val arg: Class<*>)
|
||||
|
||||
// method: Ann::arg
|
||||
// jvm signature: ()Ljava/lang/Class;
|
||||
// generic signature: ()Ljava/lang/Class<*>;
|
||||
@@ -0,0 +1,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class Ann(val arg: Class<Int>)
|
||||
|
||||
// method: Ann::arg
|
||||
// jvm signature: ()Ljava/lang/Class;
|
||||
// generic signature: ()Ljava/lang/Class<Ljava/lang/Integer;>;
|
||||
@@ -0,0 +1,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class Ann(val arg: Array<out KClass<out Class<*>>>)
|
||||
|
||||
// method: Ann::arg
|
||||
// jvm signature: ()[Ljava/lang/Class;
|
||||
// generic signature: ()[Ljava/lang/Class<+Ljava/lang/Class<*>;>;
|
||||
@@ -0,0 +1,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class Ann(val arg: Array<out KClass<out KClass<*>>>)
|
||||
|
||||
// method: Ann::arg
|
||||
// jvm signature: ()[Ljava/lang/Class;
|
||||
// generic signature: ()[Ljava/lang/Class<+Lkotlin/reflect/KClass<*>;>;
|
||||
@@ -0,0 +1,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class Ann(val arg: KClass<*>)
|
||||
|
||||
// method: Ann::arg
|
||||
// jvm signature: ()Ljava/lang/Class;
|
||||
// generic signature: ()Ljava/lang/Class<*>;
|
||||
@@ -0,0 +1,7 @@
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
annotation class Ann(val arg: KClass<Int>)
|
||||
|
||||
// method: Ann::arg
|
||||
// jvm signature: ()Ljava/lang/Class;
|
||||
// generic signature: ()Ljava/lang/Class<Ljava/lang/Integer;>;
|
||||
@@ -137,6 +137,57 @@ public class WriteSignatureTestGenerated extends AbstractWriteSignatureTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/writeSignature/annotations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Annotations extends AbstractWriteSignatureTest {
|
||||
public void testAllFilesPresentInAnnotations() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/writeSignature/annotations"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("jArrayClassOfKClass.kt")
|
||||
public void testJArrayClassOfKClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/writeSignature/annotations/jArrayClassOfKClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jClassBasic.kt")
|
||||
public void testJClassBasic() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/writeSignature/annotations/jClassBasic.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jClassInt.kt")
|
||||
public void testJClassInt() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/writeSignature/annotations/jClassInt.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kArrayClassOfJClass.kt")
|
||||
public void testKArrayClassOfJClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/writeSignature/annotations/kArrayClassOfJClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kArrayClassOfKClass.kt")
|
||||
public void testKArrayClassOfKClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/writeSignature/annotations/kArrayClassOfKClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kClassBasic.kt")
|
||||
public void testKClassBasic() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/writeSignature/annotations/kClassBasic.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kClassInt.kt")
|
||||
public void testKClassInt() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/writeSignature/annotations/kClassInt.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/writeSignature/constructor")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user