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 ee20f77ae53..c9af23a7e8f 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 @@ -85,28 +85,24 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader { + override fun loadCallableAnnotations(container: ProtoContainer, proto: ProtoBuf.Callable, kind: AnnotatedCallableKind): List { + val nameResolver = container.nameResolver if (kind == AnnotatedCallableKind.PROPERTY) { val syntheticFunctionSignature = getPropertySignature(proto, nameResolver, synthetic = true) val fieldSignature = getPropertySignature(proto, nameResolver, field = true) val propertyAnnotations = syntheticFunctionSignature?.let { sig -> - findClassAndLoadMemberAnnotations(container, proto, nameResolver, sig) + findClassAndLoadMemberAnnotations(container, proto, sig) } ?: listOf() val fieldAnnotations = fieldSignature?.let { sig -> - findClassAndLoadMemberAnnotations(container, proto, nameResolver, sig, isStaticFieldInOuter(proto)) + findClassAndLoadMemberAnnotations(container, proto, sig, isStaticFieldInOuter(proto)) } ?: listOf() return loadPropertyAnnotations(propertyAnnotations, fieldAnnotations) } val signature = getCallableSignature(proto, nameResolver, kind) ?: return listOf() - return transformAnnotations(findClassAndLoadMemberAnnotations(container, proto, nameResolver, signature)) + return transformAnnotations(findClassAndLoadMemberAnnotations(container, proto, signature)) } protected abstract fun loadPropertyAnnotations(propertyAnnotations: List, fieldAnnotations: List): List @@ -116,15 +112,14 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader { val kotlinClass = findClassWithAnnotationsAndInitializers( - container, nameResolver, getImplClassName(proto, nameResolver), isStaticFieldInOuter + container, getImplClassName(proto, container.nameResolver), isStaticFieldInOuter ) if (kotlinClass == null) { - errorReporter.reportLoadingError("Kotlin class for loading member annotations is not found: ${container.getFqName(nameResolver)}", null) + errorReporter.reportLoadingError("Kotlin class for loading member annotations is not found: ${container.getFqName()}", null) return listOf() } @@ -134,16 +129,15 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader { - val methodSignature = getCallableSignature(callable, nameResolver, kind) + val methodSignature = getCallableSignature(callable, container.nameResolver, kind) if (methodSignature != null) { val index = if (proto.hasExtension(index)) proto.getExtension(index) else parameterIndex val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, index) - return findClassAndLoadMemberAnnotations(container, callable, nameResolver, paramSignature) + return findClassAndLoadMemberAnnotations(container, callable, paramSignature) } return listOf() @@ -152,14 +146,13 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader { if (!callable.hasReceiverType()) return emptyList() - val methodSignature = getCallableSignature(callable, nameResolver, kind) + val methodSignature = getCallableSignature(callable, container.nameResolver, kind) if (methodSignature != null) { val paramSignature = MemberSignature.fromMethodSignatureAndParameterIndex(methodSignature, 0) - return findClassAndLoadMemberAnnotations(container, callable, nameResolver, paramSignature) + return findClassAndLoadMemberAnnotations(container, callable, paramSignature) } return emptyList() @@ -169,19 +162,15 @@ public abstract class AbstractBinaryClassAnnotationAndConstantLoader { - val classId = nameResolver.getClassId(classProto.fqName) + val classId = container.nameResolver.getClassId(classProto.fqName) if (implClassName != null) { // TODO: store accurate name for nested traits diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsAnnotationAndConstantLoader.kt b/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsAnnotationAndConstantLoader.kt index cb40ee6278d..8e9afd8bbbf 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsAnnotationAndConstantLoader.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/BuiltInsAnnotationAndConstantLoader.kt @@ -41,29 +41,26 @@ class BuiltInsAnnotationAndConstantLoader( override fun loadCallableAnnotations( container: ProtoContainer, proto: ProtoBuf.Callable, - nameResolver: NameResolver, kind: AnnotatedCallableKind ): List { val annotations = proto.getExtension(BuiltInsProtoBuf.callableAnnotation).orEmpty() - return annotations.map { proto -> AnnotationWithTarget(deserializer.deserializeAnnotation(proto, nameResolver), null) } + return annotations.map { proto -> AnnotationWithTarget(deserializer.deserializeAnnotation(proto, container.nameResolver), null) } } override fun loadValueParameterAnnotations( container: ProtoContainer, callable: ProtoBuf.Callable, - nameResolver: NameResolver, kind: AnnotatedCallableKind, parameterIndex: Int, proto: ProtoBuf.ValueParameter ): List { val annotations = proto.getExtension(BuiltInsProtoBuf.parameterAnnotation).orEmpty() - return annotations.map { proto -> deserializer.deserializeAnnotation(proto, nameResolver) } + return annotations.map { proto -> deserializer.deserializeAnnotation(proto, container.nameResolver) } } override fun loadExtensionReceiverParameterAnnotations( container: ProtoContainer, callable: ProtoBuf.Callable, - nameResolver: NameResolver, kind: AnnotatedCallableKind ): List = emptyList() @@ -75,10 +72,9 @@ class BuiltInsAnnotationAndConstantLoader( override fun loadPropertyConstant( container: ProtoContainer, proto: ProtoBuf.Callable, - nameResolver: NameResolver, expectedType: JetType ): ConstantValue<*>? { val value = proto.getExtension(BuiltInsProtoBuf.compileTimeValue) - return deserializer.resolveValue(expectedType, value, nameResolver) + return deserializer.resolveValue(expectedType, value, container.nameResolver) } } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.java b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.java index 68c845d530f..8ac0c3fe1af 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.java +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.java @@ -34,7 +34,6 @@ public interface AnnotationAndConstantLoader { List loadCallableAnnotations( @NotNull ProtoContainer container, @NotNull ProtoBuf.Callable proto, - @NotNull NameResolver nameResolver, @NotNull AnnotatedCallableKind kind ); @@ -42,7 +41,6 @@ public interface AnnotationAndConstantLoader { List loadValueParameterAnnotations( @NotNull ProtoContainer container, @NotNull ProtoBuf.Callable callable, - @NotNull NameResolver nameResolver, @NotNull AnnotatedCallableKind kind, int parameterIndex, @NotNull ProtoBuf.ValueParameter proto @@ -52,7 +50,6 @@ public interface AnnotationAndConstantLoader { List loadExtensionReceiverParameterAnnotations( @NotNull ProtoContainer container, @NotNull ProtoBuf.Callable callable, - @NotNull NameResolver nameResolver, @NotNull AnnotatedCallableKind kind ); @@ -66,7 +63,6 @@ public interface AnnotationAndConstantLoader { C loadPropertyConstant( @NotNull ProtoContainer container, @NotNull ProtoBuf.Callable proto, - @NotNull NameResolver nameResolver, @NotNull JetType expectedType ); } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt index d5f9c3e03b6..38c3a592ef1 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt @@ -129,7 +129,7 @@ public class MemberDeserializer(private val c: DeserializationContext) { property.setCompileTimeInitializer( c.storageManager.createNullableLazyValue { val container = c.containingDeclaration.asProtoContainer()!! - c.components.annotationAndConstantLoader.loadPropertyConstant(container, proto, c.nameResolver, property.getReturnType()) + c.components.annotationAndConstantLoader.loadPropertyConstant(container, proto, property.returnType) } ) } @@ -184,9 +184,7 @@ public class MemberDeserializer(private val c: DeserializationContext) { } return DeserializedAnnotationsWithPossibleTargets(c.storageManager) { c.containingDeclaration.asProtoContainer()?.let { - c.components.annotationAndConstantLoader.loadCallableAnnotations( - it, proto, c.nameResolver, kind - ) + c.components.annotationAndConstantLoader.loadCallableAnnotations(it, proto, kind) }.orEmpty() } } @@ -200,7 +198,7 @@ public class MemberDeserializer(private val c: DeserializationContext) { if (proto.hasReceiverType()) { c.containingDeclaration.asProtoContainer()?.let { c.components.annotationAndConstantLoader - .loadExtensionReceiverParameterAnnotations(it, proto, c.nameResolver, receiverTargetedKind) + .loadExtensionReceiverParameterAnnotations(it, proto, receiverTargetedKind) .map { AnnotationWithTarget(it, AnnotationUseSiteTarget.RECEIVER) } }.orEmpty() } @@ -234,9 +232,7 @@ public class MemberDeserializer(private val c: DeserializationContext) { valueParameter: ProtoBuf.ValueParameter ): Annotations { return DeserializedAnnotations(c.storageManager) { - c.components.annotationAndConstantLoader.loadValueParameterAnnotations( - container, callable, c.nameResolver, kind, index, valueParameter - ) + c.components.annotationAndConstantLoader.loadValueParameterAnnotations(container, callable, kind, index, valueParameter) } } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt index 3e29ef96378..4c73b386468 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt @@ -28,9 +28,6 @@ public data class ProtoContainer( assert((classProto != null) xor (packageFqName != null)) } - fun getFqName(nameResolver: NameResolver): FqName { - if (packageFqName != null) return packageFqName - - return nameResolver.getClassId(classProto!!.getFqName()).asSingleFqName() - } + fun getFqName(): FqName = + packageFqName ?: nameResolver.getClassId(classProto!!.getFqName()).asSingleFqName() } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/AnnotationLoaderForKotlinJavaScriptStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/AnnotationLoaderForKotlinJavaScriptStubBuilder.kt index c4399511361..66a55073913 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/AnnotationLoaderForKotlinJavaScriptStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/AnnotationLoaderForKotlinJavaScriptStubBuilder.kt @@ -36,26 +36,26 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon override fun loadCallableAnnotations( container: ProtoContainer, proto: ProtoBuf.Callable, - nameResolver: NameResolver, kind: AnnotatedCallableKind - ): List { - return proto.getExtension(JsProtoBuf.callableAnnotation).orEmpty().map { ClassIdWithTarget(nameResolver.getClassId(it.id), null) } - } + ): List = + proto.getExtension(JsProtoBuf.callableAnnotation).orEmpty().map { + ClassIdWithTarget(container.nameResolver.getClassId(it.id), null) + } override fun loadValueParameterAnnotations( container: ProtoContainer, callable: ProtoBuf.Callable, - nameResolver: NameResolver, kind: AnnotatedCallableKind, parameterIndex: Int, proto: ProtoBuf.ValueParameter ): List = - proto.getExtension(JsProtoBuf.parameterAnnotation).orEmpty().map { nameResolver.getClassId(it.id) } + proto.getExtension(JsProtoBuf.parameterAnnotation).orEmpty().map { + container.nameResolver.getClassId(it.id) + } override fun loadExtensionReceiverParameterAnnotations( container: ProtoContainer, callable: ProtoBuf.Callable, - nameResolver: NameResolver, kind: AnnotatedCallableKind ): List = emptyList() @@ -68,7 +68,6 @@ public class AnnotationLoaderForKotlinJavaScriptStubBuilder() : AnnotationAndCon override fun loadPropertyConstant( container: ProtoContainer, proto: ProtoBuf.Callable, - nameResolver: NameResolver, expectedType: JetType - ): Unit {} + ) {} } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt index abbbf99765a..004efa98160 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/CallableClsStubBuilder.kt @@ -110,7 +110,7 @@ private class CallableClsStubBuilder( ) val kind = callableProto.annotatedCallableKind - val annotationIds = c.components.annotationLoader.loadCallableAnnotations(protoContainer, callableProto, c.nameResolver, kind) + val annotationIds = c.components.annotationLoader.loadCallableAnnotations(protoContainer, callableProto, kind) createTargetedAnnotationStubs(annotationIds, modifierListStubImpl) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt index a4143dce4e9..6450a4c30c1 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt @@ -157,7 +157,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) { val isVararg = valueParameterProto.hasVarargElementType() val modifierList = if (isVararg) createModifierListStub(parameterStub, listOf(JetTokens.VARARG_KEYWORD)) else null val parameterAnnotations = c.components.annotationLoader.loadValueParameterAnnotations( - container, callableProto, c.nameResolver, callableProto.annotatedCallableKind, index, valueParameterProto + container, callableProto, callableProto.annotatedCallableKind, index, valueParameterProto ) if (parameterAnnotations.isNotEmpty()) { createAnnotationStubs(parameterAnnotations, modifierList ?: createEmptyModifierList(parameterStub)) diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptAnnotationAndConstantLoader.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptAnnotationAndConstantLoader.kt index a0dbd83c0f0..c35a61cae75 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptAnnotationAndConstantLoader.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptAnnotationAndConstantLoader.kt @@ -40,29 +40,26 @@ class KotlinJavascriptAnnotationAndConstantLoader( override fun loadCallableAnnotations( container: ProtoContainer, proto: ProtoBuf.Callable, - nameResolver: NameResolver, kind: AnnotatedCallableKind ): List { val annotations = proto.getExtension(JsProtoBuf.callableAnnotation).orEmpty() - return annotations.map { proto -> AnnotationWithTarget(deserializer.deserializeAnnotation(proto, nameResolver), null) } + return annotations.map { proto -> AnnotationWithTarget(deserializer.deserializeAnnotation(proto, container.nameResolver), null) } } override fun loadValueParameterAnnotations( container: ProtoContainer, callable: ProtoBuf.Callable, - nameResolver: NameResolver, kind: AnnotatedCallableKind, parameterIndex: Int, proto: ProtoBuf.ValueParameter ): List { val annotations = proto.getExtension(JsProtoBuf.parameterAnnotation).orEmpty() - return annotations.map { proto -> deserializer.deserializeAnnotation(proto, nameResolver) } + return annotations.map { proto -> deserializer.deserializeAnnotation(proto, container.nameResolver) } } override fun loadExtensionReceiverParameterAnnotations( container: ProtoContainer, callable: ProtoBuf.Callable, - nameResolver: NameResolver, kind: AnnotatedCallableKind ): List = emptyList() @@ -74,10 +71,9 @@ class KotlinJavascriptAnnotationAndConstantLoader( override fun loadPropertyConstant( container: ProtoContainer, proto: ProtoBuf.Callable, - nameResolver: NameResolver, expectedType: JetType ): ConstantValue<*>? { val value = proto.getExtension(JsProtoBuf.compileTimeValue) - return deserializer.resolveValue(expectedType, value, nameResolver) + return deserializer.resolveValue(expectedType, value, container.nameResolver) } }