correctly call properties on annotation classes
#KT-1932 Fixed
This commit is contained in:
@@ -41,7 +41,11 @@ public class CodegenUtil {
|
||||
private static final Random RANDOM = new Random(55L);
|
||||
|
||||
public static boolean isInterface(DeclarationDescriptor descriptor) {
|
||||
return descriptor instanceof ClassDescriptor && ((ClassDescriptor)descriptor).getKind() == ClassKind.TRAIT;
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
final ClassKind kind = ((ClassDescriptor) descriptor).getKind();
|
||||
return kind == ClassKind.TRAIT || kind == ClassKind.ANNOTATION_CLASS;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isInterface(JetType type) {
|
||||
|
||||
@@ -792,7 +792,10 @@ public class JetTypeMapper {
|
||||
|
||||
|
||||
public JvmPropertyAccessorSignature mapGetterSignature(PropertyDescriptor descriptor, OwnerKind kind) {
|
||||
String name = PropertyCodegen.getterName(descriptor.getName());
|
||||
final DeclarationDescriptor parentDescriptor = descriptor.getContainingDeclaration();
|
||||
boolean isAnnotation = parentDescriptor instanceof ClassDescriptor &&
|
||||
((ClassDescriptor) parentDescriptor).getKind() == ClassKind.ANNOTATION_CLASS;
|
||||
String name = isAnnotation ? descriptor.getName().getName() : PropertyCodegen.getterName(descriptor.getName());
|
||||
|
||||
// TODO: do not generate generics if not needed
|
||||
BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, true);
|
||||
@@ -801,8 +804,8 @@ public class JetTypeMapper {
|
||||
|
||||
signatureWriter.writeParametersStart();
|
||||
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) descriptor.getContainingDeclaration();
|
||||
if(kind == OwnerKind.TRAIT_IMPL) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) parentDescriptor;
|
||||
assert containingDeclaration != null;
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
mapType(containingDeclaration.getDefaultType(), signatureWriter, MapTypeMode.IMPL);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.lang.annotation.Retention
|
||||
import java.lang.annotation.RetentionPolicy
|
||||
import java.lang.annotation.Annotation
|
||||
|
||||
Retention(RetentionPolicy.RUNTIME) annotation class foo(val name : String)
|
||||
|
||||
class Test() {
|
||||
foo("OK") fun hello(input : String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val test = Test()
|
||||
for (method in javaClass<Test>().getMethods()) {
|
||||
val anns = method?.getAnnotations() as Array<Annotation>
|
||||
if (!anns.isEmpty()) {
|
||||
for (ann in anns) {
|
||||
val fooAnn = ann as foo
|
||||
return fooAnn.name
|
||||
}
|
||||
}
|
||||
}
|
||||
return "fail"
|
||||
}
|
||||
@@ -320,4 +320,8 @@ public class StdlibTest extends CodegenTestCase {
|
||||
assertEquals(invoke1[0].value(), RetentionPolicy.RUNTIME);
|
||||
assertEquals(invoke1[1].value(), RetentionPolicy.SOURCE);
|
||||
}
|
||||
|
||||
public void testInvokeAnnotationMethod() {
|
||||
blackBoxFile("regressions/kt1932.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user