[decompiler] Fix property and receiver annotations loading for stubs
Add annotation loading for property backing field, property delegate and extension receiver to AnnotationLoaderForStubBuilderImpl. Use logic from AnnotationAndConstantLoaderImpl. AnnotationLoaderForStubBuilderImpl is used by KotlinMetadataDecompiler, K2KlibMetadataDecompiler and KotlinJavaScriptMetaFileDecompiler. Stub versions for built-ins (affects metadata and K/N decompilers) and JS are bumped. KTIJ-26761 KTIJ-26961
This commit is contained in:
committed by
Space Team
parent
0882d5201b
commit
30d45039fb
+27
-5
@@ -40,11 +40,19 @@ class AnnotationLoaderForStubBuilderImpl(
|
||||
return annotations.map { loadAnnotation(it, container.nameResolver) }
|
||||
}
|
||||
|
||||
override fun loadPropertyBackingFieldAnnotations(container: ProtoContainer, proto: ProtoBuf.Property): List<AnnotationWithArgs> =
|
||||
emptyList()
|
||||
override fun loadPropertyBackingFieldAnnotations(container: ProtoContainer, proto: ProtoBuf.Property): List<AnnotationWithArgs> {
|
||||
val annotations = protocol.propertyBackingFieldAnnotation?.let { proto.getExtension(it) }.orEmpty()
|
||||
return annotations.map { annotationProto ->
|
||||
loadAnnotation(annotationProto, container.nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadPropertyDelegateFieldAnnotations(container: ProtoContainer, proto: ProtoBuf.Property): List<AnnotationWithArgs> =
|
||||
emptyList()
|
||||
override fun loadPropertyDelegateFieldAnnotations(container: ProtoContainer, proto: ProtoBuf.Property): List<AnnotationWithArgs> {
|
||||
val annotations = protocol.propertyDelegatedFieldAnnotation?.let {proto.getExtension(it) }.orEmpty()
|
||||
return annotations.map { annotationProto ->
|
||||
loadAnnotation(annotationProto, container.nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadEnumEntryAnnotations(container: ProtoContainer, proto: ProtoBuf.EnumEntry): List<AnnotationWithArgs> =
|
||||
proto.getExtension(protocol.enumEntryAnnotation).orEmpty().map { loadAnnotation(it, container.nameResolver) }
|
||||
@@ -62,7 +70,21 @@ class AnnotationLoaderForStubBuilderImpl(
|
||||
container: ProtoContainer,
|
||||
proto: MessageLite,
|
||||
kind: AnnotatedCallableKind
|
||||
): List<AnnotationWithArgs> = emptyList()
|
||||
): List<AnnotationWithArgs> {
|
||||
val annotations = when (proto) {
|
||||
is ProtoBuf.Function -> protocol.functionExtensionReceiverAnnotation?.let { proto.getExtension(it) }
|
||||
is ProtoBuf.Property -> when (kind) {
|
||||
AnnotatedCallableKind.PROPERTY, AnnotatedCallableKind.PROPERTY_GETTER, AnnotatedCallableKind.PROPERTY_SETTER -> {
|
||||
protocol.propertyExtensionReceiverAnnotation?.let { proto.getExtension(it) }
|
||||
}
|
||||
else -> error("Unsupported callable kind with property proto for receiver annotations: $kind")
|
||||
}
|
||||
else -> error("Unknown message: $proto")
|
||||
}.orEmpty()
|
||||
return annotations.map { annotationProto ->
|
||||
loadAnnotation(annotationProto, container.nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
override fun loadTypeAnnotations(
|
||||
proto: ProtoBuf.Type,
|
||||
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// Issue: KTIJ-26761
|
||||
// KNM_K2_IGNORE
|
||||
public class AnnotationsOnNullableTypes {
|
||||
fun B<@A C?>.receiverArgument() {}
|
||||
|
||||
|
||||
-3
@@ -1,6 +1,3 @@
|
||||
// Issue: KTIJ-26761
|
||||
// KNM_K2_IGNORE
|
||||
|
||||
package foo.TopLevelMembers
|
||||
|
||||
fun funWithBlockBody() {
|
||||
|
||||
@@ -25,9 +25,9 @@ object KotlinStubVersions {
|
||||
|
||||
// BuiltIn stub version should be increased if changes are made to builtIn stub building subsystem (org.jetbrains.kotlin.idea.decompiler.builtIns)
|
||||
// Increasing this version will lead to reindexing of all builtIn files (see KotlinBuiltInFileType).
|
||||
const val BUILTIN_STUB_VERSION = BINARY_STUB_VERSION + 4
|
||||
const val BUILTIN_STUB_VERSION = BINARY_STUB_VERSION + 5
|
||||
|
||||
// JS stub version should be increased if changes are made to js stub building subsystem (org.jetbrains.kotlin.idea.decompiler.js)
|
||||
// Increasing this version will lead to reindexing of js binary files (see KotlinJavaScriptMetaFileType).
|
||||
const val JS_STUB_VERSION = BINARY_STUB_VERSION + 3
|
||||
const val JS_STUB_VERSION = BINARY_STUB_VERSION + 4
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user