psi2ir: Java annotations have no primary constructor
This commit is contained in:
+5
-3
@@ -88,15 +88,17 @@ class AnnotationGenerator(
|
|||||||
|
|
||||||
fun generateAnnotationConstructorCall(annotationDescriptor: AnnotationDescriptor): IrCall {
|
fun generateAnnotationConstructorCall(annotationDescriptor: AnnotationDescriptor): IrCall {
|
||||||
val annotationType = annotationDescriptor.type
|
val annotationType = annotationDescriptor.type
|
||||||
val annotationClassDescriptor = annotationType.constructor.declarationDescriptor
|
val annotationClassDescriptor = annotationType.constructor.declarationDescriptor as? ClassDescriptor
|
||||||
?: throw AssertionError("No declaration descriptor for annotation $annotationDescriptor")
|
?: throw AssertionError("No declaration descriptor for annotation $annotationDescriptor")
|
||||||
assert(DescriptorUtils.isAnnotationClass(annotationClassDescriptor)) {
|
assert(DescriptorUtils.isAnnotationClass(annotationClassDescriptor)) {
|
||||||
"Annotation class expected: $annotationClassDescriptor"
|
"Annotation class expected: $annotationClassDescriptor"
|
||||||
}
|
}
|
||||||
|
|
||||||
val primaryConstructorDescriptor =
|
val primaryConstructorDescriptor =
|
||||||
annotationClassDescriptor.safeAs<ClassDescriptor>()?.unsubstitutedPrimaryConstructor
|
annotationClassDescriptor.unsubstitutedPrimaryConstructor
|
||||||
?: throw AssertionError("No primary constructor for annotation class $annotationClassDescriptor")
|
?: annotationClassDescriptor.constructors.singleOrNull()
|
||||||
|
?: throw AssertionError("No constructor for annotation class $annotationClassDescriptor")
|
||||||
|
|
||||||
val primaryConstructorSymbol = symbolTable.referenceConstructor(primaryConstructorDescriptor)
|
val primaryConstructorSymbol = symbolTable.referenceConstructor(primaryConstructorDescriptor)
|
||||||
|
|
||||||
val psi = annotationDescriptor.source.safeAs<PsiSourceElement>()?.psi
|
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");
|
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")
|
@TestMetadata("localDelegatedPropertiesWithAnnotations.kt")
|
||||||
public void testLocalDelegatedPropertiesWithAnnotations() throws Exception {
|
public void testLocalDelegatedPropertiesWithAnnotations() throws Exception {
|
||||||
runTest("compiler/testData/ir/irText/declarations/annotations/localDelegatedPropertiesWithAnnotations.kt");
|
runTest("compiler/testData/ir/irText/declarations/annotations/localDelegatedPropertiesWithAnnotations.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user