diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedAnnotationDescriptor.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedAnnotationDescriptor.kt new file mode 100644 index 00000000000..7a009a4ba67 --- /dev/null +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedAnnotationDescriptor.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2010-2019 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.descriptors.commonizer.builder + +import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.ClassKind.ANNOTATION_CLASS +import org.jetbrains.kotlin.descriptors.SourceElement +import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirAnnotation +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.constants.AnnotationValue +import org.jetbrains.kotlin.resolve.constants.ConstantValue +import org.jetbrains.kotlin.storage.getValue + +class CommonizedAnnotationDescriptor( + private val targetComponents: TargetDeclarationsBuilderComponents, + override val fqName: FqName, + rawValueArguments: Map> +) : AnnotationDescriptor { + constructor(targetComponents: TargetDeclarationsBuilderComponents, cirAnnotation: CirAnnotation) : this( + targetComponents, + cirAnnotation.fqName, + cirAnnotation.allValueArguments + ) + + override val type by targetComponents.storageManager.createLazyValue { + val annotationClass = findClassOrTypeAlias(targetComponents, fqName) + check(annotationClass is ClassDescriptor && annotationClass.kind == ANNOTATION_CLASS) { + "Not an annotation class: ${annotationClass::class.java}, $annotationClass" + } + annotationClass.defaultType + } + + override val allValueArguments by targetComponents.storageManager.createLazyValue { + rawValueArguments.mapValues { (_, value) -> substituteValueArgument(value) } + } + + override val source: SourceElement get() = SourceElement.NO_SOURCE + + private fun substituteValueArgument(value: ConstantValue<*>) = + (value as? AnnotationValue)?.value?.let { nestedAnnotationDescriptor -> + // re-build annotation descriptors + val fqName = nestedAnnotationDescriptor.fqName + ?: error("Annotation with no FQ name: ${nestedAnnotationDescriptor::class.java}, $nestedAnnotationDescriptor") + + AnnotationValue(CommonizedAnnotationDescriptor(targetComponents, fqName, nestedAnnotationDescriptor.allValueArguments)) + } ?: value // keep other values as they are platform agnostic +} diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt index 090d6235121..7fb470c933e 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/classDescriptors.kt @@ -41,7 +41,7 @@ internal fun CirClass.buildDescriptor( val classDescriptor = CommonizedClassDescriptor( targetComponents = targetComponents, containingDeclaration = containingDeclaration, - annotations = annotations, + annotations = annotations.buildDescriptors(targetComponents), name = name, kind = kind, modality = modality, @@ -92,7 +92,7 @@ private fun CirClassConstructor.buildDescriptor( val constructorDescriptor = CommonizedClassConstructorDescriptor( containingDeclaration = containingDeclaration, - annotations = annotations, + annotations = annotations.buildDescriptors(targetComponents), isPrimary = isPrimary, kind = kind ) diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt index fbdd00510ec..5e178a33139 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/functionDescriptors.kt @@ -43,7 +43,7 @@ private fun CirFunction.buildDescriptor( val functionDescriptor = SimpleFunctionDescriptorImpl.create( containingDeclaration, - annotations, + annotations.buildDescriptors(targetComponents), name, kind, SourceElement.NO_SOURCE diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt index 257e018d3e4..99e803700a5 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/propertyDescriptors.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.indexOfCommon import org.jetbrains.kotlin.descriptors.impl.FieldDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl import org.jetbrains.kotlin.resolve.DescriptorFactory +import org.jetbrains.kotlin.resolve.constants.AnnotationValue internal fun CirPropertyNode.buildDescriptors( components: GlobalDeclarationsBuilderComponents, @@ -45,7 +46,7 @@ private fun CirProperty.buildDescriptor( val propertyDescriptor = PropertyDescriptorImpl.create( containingDeclaration, - annotations, + annotations.buildDescriptors(targetComponents), modality, visibility, isVar, @@ -109,6 +110,9 @@ private fun CirProperty.buildDescriptor( ) compileTimeInitializer?.let { constantValue -> + check(constantValue !is AnnotationValue) { + "Unexpected type of compile time constant: ${constantValue::class.java}, $constantValue" + } propertyDescriptor.setCompileTimeInitializer(targetComponents.storageManager.createNullableLazyValue { constantValue }) } diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt index d5118eac485..4eb6b066075 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/typeAliasDescriptors.kt @@ -44,7 +44,7 @@ private fun CirTypeAlias.buildDescriptor( val typeAliasDescriptor = CommonizedTypeAliasDescriptor( storageManager = storageManager, containingDeclaration = containingDeclaration, - annotations = annotations, + annotations = annotations.buildDescriptors(targetComponents), name = name, visibility = visibility, isActual = isActual diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/utils.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/utils.kt index 49e41c30784..32b42ccdde5 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/utils.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/utils.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.* import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirSimpleTypeKind.Companion.areCompatible import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl import org.jetbrains.kotlin.incremental.components.NoLookupLocation +import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.DescriptorFactory import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.types.* @@ -71,6 +72,12 @@ internal fun List.buildDescriptors( ) } +internal fun List.buildDescriptors(targetComponents: TargetDeclarationsBuilderComponents): Annotations = + if (isEmpty()) + Annotations.EMPTY + else + Annotations.create(map { CommonizedAnnotationDescriptor(targetComponents, it) }) + internal fun CirExtensionReceiver.buildExtensionReceiver( targetComponents: TargetDeclarationsBuilderComponents, typeParameterResolver: TypeParameterResolver, @@ -78,7 +85,7 @@ internal fun CirExtensionReceiver.buildExtensionReceiver( ) = DescriptorFactory.createExtensionReceiverParameterForCallable( containingDeclaration, type.buildType(targetComponents, typeParameterResolver), - annotations + annotations.buildDescriptors(targetComponents) ) internal fun buildDispatchReceiver(callableDescriptor: CallableDescriptor) = @@ -107,27 +114,16 @@ internal fun CirSimpleType.buildType( } CirSimpleTypeKind.CLASS, CirSimpleTypeKind.TYPE_ALIAS -> { - if (fqName.isUnderStandardKotlinPackages) { - // look up for classifier in built-ins module: - val builtInsModule = targetComponents.builtIns.builtInsModule - // TODO: this works fine for Native as far as built-ins module contains full Native stdlib, but this is not enough for JVM and JS - builtInsModule.getPackage(fqName.parent()) - .memberScope - .getContributedClassifier(fqName.shortName(), NoLookupLocation.FOR_ALREADY_TRACKED) - ?.cast() - ?.also { checkClassifier(it, kind, true) } - ?: error("Classifier $fqName not found in built-ins module $builtInsModule") - } else { - // otherwise, look up in created descriptors cache: - targetComponents.getCachedClassifier(fqName) - ?.also { checkClassifier(it, kind, !targetComponents.isCommon) } - ?: error("Classifier $fqName not found in created descriptors cache") - } + val classOrTypeAlias = findClassOrTypeAlias(targetComponents, fqName) + checkClassifier(classOrTypeAlias, kind, fqName.isUnderStandardKotlinPackages || !targetComponents.isCommon) + classOrTypeAlias } } + // TODO: commonize annotations, KT-34234 + val typeAnnotations = if (!targetComponents.isCommon) annotations.buildDescriptors(targetComponents) else Annotations.EMPTY val rawType = simpleType( - annotations = Annotations.EMPTY, // TODO: support annotations + annotations = typeAnnotations, constructor = classifier.typeConstructor, arguments = arguments.map { it.buildArgument(targetComponents, typeParameterResolver) }, nullable = isMarkedNullable, @@ -137,16 +133,36 @@ internal fun CirSimpleType.buildType( return if (isDefinitelyNotNullType) rawType.makeSimpleTypeDefinitelyNotNullOrNotNull() else rawType } -private fun checkClassifier(classifier: ClassifierDescriptor, kindInCir: CirSimpleTypeKind, strict: Boolean) { +internal fun findClassOrTypeAlias( + targetComponents: TargetDeclarationsBuilderComponents, + fqName: FqName +): ClassifierDescriptorWithTypeParameters { + return if (fqName.isUnderStandardKotlinPackages) { + // look up for classifier in built-ins module: + val builtInsModule = targetComponents.builtIns.builtInsModule + // TODO: this works fine for Native as far as built-ins module contains full Native stdlib, but this is not enough for JVM and JS + builtInsModule.getPackage(fqName.parent()) + .memberScope + .getContributedClassifier(fqName.shortName(), NoLookupLocation.FOR_ALREADY_TRACKED) + ?.cast() + ?: error("Classifier $fqName not found in built-ins module $builtInsModule") + } else { + // otherwise, look up in created descriptors cache: + targetComponents.getCachedClassifier(fqName) + ?: error("Classifier $fqName not found in created descriptors cache") + } +} + +private fun checkClassifier(classifier: ClassifierDescriptor, kind: CirSimpleTypeKind, strict: Boolean) { val classifierKind = CirSimpleTypeKind.determineKind(classifier) if (strict) { - check(kindInCir == classifierKind) { - "Mismatched classifier kinds.\nFound: $classifierKind, ${classifier::class.java}, $classifier\nShould be: $kindInCir" + check(kind == classifierKind) { + "Mismatched classifier kinds.\nFound: $classifierKind, ${classifier::class.java}, $classifier\nShould be: $kind" } } else { - check(areCompatible(classifierKind, kindInCir)) { - "Incompatible classifier kinds.\nExpect: $classifierKind, ${classifier::class.java}, $classifier\nActual: $kindInCir" + check(areCompatible(classifierKind, kind)) { + "Incompatible classifier kinds.\nExpect: $classifierKind, ${classifier::class.java}, $classifier\nActual: $kind" } } } diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirAnnotation.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirAnnotation.kt new file mode 100644 index 00000000000..3f60981e11a --- /dev/null +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirAnnotation.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2010-2019 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.descriptors.commonizer.mergedtree.ir + +import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.constants.ConstantValue + +class CirAnnotation(private val wrapped: AnnotationDescriptor) { + val fqName: FqName get() = wrapped.fqName ?: error("Annotation with no FQ name: ${wrapped::class.java}, $wrapped") + val allValueArguments: Map> get() = wrapped.allValueArguments +} diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirClass.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirClass.kt index 6add6273311..ff0daff53e4 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirClass.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirClass.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe @@ -41,7 +40,7 @@ data class CirCommonClass( override val isInline: Boolean, override val isInner: Boolean ) : CirClass { - override val annotations get() = Annotations.EMPTY + override val annotations: List get() = emptyList() // TODO: commonize annotations, KT-34234 override val isData get() = false override val isExternal get() = false override var companion: FqName? = null @@ -57,14 +56,14 @@ data class CirCommonClassConstructor( override val hasStableParameterNames: Boolean, override val hasSynthesizedParameterNames: Boolean ) : CirClassConstructor { - override val annotations get() = Annotations.EMPTY + override val annotations: List get() = emptyList() // TODO: commonize annotations, KT-34234 override val containingClassKind get() = unsupported() override val containingClassModality get() = unsupported() override val containingClassIsData get() = unsupported() } class CirWrappedClass(private val wrapped: ClassDescriptor) : CirClass { - override val annotations get() = wrapped.annotations + override val annotations by lazy(PUBLICATION) { wrapped.annotations.map(::CirAnnotation) } override val name get() = wrapped.name override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) } override val companion by lazy(PUBLICATION) { wrapped.companionObjectDescriptor?.fqNameSafe } @@ -85,7 +84,7 @@ class CirWrappedClassConstructor(private val wrapped: ClassConstructorDescriptor override val containingClassKind get() = wrapped.containingDeclaration.kind override val containingClassModality get() = wrapped.containingDeclaration.modality override val containingClassIsData get() = wrapped.containingDeclaration.isData - override val annotations get() = wrapped.annotations + override val annotations by lazy(PUBLICATION) { wrapped.annotations.map(::CirAnnotation) } override val visibility get() = wrapped.visibility override val typeParameters by lazy(PUBLICATION) { wrapped.typeParameters.mapNotNull { typeParameter -> diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirDeclaration.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirDeclaration.kt index 4fc5f6c1f40..ff28ba15f7d 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirDeclaration.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirDeclaration.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -25,7 +24,7 @@ import org.jetbrains.kotlin.name.Name interface CirDeclaration interface CirAnnotatedDeclaration : CirDeclaration { - val annotations: Annotations + val annotations: List } interface CirNamedDeclaration : CirDeclaration { diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunctionOrProperty.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunctionOrProperty.kt index cd3679459cf..771fa793074 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunctionOrProperty.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirFunctionOrProperty.kt @@ -6,9 +6,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver.Companion.toReceiver -import org.jetbrains.kotlin.types.KotlinType import kotlin.LazyThreadSafetyMode.PUBLICATION interface CirFunctionOrProperty : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility, CirDeclarationWithModality, CirMaybeCallableMemberOfClass { @@ -19,14 +17,14 @@ interface CirFunctionOrProperty : CirAnnotatedDeclaration, CirNamedDeclaration, } abstract class CirCommonFunctionOrProperty : CirFunctionOrProperty { - final override val annotations get() = Annotations.EMPTY + final override val annotations: List get() = emptyList() // TODO: commonize annotations, KT-34234 final override val containingClassKind: ClassKind? get() = unsupported() final override val containingClassModality: Modality? get() = unsupported() final override val containingClassIsData: Boolean? get() = unsupported() } abstract class CirWrappedFunctionOrProperty(protected val wrapped: T) : CirFunctionOrProperty { - final override val annotations get() = wrapped.annotations + final override val annotations by lazy(PUBLICATION) { wrapped.annotations.map(::CirAnnotation) } final override val name get() = wrapped.name final override val modality get() = wrapped.modality final override val visibility get() = wrapped.visibility @@ -42,12 +40,12 @@ abstract class CirWrappedFunctionOrProperty(protec } data class CirExtensionReceiver( - val annotations: Annotations, + val annotations: List, val type: CirType ) { companion object { - fun CirType.toReceiverNoAnnotations() = CirExtensionReceiver(Annotations.EMPTY, this) - fun ReceiverParameterDescriptor.toReceiver() = CirExtensionReceiver(annotations, CirType.create(type)) + fun CirType.toReceiverNoAnnotations() = CirExtensionReceiver( /* TODO: commonize annotations, KT-34234 */ emptyList(), this) + fun ReceiverParameterDescriptor.toReceiver() = CirExtensionReceiver(annotations.map(::CirAnnotation), CirType.create(type)) } } diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirType.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirType.kt index 56ebbb42815..e51430c56ed 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirType.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirType.kt @@ -39,6 +39,7 @@ sealed class CirType { * There is no difference between [abbreviation] and [expanded] for types representing classes and type parameters. */ class CirSimpleType(private val wrapped: SimpleType) : CirType() { + val annotations by lazy(PUBLICATION) { abbreviation.annotations.map(::CirAnnotation) } val kind = CirSimpleTypeKind.determineKind(abbreviation.declarationDescriptor) val fqName by lazy(PUBLICATION) { abbreviation.fqName } val arguments by lazy(PUBLICATION) { abbreviation.arguments.map(::CirTypeProjection) } diff --git a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeAlias.kt b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeAlias.kt index 3826a7fde23..8af491f1339 100644 --- a/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeAlias.kt +++ b/konan/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/ir/CirTypeAlias.kt @@ -14,7 +14,7 @@ interface CirTypeAlias : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclar } class CirWrappedTypeAlias(private val wrapped: TypeAliasDescriptor) : CirTypeAlias { - override val annotations get() = wrapped.annotations + override val annotations by lazy(PUBLICATION) { wrapped.annotations.map(::CirAnnotation) } override val name get() = wrapped.name override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) } override val visibility get() = wrapped.visibility diff --git a/konan/commonizer/testData/generalCommonization/annotations/commonized/common/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/commonized/common/package_root.kt index d0832528670..17b4eccd559 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/commonized/common/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/commonized/common/package_root.kt @@ -1,6 +1,9 @@ expect annotation class CommonAnnotationForAnnotationClassesOnly(text: String) { val text: String } expect annotation class CommonAnnotation(text: String) { val text: String } +expect annotation class CommonOuterAnnotation(inner: CommonInnerAnnotation) { val inner: CommonInnerAnnotation } +expect annotation class CommonInnerAnnotation(text: String) { val text: String } + expect var propertyWithoutBackingField: Double expect val propertyWithBackingField: Double expect val propertyWithDelegateField: Int @@ -11,3 +14,5 @@ expect fun Q.function2(): Q expect class AnnotatedClass(value: String) { val value: String } expect class AnnotatedTypeAlias + +expect object ObjectWithNestedAnnotations diff --git a/konan/commonizer/testData/generalCommonization/annotations/commonized/js/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/commonized/js/package_root.kt index a235cc5aea5..0703b048eb5 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/commonized/js/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/commonized/js/package_root.kt @@ -16,6 +16,14 @@ annotation class JsAnnotationForAnnotationClassesOnly(val text: String) @CommonAnnotationForAnnotationClassesOnly("annotation-class") annotation class JsAnnotation(val text: String) +@Target(AnnotationTarget.CLASS) +actual annotation class CommonOuterAnnotation(actual val inner: CommonInnerAnnotation) +actual annotation class CommonInnerAnnotation(actual val text: String) + +@Target(AnnotationTarget.CLASS) +annotation class JsOuterAnnotation(val inner: JsInnerAnnotation) +annotation class JsInnerAnnotation(val text: String) + @JsAnnotation("property") @CommonAnnotation("property") actual var propertyWithoutBackingField @@ -48,3 +56,7 @@ actual class AnnotatedClass @JsAnnotation("constructor") @CommonAnnotation("cons @JsAnnotation("type-alias") @CommonAnnotation("type-alias") actual typealias AnnotatedTypeAlias = AnnotatedClass + +@JsOuterAnnotation(inner = JsInnerAnnotation("nested-annotations")) +@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations")) +actual object ObjectWithNestedAnnotations diff --git a/konan/commonizer/testData/generalCommonization/annotations/commonized/jvm/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/commonized/jvm/package_root.kt index 2178c626759..c031d2bc23c 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/commonized/jvm/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/commonized/jvm/package_root.kt @@ -16,6 +16,14 @@ annotation class JvmAnnotationForAnnotationClassesOnly(val text: String) @CommonAnnotationForAnnotationClassesOnly("annotation-class") annotation class JvmAnnotation(val text: String) +@Target(AnnotationTarget.CLASS) +actual annotation class CommonOuterAnnotation(actual val inner: CommonInnerAnnotation) +actual annotation class CommonInnerAnnotation(actual val text: String) + +@Target(AnnotationTarget.CLASS) +annotation class JvmOuterAnnotation(val inner: JvmInnerAnnotation) +annotation class JvmInnerAnnotation(val text: String) + @JvmAnnotation("property") @CommonAnnotation("property") actual var propertyWithoutBackingField @@ -48,3 +56,7 @@ actual class AnnotatedClass @JvmAnnotation("constructor") @CommonAnnotation("con @JvmAnnotation("type-alias") @CommonAnnotation("type-alias") actual typealias AnnotatedTypeAlias = AnnotatedClass + +@JvmOuterAnnotation(inner = JvmInnerAnnotation("nested-annotations")) +@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations")) +actual object ObjectWithNestedAnnotations diff --git a/konan/commonizer/testData/generalCommonization/annotations/original/js/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/original/js/package_root.kt index c4424dc7394..9241f5a88f4 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/original/js/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/original/js/package_root.kt @@ -16,6 +16,14 @@ annotation class JsAnnotationForAnnotationClassesOnly(val text: String) @CommonAnnotationForAnnotationClassesOnly("annotation-class") annotation class JsAnnotation(val text: String) +@Target(AnnotationTarget.CLASS) +annotation class CommonOuterAnnotation(val inner: CommonInnerAnnotation) +annotation class CommonInnerAnnotation(val text: String) + +@Target(AnnotationTarget.CLASS) +annotation class JsOuterAnnotation(val inner: JsInnerAnnotation) +annotation class JsInnerAnnotation(val text: String) + @JsAnnotation("property") @CommonAnnotation("property") var propertyWithoutBackingField @@ -48,3 +56,7 @@ class AnnotatedClass @JsAnnotation("constructor") @CommonAnnotation("constructor @JsAnnotation("type-alias") @CommonAnnotation("type-alias") typealias AnnotatedTypeAlias = AnnotatedClass + +@JsOuterAnnotation(inner = JsInnerAnnotation("nested-annotations")) +@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations")) +object ObjectWithNestedAnnotations diff --git a/konan/commonizer/testData/generalCommonization/annotations/original/jvm/package_root.kt b/konan/commonizer/testData/generalCommonization/annotations/original/jvm/package_root.kt index c04f8f2f246..759195b8f95 100644 --- a/konan/commonizer/testData/generalCommonization/annotations/original/jvm/package_root.kt +++ b/konan/commonizer/testData/generalCommonization/annotations/original/jvm/package_root.kt @@ -16,6 +16,14 @@ annotation class JvmAnnotationForAnnotationClassesOnly(val text: String) @CommonAnnotationForAnnotationClassesOnly("annotation-class") annotation class JvmAnnotation(val text: String) +@Target(AnnotationTarget.CLASS) +annotation class CommonOuterAnnotation(val inner: CommonInnerAnnotation) +annotation class CommonInnerAnnotation(val text: String) + +@Target(AnnotationTarget.CLASS) +annotation class JvmOuterAnnotation(val inner: JvmInnerAnnotation) +annotation class JvmInnerAnnotation(val text: String) + @JvmAnnotation("property") @CommonAnnotation("property") var propertyWithoutBackingField @@ -48,3 +56,7 @@ class AnnotatedClass @JvmAnnotation("constructor") @CommonAnnotation("constructo @JvmAnnotation("type-alias") @CommonAnnotation("type-alias") typealias AnnotatedTypeAlias = AnnotatedClass + +@JvmOuterAnnotation(inner = JvmInnerAnnotation("nested-annotations")) +@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations")) +object ObjectWithNestedAnnotations diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultExtensionReceiverCommonizerTest.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultExtensionReceiverCommonizerTest.kt index 5b8bbe599be..e04c320979f 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultExtensionReceiverCommonizerTest.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/core/DefaultExtensionReceiverCommonizerTest.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.descriptors.commonizer.core -import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.commonizer.utils.EMPTY_CLASSIFIERS_CACHE import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType @@ -55,6 +54,6 @@ class DefaultExtensionReceiverCommonizerTest : AbstractCommonizerTest get() = unsupported() + override val visibility = this@toMock + override val modality get() = if (areMembersVirtual) Modality.OPEN else Modality.FINAL + override val containingClassModality get() = if (areMembersVirtual) Modality.OPEN else null + override val containingClassKind get() = if (areMembersVirtual) ClassKind.CLASS else null + override val isExternal get() = unsupported() + override val extensionReceiver get() = unsupported() + override val returnType get() = unsupported() + override val kind get() = unsupported() + override val annotations get() = unsupported() + override val name get() = unsupported() + override val containingClassIsData get() = unsupported() + override val typeParameters get() = unsupported() } class PrivateMembers : LoweringVisibilityCommonizerTest(true, false) { diff --git a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/ComparingDeclarationsVisitor.kt b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/ComparingDeclarationsVisitor.kt index 36da5f610a1..cde44d55040 100644 --- a/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/ComparingDeclarationsVisitor.kt +++ b/konan/commonizer/tests/org/jetbrains/kotlin/descriptors/commonizer/utils/ComparingDeclarationsVisitor.kt @@ -412,11 +412,23 @@ internal class ComparingDeclarationsVisitor( check(actual != null && expected != null) + visitAnnotations( + expected.annotations, + actual.annotations, + context.nextLevel("Type annotations") + ) + val expectedUnwrapped = expected.getAbbreviation() ?: expected.unwrap() val actualUnwrapped = actual.getAbbreviation() ?: actual.unwrap() if (expectedUnwrapped === actualUnwrapped) return + visitAnnotations( + expectedUnwrapped.annotations, + actualUnwrapped.annotations, + context.nextLevel("Unwrapped/unabbreviated type annotations") + ) + val expectedFqName = expectedUnwrapped.fqName val actualFqName = actualUnwrapped.fqName