[Commonizer] Annotations

This commit is contained in:
Dmitriy Dolovov
2019-10-08 12:12:12 +07:00
parent 72869e848d
commit ddc5a62e4a
20 changed files with 206 additions and 59 deletions
@@ -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<Name, ConstantValue<*>>
) : 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
}
@@ -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
)
@@ -43,7 +43,7 @@ private fun CirFunction.buildDescriptor(
val functionDescriptor = SimpleFunctionDescriptorImpl.create(
containingDeclaration,
annotations,
annotations.buildDescriptors(targetComponents),
name,
kind,
SourceElement.NO_SOURCE
@@ -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 })
}
@@ -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
@@ -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<CirValueParameter>.buildDescriptors(
)
}
internal fun List<CirAnnotation>.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<ClassifierDescriptorWithTypeParameters>()
?.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"
}
}
}
@@ -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<Name, ConstantValue<*>> get() = wrapped.allValueArguments
}
@@ -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<CirAnnotation> 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<CirAnnotation> 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 ->
@@ -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<CirAnnotation>
}
interface CirNamedDeclaration : CirDeclaration {
@@ -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<CirAnnotation> 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<T : CallableMemberDescriptor>(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<T : CallableMemberDescriptor>(protec
}
data class CirExtensionReceiver(
val annotations: Annotations,
val annotations: List<CirAnnotation>,
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))
}
}
@@ -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) }
@@ -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
@@ -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 : Number> Q.function2(): Q
expect class AnnotatedClass(value: String) { val value: String }
expect class AnnotatedTypeAlias
expect object ObjectWithNestedAnnotations
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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<CirExtensi
}
private fun mockExtensionReceiver(typeFqName: String) = CirExtensionReceiver(
annotations = Annotations.EMPTY,
annotations = emptyList(),
type = CirType.create(mockClassType(typeFqName))
)
@@ -7,9 +7,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.Visibilities.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.*
import org.jetbrains.kotlin.name.Name
import org.junit.Test
abstract class LoweringVisibilityCommonizerTest(
@@ -32,18 +30,18 @@ abstract class LoweringVisibilityCommonizerTest(
final override fun createCommonizer() = VisibilityCommonizer.lowering(allowPrivate = allowPrivate)
protected fun Visibility.toMock() = object : CirFunctionOrProperty {
override val visibility: Visibility = this@toMock
override val modality: Modality get() = if (areMembersVirtual) Modality.OPEN else Modality.FINAL
override val containingClassModality: Modality? get() = if (areMembersVirtual) Modality.OPEN else null
override val containingClassKind: ClassKind? get() = if (areMembersVirtual) ClassKind.CLASS else null
override val isExternal: Boolean get() = unsupported()
override val extensionReceiver: CirExtensionReceiver? get() = unsupported()
override val returnType: CirType get() = unsupported()
override val kind: CallableMemberDescriptor.Kind get() = unsupported()
override val annotations: Annotations get() = unsupported()
override val name: Name get() = unsupported()
override val containingClassIsData: Boolean? get() = unsupported()
override val typeParameters: List<CirTypeParameter> 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) {
@@ -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