diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.kt b/compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.kt new file mode 100644 index 00000000000..f11a028ac35 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.kt @@ -0,0 +1,15 @@ +// ALLOW_AST_ACCESS + +package test + +import kotlin.reflect.KProperty + +annotation class Anno + +class CustomDelegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = prop.name +} + +class Class { + @delegate:Anno val property by CustomDelegate() +} diff --git a/compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.txt b/compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.txt new file mode 100644 index 00000000000..9485dfccf42 --- /dev/null +++ b/compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.txt @@ -0,0 +1,16 @@ +package test + +public final annotation class Anno : kotlin.Annotation { + /*primary*/ public constructor Anno() +} + +public final class Class { + /*primary*/ public constructor Class() + @delegate:test.Anno() public final val property: kotlin.String + public final fun (): kotlin.String +} + +public final class CustomDelegate { + /*primary*/ public constructor CustomDelegate() + public final operator fun getValue(/*0*/ thisRef: kotlin.Any?, /*1*/ prop: kotlin.reflect.KProperty<*>): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java index 6deb790437b..a7324fcb813 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadJavaTestGenerated.java @@ -2262,6 +2262,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("DelegateTarget.kt") + public void testDelegateTarget() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.kt"); + doTestCompiledKotlin(fileName); + } + @TestMetadata("FieldTarget.kt") public void testFieldTarget() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/FieldTarget.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java index a66e5de271c..f0c242baed5 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/LoadKotlinWithTypeTableTestGenerated.java @@ -501,6 +501,12 @@ public class LoadKotlinWithTypeTableTestGenerated extends AbstractLoadKotlinWith KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("DelegateTarget.kt") + public void testDelegateTarget() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.kt"); + doTest(fileName); + } + @TestMetadata("FieldTarget.kt") public void testFieldTarget() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/FieldTarget.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java index 37b4473edca..ae3d3e1bb0f 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/runtime/JvmRuntimeDescriptorLoaderTestGenerated.java @@ -503,6 +503,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("DelegateTarget.kt") + public void testDelegateTarget() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.kt"); + doTest(fileName); + } + @TestMetadata("FieldTarget.kt") public void testFieldTarget() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/FieldTarget.kt"); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt index 98fa276be76..5f90514938d 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.load.kotlin import com.google.protobuf.MessageLite import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.SourceElement +import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.name.ClassId @@ -102,7 +103,14 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader, fieldAnnotations: List): List + protected abstract fun loadPropertyAnnotations(propertyAnnotations: List, fieldAnnotations: List, + fieldUseSiteTarget: AnnotationUseSiteTarget): List protected abstract fun transformAnnotations(annotations: List): List diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt index b5d445a4482..5ad51a79954 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt @@ -85,10 +85,12 @@ class BinaryClassAnnotationAndConstantLoaderImpl( override fun loadPropertyAnnotations( propertyAnnotations: List, - fieldAnnotations: List + fieldAnnotations: List, + fieldUseSiteTarget: AnnotationUseSiteTarget ): List { return propertyAnnotations.map { AnnotationWithTarget(it, null) } + - fieldAnnotations.map { AnnotationWithTarget(it, AnnotationUseSiteTarget.FIELD) } + fieldAnnotations.map { AnnotationWithTarget(it, fieldUseSiteTarget) } + fieldAnnotations.map { AnnotationWithTarget(it, fieldUseSiteTarget) } } override fun transformAnnotations(annotations: List): List { diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/MemberSignature.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/MemberSignature.kt index d9285c5a9ed..63361009177 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/MemberSignature.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/MemberSignature.kt @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf // The purpose of this class is to hold a unique signature of either a method or a field, so that annotations on a member can be put // into a map indexed by these signatures -internal data class MemberSignature private constructor(private val signature: String) { +internal data class MemberSignature private constructor(internal val signature: String) { companion object { @JvmStatic fun fromMethod(nameResolver: NameResolver, signature: JvmProtoBuf.JvmMethodSignature): MemberSignature { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClsStubBuilder.kt index 1f4c3073636..168665d3d14 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/classFile/KotlinClsStubBuilder.kt @@ -138,9 +138,11 @@ class AnnotationLoaderForClassFileStubBuilder( return null } - override fun loadPropertyAnnotations(propertyAnnotations: List, fieldAnnotations: List): List { + override fun loadPropertyAnnotations( + propertyAnnotations: List, fieldAnnotations: List, fieldUseSiteTarget: AnnotationUseSiteTarget + ): List { return propertyAnnotations.map { ClassIdWithTarget(it, null) } + - fieldAnnotations.map { ClassIdWithTarget(it, AnnotationUseSiteTarget.FIELD) } + fieldAnnotations.map { ClassIdWithTarget(it, fieldUseSiteTarget ) } } override fun transformAnnotations(annotations: List) = annotations.map { ClassIdWithTarget(it, null) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java index 931043d839e..f3223096b2c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/stubs/ResolveByStubTestGenerated.java @@ -501,6 +501,12 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("DelegateTarget.kt") + public void testDelegateTarget() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/DelegateTarget.kt"); + doTest(fileName); + } + @TestMetadata("FieldTarget.kt") public void testFieldTarget() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/annotations/withUseSiteTarget/FieldTarget.kt");