psi2ir: Java annotations have no primary constructor

This commit is contained in:
Dmitry Petrov
2018-05-30 16:16:54 +03:00
parent 8094cb7dc5
commit 7b1b557250
4 changed files with 43 additions and 3 deletions
@@ -88,15 +88,17 @@ class AnnotationGenerator(
fun generateAnnotationConstructorCall(annotationDescriptor: AnnotationDescriptor): IrCall {
val annotationType = annotationDescriptor.type
val annotationClassDescriptor = annotationType.constructor.declarationDescriptor
val annotationClassDescriptor = annotationType.constructor.declarationDescriptor as? ClassDescriptor
?: throw AssertionError("No declaration descriptor for annotation $annotationDescriptor")
assert(DescriptorUtils.isAnnotationClass(annotationClassDescriptor)) {
"Annotation class expected: $annotationClassDescriptor"
}
val primaryConstructorDescriptor =
annotationClassDescriptor.safeAs<ClassDescriptor>()?.unsubstitutedPrimaryConstructor
?: throw AssertionError("No primary constructor for annotation class $annotationClassDescriptor")
annotationClassDescriptor.unsubstitutedPrimaryConstructor
?: annotationClassDescriptor.constructors.singleOrNull()
?: throw AssertionError("No constructor for annotation class $annotationClassDescriptor")
val primaryConstructorSymbol = symbolTable.referenceConstructor(primaryConstructorDescriptor)
val psi = annotationDescriptor.source.safeAs<PsiSourceElement>()?.psi
@@ -0,0 +1,16 @@
// FILE: JavaAnn.java
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@interface JavaAnn {
String value() default "";
int i() default 0;
}
// FILE: javaAnnotation.kt
@JavaAnn fun test1() {}
@JavaAnn(value="abc", i=123) fun test2() {}
@JavaAnn(i=123, value="abc") fun test3() {}
@@ -0,0 +1,17 @@
FILE fqName:<root> fileName:/javaAnnotation.kt
FUN name:test1 visibility:public modality:FINAL <> () returnType:Unit flags:
annotations:
CALL 'constructor JavaAnn(String = ..., Int = ...)' type=JavaAnn origin=null
BLOCK_BODY
FUN name:test2 visibility:public modality:FINAL <> () returnType:Unit flags:
annotations:
CALL 'constructor JavaAnn(String = ..., Int = ...)' type=JavaAnn origin=null
value: CONST String type=kotlin.String value=abc
i: CONST Int type=kotlin.Int value=123
BLOCK_BODY
FUN name:test3 visibility:public modality:FINAL <> () returnType:Unit flags:
annotations:
CALL 'constructor JavaAnn(String = ..., Int = ...)' type=JavaAnn origin=null
value: CONST String type=kotlin.String value=abc
i: CONST Int type=kotlin.Int value=123
BLOCK_BODY
@@ -381,6 +381,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
runTest("compiler/testData/ir/irText/declarations/annotations/functionsWithAnnotations.kt");
}
@TestMetadata("javaAnnotation.kt")
public void testJavaAnnotation() throws Exception {
runTest("compiler/testData/ir/irText/declarations/annotations/javaAnnotation.kt");
}
@TestMetadata("localDelegatedPropertiesWithAnnotations.kt")
public void testLocalDelegatedPropertiesWithAnnotations() throws Exception {
runTest("compiler/testData/ir/irText/declarations/annotations/localDelegatedPropertiesWithAnnotations.kt");