diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt index 72c9bafdde8..df1d894dd11 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/AbstractBinaryClassAnnotationAndConstantLoader.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.load.kotlin @@ -30,6 +19,8 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.protobuf.MessageLite +import org.jetbrains.kotlin.resolve.constants.ConstantValue +import org.jetbrains.kotlin.resolve.constants.KClassValue import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind import org.jetbrains.kotlin.serialization.deserialization.AnnotationAndConstantLoader import org.jetbrains.kotlin.serialization.deserialization.ProtoContainer @@ -405,6 +396,20 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader( } } + protected fun isRepeatableWithImplicitContainer(annotationClassId: ClassId, arguments: Map>): Boolean { + if (annotationClassId != SpecialJvmAnnotations.JAVA_LANG_ANNOTATION_REPEATABLE) return false + + val containerKClassValue = arguments[Name.identifier("value")] as? KClassValue ?: return false + val normalClass = containerKClassValue.value as? KClassValue.Value.NormalClass ?: return false + val classId = normalClass.classId + if (classId.outerClassId == null || + classId.shortClassName.asString() != JvmAbi.REPEATABLE_ANNOTATION_CONTAINER_NAME + ) return false + + val klass = kotlinClassFinder.findKotlinClass(classId) + return klass != null && SpecialJvmAnnotations.isAnnotatedWithContainerMetaAnnotation(klass) + } + private class Storage( val memberAnnotations: Map>, val propertyConstants: Map diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt index faac6c3aeec..271d0d4b44e 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/kotlin/BinaryClassAnnotationAndConstantLoaderImpl.kt @@ -1,27 +1,13 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.load.kotlin -import org.jetbrains.kotlin.SpecialJvmAnnotations import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl -import org.jetbrains.kotlin.load.java.JvmAbi -import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass.AnnotationArrayArgumentVisitor import org.jetbrains.kotlin.metadata.ProtoBuf @@ -145,12 +131,11 @@ class BinaryClassAnnotationAndConstantLoaderImpl( } override fun visitEnd() { - val annotation = AnnotationDescriptorImpl(annotationClass.defaultType, arguments, source) // Do not load the @java.lang.annotation.Repeatable annotation instance generated automatically by the compiler for // Kotlin-repeatable annotation classes. Otherwise the reference to the implicit nested "Container" class cannot be // resolved, since that class is only generated in the backend, and is not visible to the frontend. - if (!isRepeatableWithImplicitContainer(annotation)) { - result.add(annotation) + if (!isRepeatableWithImplicitContainer(annotationClassId, arguments)) { + result.add(AnnotationDescriptorImpl(annotationClass.defaultType, arguments, source)) } } @@ -164,18 +149,4 @@ class BinaryClassAnnotationAndConstantLoaderImpl( private fun resolveClass(classId: ClassId): ClassDescriptor { return module.findNonGenericClassAcrossDependencies(classId, notFoundClasses) } - - private fun isRepeatableWithImplicitContainer(annotation: AnnotationDescriptor): Boolean { - if (annotation.fqName != JvmAnnotationNames.REPEATABLE_ANNOTATION) return false - - val containerKClassValue = annotation.allValueArguments[Name.identifier("value")] as? KClassValue ?: return false - val normalClass = containerKClassValue.value as? KClassValue.Value.NormalClass ?: return false - val classId = normalClass.classId - if (classId.outerClassId == null || - classId.shortClassName.asString() != JvmAbi.REPEATABLE_ANNOTATION_CONTAINER_NAME - ) return false - - val klass = kotlinClassFinder.findKotlinClass(classId) - return klass != null && SpecialJvmAnnotations.isAnnotatedWithContainerMetaAnnotation(klass) - } }