[Commonizer] Annotations
This commit is contained in:
+52
@@ -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
|
||||||
|
}
|
||||||
+2
-2
@@ -41,7 +41,7 @@ internal fun CirClass.buildDescriptor(
|
|||||||
val classDescriptor = CommonizedClassDescriptor(
|
val classDescriptor = CommonizedClassDescriptor(
|
||||||
targetComponents = targetComponents,
|
targetComponents = targetComponents,
|
||||||
containingDeclaration = containingDeclaration,
|
containingDeclaration = containingDeclaration,
|
||||||
annotations = annotations,
|
annotations = annotations.buildDescriptors(targetComponents),
|
||||||
name = name,
|
name = name,
|
||||||
kind = kind,
|
kind = kind,
|
||||||
modality = modality,
|
modality = modality,
|
||||||
@@ -92,7 +92,7 @@ private fun CirClassConstructor.buildDescriptor(
|
|||||||
|
|
||||||
val constructorDescriptor = CommonizedClassConstructorDescriptor(
|
val constructorDescriptor = CommonizedClassConstructorDescriptor(
|
||||||
containingDeclaration = containingDeclaration,
|
containingDeclaration = containingDeclaration,
|
||||||
annotations = annotations,
|
annotations = annotations.buildDescriptors(targetComponents),
|
||||||
isPrimary = isPrimary,
|
isPrimary = isPrimary,
|
||||||
kind = kind
|
kind = kind
|
||||||
)
|
)
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ private fun CirFunction.buildDescriptor(
|
|||||||
|
|
||||||
val functionDescriptor = SimpleFunctionDescriptorImpl.create(
|
val functionDescriptor = SimpleFunctionDescriptorImpl.create(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
annotations,
|
annotations.buildDescriptors(targetComponents),
|
||||||
name,
|
name,
|
||||||
kind,
|
kind,
|
||||||
SourceElement.NO_SOURCE
|
SourceElement.NO_SOURCE
|
||||||
|
|||||||
+5
-1
@@ -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.FieldDescriptorImpl
|
||||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||||
|
import org.jetbrains.kotlin.resolve.constants.AnnotationValue
|
||||||
|
|
||||||
internal fun CirPropertyNode.buildDescriptors(
|
internal fun CirPropertyNode.buildDescriptors(
|
||||||
components: GlobalDeclarationsBuilderComponents,
|
components: GlobalDeclarationsBuilderComponents,
|
||||||
@@ -45,7 +46,7 @@ private fun CirProperty.buildDescriptor(
|
|||||||
|
|
||||||
val propertyDescriptor = PropertyDescriptorImpl.create(
|
val propertyDescriptor = PropertyDescriptorImpl.create(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
annotations,
|
annotations.buildDescriptors(targetComponents),
|
||||||
modality,
|
modality,
|
||||||
visibility,
|
visibility,
|
||||||
isVar,
|
isVar,
|
||||||
@@ -109,6 +110,9 @@ private fun CirProperty.buildDescriptor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
compileTimeInitializer?.let { constantValue ->
|
compileTimeInitializer?.let { constantValue ->
|
||||||
|
check(constantValue !is AnnotationValue) {
|
||||||
|
"Unexpected type of compile time constant: ${constantValue::class.java}, $constantValue"
|
||||||
|
}
|
||||||
propertyDescriptor.setCompileTimeInitializer(targetComponents.storageManager.createNullableLazyValue { constantValue })
|
propertyDescriptor.setCompileTimeInitializer(targetComponents.storageManager.createNullableLazyValue { constantValue })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ private fun CirTypeAlias.buildDescriptor(
|
|||||||
val typeAliasDescriptor = CommonizedTypeAliasDescriptor(
|
val typeAliasDescriptor = CommonizedTypeAliasDescriptor(
|
||||||
storageManager = storageManager,
|
storageManager = storageManager,
|
||||||
containingDeclaration = containingDeclaration,
|
containingDeclaration = containingDeclaration,
|
||||||
annotations = annotations,
|
annotations = annotations.buildDescriptors(targetComponents),
|
||||||
name = name,
|
name = name,
|
||||||
visibility = visibility,
|
visibility = visibility,
|
||||||
isActual = isActual
|
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.commonizer.mergedtree.ir.CirSimpleTypeKind.Companion.areCompatible
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.types.*
|
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(
|
internal fun CirExtensionReceiver.buildExtensionReceiver(
|
||||||
targetComponents: TargetDeclarationsBuilderComponents,
|
targetComponents: TargetDeclarationsBuilderComponents,
|
||||||
typeParameterResolver: TypeParameterResolver,
|
typeParameterResolver: TypeParameterResolver,
|
||||||
@@ -78,7 +85,7 @@ internal fun CirExtensionReceiver.buildExtensionReceiver(
|
|||||||
) = DescriptorFactory.createExtensionReceiverParameterForCallable(
|
) = DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
type.buildType(targetComponents, typeParameterResolver),
|
type.buildType(targetComponents, typeParameterResolver),
|
||||||
annotations
|
annotations.buildDescriptors(targetComponents)
|
||||||
)
|
)
|
||||||
|
|
||||||
internal fun buildDispatchReceiver(callableDescriptor: CallableDescriptor) =
|
internal fun buildDispatchReceiver(callableDescriptor: CallableDescriptor) =
|
||||||
@@ -107,27 +114,16 @@ internal fun CirSimpleType.buildType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
CirSimpleTypeKind.CLASS, CirSimpleTypeKind.TYPE_ALIAS -> {
|
CirSimpleTypeKind.CLASS, CirSimpleTypeKind.TYPE_ALIAS -> {
|
||||||
if (fqName.isUnderStandardKotlinPackages) {
|
val classOrTypeAlias = findClassOrTypeAlias(targetComponents, fqName)
|
||||||
// look up for classifier in built-ins module:
|
checkClassifier(classOrTypeAlias, kind, fqName.isUnderStandardKotlinPackages || !targetComponents.isCommon)
|
||||||
val builtInsModule = targetComponents.builtIns.builtInsModule
|
classOrTypeAlias
|
||||||
// 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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: commonize annotations, KT-34234
|
||||||
|
val typeAnnotations = if (!targetComponents.isCommon) annotations.buildDescriptors(targetComponents) else Annotations.EMPTY
|
||||||
val rawType = simpleType(
|
val rawType = simpleType(
|
||||||
annotations = Annotations.EMPTY, // TODO: support annotations
|
annotations = typeAnnotations,
|
||||||
constructor = classifier.typeConstructor,
|
constructor = classifier.typeConstructor,
|
||||||
arguments = arguments.map { it.buildArgument(targetComponents, typeParameterResolver) },
|
arguments = arguments.map { it.buildArgument(targetComponents, typeParameterResolver) },
|
||||||
nullable = isMarkedNullable,
|
nullable = isMarkedNullable,
|
||||||
@@ -137,16 +133,36 @@ internal fun CirSimpleType.buildType(
|
|||||||
return if (isDefinitelyNotNullType) rawType.makeSimpleTypeDefinitelyNotNullOrNotNull() else rawType
|
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)
|
val classifierKind = CirSimpleTypeKind.determineKind(classifier)
|
||||||
|
|
||||||
if (strict) {
|
if (strict) {
|
||||||
check(kindInCir == classifierKind) {
|
check(kind == classifierKind) {
|
||||||
"Mismatched classifier kinds.\nFound: $classifierKind, ${classifier::class.java}, $classifier\nShould be: $kindInCir"
|
"Mismatched classifier kinds.\nFound: $classifierKind, ${classifier::class.java}, $classifier\nShould be: $kind"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
check(areCompatible(classifierKind, kindInCir)) {
|
check(areCompatible(classifierKind, kind)) {
|
||||||
"Incompatible classifier kinds.\nExpect: $classifierKind, ${classifier::class.java}, $classifier\nActual: $kindInCir"
|
"Incompatible classifier kinds.\nExpect: $classifierKind, ${classifier::class.java}, $classifier\nActual: $kind"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
@@ -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
|
||||||
|
}
|
||||||
+4
-5
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
|
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
@@ -41,7 +40,7 @@ data class CirCommonClass(
|
|||||||
override val isInline: Boolean,
|
override val isInline: Boolean,
|
||||||
override val isInner: Boolean
|
override val isInner: Boolean
|
||||||
) : CirClass {
|
) : 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 isData get() = false
|
||||||
override val isExternal get() = false
|
override val isExternal get() = false
|
||||||
override var companion: FqName? = null
|
override var companion: FqName? = null
|
||||||
@@ -57,14 +56,14 @@ data class CirCommonClassConstructor(
|
|||||||
override val hasStableParameterNames: Boolean,
|
override val hasStableParameterNames: Boolean,
|
||||||
override val hasSynthesizedParameterNames: Boolean
|
override val hasSynthesizedParameterNames: Boolean
|
||||||
) : CirClassConstructor {
|
) : 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 containingClassKind get() = unsupported()
|
||||||
override val containingClassModality get() = unsupported()
|
override val containingClassModality get() = unsupported()
|
||||||
override val containingClassIsData get() = unsupported()
|
override val containingClassIsData get() = unsupported()
|
||||||
}
|
}
|
||||||
|
|
||||||
class CirWrappedClass(private val wrapped: ClassDescriptor) : CirClass {
|
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 name get() = wrapped.name
|
||||||
override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) }
|
override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) }
|
||||||
override val companion by lazy(PUBLICATION) { wrapped.companionObjectDescriptor?.fqNameSafe }
|
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 containingClassKind get() = wrapped.containingDeclaration.kind
|
||||||
override val containingClassModality get() = wrapped.containingDeclaration.modality
|
override val containingClassModality get() = wrapped.containingDeclaration.modality
|
||||||
override val containingClassIsData get() = wrapped.containingDeclaration.isData
|
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 visibility get() = wrapped.visibility
|
||||||
override val typeParameters by lazy(PUBLICATION) {
|
override val typeParameters by lazy(PUBLICATION) {
|
||||||
wrapped.typeParameters.mapNotNull { typeParameter ->
|
wrapped.typeParameters.mapNotNull { typeParameter ->
|
||||||
|
|||||||
+1
-2
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
|
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
interface CirDeclaration
|
interface CirDeclaration
|
||||||
|
|
||||||
interface CirAnnotatedDeclaration : CirDeclaration {
|
interface CirAnnotatedDeclaration : CirDeclaration {
|
||||||
val annotations: Annotations
|
val annotations: List<CirAnnotation>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CirNamedDeclaration : CirDeclaration {
|
interface CirNamedDeclaration : CirDeclaration {
|
||||||
|
|||||||
+5
-7
@@ -6,9 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
|
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
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.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver.Companion.toReceiver
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import kotlin.LazyThreadSafetyMode.PUBLICATION
|
import kotlin.LazyThreadSafetyMode.PUBLICATION
|
||||||
|
|
||||||
interface CirFunctionOrProperty : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility, CirDeclarationWithModality, CirMaybeCallableMemberOfClass {
|
interface CirFunctionOrProperty : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclarationWithTypeParameters, CirDeclarationWithVisibility, CirDeclarationWithModality, CirMaybeCallableMemberOfClass {
|
||||||
@@ -19,14 +17,14 @@ interface CirFunctionOrProperty : CirAnnotatedDeclaration, CirNamedDeclaration,
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class CirCommonFunctionOrProperty : CirFunctionOrProperty {
|
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 containingClassKind: ClassKind? get() = unsupported()
|
||||||
final override val containingClassModality: Modality? get() = unsupported()
|
final override val containingClassModality: Modality? get() = unsupported()
|
||||||
final override val containingClassIsData: Boolean? get() = unsupported()
|
final override val containingClassIsData: Boolean? get() = unsupported()
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class CirWrappedFunctionOrProperty<T : CallableMemberDescriptor>(protected val wrapped: T) : CirFunctionOrProperty {
|
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 name get() = wrapped.name
|
||||||
final override val modality get() = wrapped.modality
|
final override val modality get() = wrapped.modality
|
||||||
final override val visibility get() = wrapped.visibility
|
final override val visibility get() = wrapped.visibility
|
||||||
@@ -42,12 +40,12 @@ abstract class CirWrappedFunctionOrProperty<T : CallableMemberDescriptor>(protec
|
|||||||
}
|
}
|
||||||
|
|
||||||
data class CirExtensionReceiver(
|
data class CirExtensionReceiver(
|
||||||
val annotations: Annotations,
|
val annotations: List<CirAnnotation>,
|
||||||
val type: CirType
|
val type: CirType
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun CirType.toReceiverNoAnnotations() = CirExtensionReceiver(Annotations.EMPTY, this)
|
fun CirType.toReceiverNoAnnotations() = CirExtensionReceiver( /* TODO: commonize annotations, KT-34234 */ emptyList(), this)
|
||||||
fun ReceiverParameterDescriptor.toReceiver() = CirExtensionReceiver(annotations, CirType.create(type))
|
fun ReceiverParameterDescriptor.toReceiver() = CirExtensionReceiver(annotations.map(::CirAnnotation), CirType.create(type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -39,6 +39,7 @@ sealed class CirType {
|
|||||||
* There is no difference between [abbreviation] and [expanded] for types representing classes and type parameters.
|
* There is no difference between [abbreviation] and [expanded] for types representing classes and type parameters.
|
||||||
*/
|
*/
|
||||||
class CirSimpleType(private val wrapped: SimpleType) : CirType() {
|
class CirSimpleType(private val wrapped: SimpleType) : CirType() {
|
||||||
|
val annotations by lazy(PUBLICATION) { abbreviation.annotations.map(::CirAnnotation) }
|
||||||
val kind = CirSimpleTypeKind.determineKind(abbreviation.declarationDescriptor)
|
val kind = CirSimpleTypeKind.determineKind(abbreviation.declarationDescriptor)
|
||||||
val fqName by lazy(PUBLICATION) { abbreviation.fqName }
|
val fqName by lazy(PUBLICATION) { abbreviation.fqName }
|
||||||
val arguments by lazy(PUBLICATION) { abbreviation.arguments.map(::CirTypeProjection) }
|
val arguments by lazy(PUBLICATION) { abbreviation.arguments.map(::CirTypeProjection) }
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ interface CirTypeAlias : CirAnnotatedDeclaration, CirNamedDeclaration, CirDeclar
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CirWrappedTypeAlias(private val wrapped: TypeAliasDescriptor) : CirTypeAlias {
|
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 name get() = wrapped.name
|
||||||
override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) }
|
override val typeParameters by lazy(PUBLICATION) { wrapped.declaredTypeParameters.map(::CirWrappedTypeParameter) }
|
||||||
override val visibility get() = wrapped.visibility
|
override val visibility get() = wrapped.visibility
|
||||||
|
|||||||
Vendored
+5
@@ -1,6 +1,9 @@
|
|||||||
expect annotation class CommonAnnotationForAnnotationClassesOnly(text: String) { val text: String }
|
expect annotation class CommonAnnotationForAnnotationClassesOnly(text: String) { val text: String }
|
||||||
expect annotation class CommonAnnotation(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 var propertyWithoutBackingField: Double
|
||||||
expect val propertyWithBackingField: Double
|
expect val propertyWithBackingField: Double
|
||||||
expect val propertyWithDelegateField: Int
|
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 AnnotatedClass(value: String) { val value: String }
|
||||||
expect class AnnotatedTypeAlias
|
expect class AnnotatedTypeAlias
|
||||||
|
|
||||||
|
expect object ObjectWithNestedAnnotations
|
||||||
|
|||||||
+12
@@ -16,6 +16,14 @@ annotation class JsAnnotationForAnnotationClassesOnly(val text: String)
|
|||||||
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
|
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
|
||||||
annotation class JsAnnotation(val text: String)
|
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")
|
@JsAnnotation("property")
|
||||||
@CommonAnnotation("property")
|
@CommonAnnotation("property")
|
||||||
actual var propertyWithoutBackingField
|
actual var propertyWithoutBackingField
|
||||||
@@ -48,3 +56,7 @@ actual class AnnotatedClass @JsAnnotation("constructor") @CommonAnnotation("cons
|
|||||||
@JsAnnotation("type-alias")
|
@JsAnnotation("type-alias")
|
||||||
@CommonAnnotation("type-alias")
|
@CommonAnnotation("type-alias")
|
||||||
actual typealias AnnotatedTypeAlias = AnnotatedClass
|
actual typealias AnnotatedTypeAlias = AnnotatedClass
|
||||||
|
|
||||||
|
@JsOuterAnnotation(inner = JsInnerAnnotation("nested-annotations"))
|
||||||
|
@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
|
||||||
|
actual object ObjectWithNestedAnnotations
|
||||||
|
|||||||
+12
@@ -16,6 +16,14 @@ annotation class JvmAnnotationForAnnotationClassesOnly(val text: String)
|
|||||||
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
|
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
|
||||||
annotation class JvmAnnotation(val text: String)
|
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")
|
@JvmAnnotation("property")
|
||||||
@CommonAnnotation("property")
|
@CommonAnnotation("property")
|
||||||
actual var propertyWithoutBackingField
|
actual var propertyWithoutBackingField
|
||||||
@@ -48,3 +56,7 @@ actual class AnnotatedClass @JvmAnnotation("constructor") @CommonAnnotation("con
|
|||||||
@JvmAnnotation("type-alias")
|
@JvmAnnotation("type-alias")
|
||||||
@CommonAnnotation("type-alias")
|
@CommonAnnotation("type-alias")
|
||||||
actual typealias AnnotatedTypeAlias = AnnotatedClass
|
actual typealias AnnotatedTypeAlias = AnnotatedClass
|
||||||
|
|
||||||
|
@JvmOuterAnnotation(inner = JvmInnerAnnotation("nested-annotations"))
|
||||||
|
@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
|
||||||
|
actual object ObjectWithNestedAnnotations
|
||||||
|
|||||||
+12
@@ -16,6 +16,14 @@ annotation class JsAnnotationForAnnotationClassesOnly(val text: String)
|
|||||||
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
|
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
|
||||||
annotation class JsAnnotation(val text: String)
|
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")
|
@JsAnnotation("property")
|
||||||
@CommonAnnotation("property")
|
@CommonAnnotation("property")
|
||||||
var propertyWithoutBackingField
|
var propertyWithoutBackingField
|
||||||
@@ -48,3 +56,7 @@ class AnnotatedClass @JsAnnotation("constructor") @CommonAnnotation("constructor
|
|||||||
@JsAnnotation("type-alias")
|
@JsAnnotation("type-alias")
|
||||||
@CommonAnnotation("type-alias")
|
@CommonAnnotation("type-alias")
|
||||||
typealias AnnotatedTypeAlias = AnnotatedClass
|
typealias AnnotatedTypeAlias = AnnotatedClass
|
||||||
|
|
||||||
|
@JsOuterAnnotation(inner = JsInnerAnnotation("nested-annotations"))
|
||||||
|
@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
|
||||||
|
object ObjectWithNestedAnnotations
|
||||||
|
|||||||
+12
@@ -16,6 +16,14 @@ annotation class JvmAnnotationForAnnotationClassesOnly(val text: String)
|
|||||||
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
|
@CommonAnnotationForAnnotationClassesOnly("annotation-class")
|
||||||
annotation class JvmAnnotation(val text: String)
|
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")
|
@JvmAnnotation("property")
|
||||||
@CommonAnnotation("property")
|
@CommonAnnotation("property")
|
||||||
var propertyWithoutBackingField
|
var propertyWithoutBackingField
|
||||||
@@ -48,3 +56,7 @@ class AnnotatedClass @JvmAnnotation("constructor") @CommonAnnotation("constructo
|
|||||||
@JvmAnnotation("type-alias")
|
@JvmAnnotation("type-alias")
|
||||||
@CommonAnnotation("type-alias")
|
@CommonAnnotation("type-alias")
|
||||||
typealias AnnotatedTypeAlias = AnnotatedClass
|
typealias AnnotatedTypeAlias = AnnotatedClass
|
||||||
|
|
||||||
|
@JvmOuterAnnotation(inner = JvmInnerAnnotation("nested-annotations"))
|
||||||
|
@CommonOuterAnnotation(inner = CommonInnerAnnotation("nested-annotations"))
|
||||||
|
object ObjectWithNestedAnnotations
|
||||||
|
|||||||
+1
-2
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.descriptors.commonizer.core
|
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.utils.EMPTY_CLASSIFIERS_CACHE
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver
|
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirExtensionReceiver
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType
|
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.ir.CirType
|
||||||
@@ -55,6 +54,6 @@ class DefaultExtensionReceiverCommonizerTest : AbstractCommonizerTest<CirExtensi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun mockExtensionReceiver(typeFqName: String) = CirExtensionReceiver(
|
private fun mockExtensionReceiver(typeFqName: String) = CirExtensionReceiver(
|
||||||
annotations = Annotations.EMPTY,
|
annotations = emptyList(),
|
||||||
type = CirType.create(mockClassType(typeFqName))
|
type = CirType.create(mockClassType(typeFqName))
|
||||||
)
|
)
|
||||||
|
|||||||
+12
-14
@@ -7,9 +7,7 @@ package org.jetbrains.kotlin.descriptors.commonizer.core
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities.*
|
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.descriptors.commonizer.mergedtree.ir.*
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
abstract class LoweringVisibilityCommonizerTest(
|
abstract class LoweringVisibilityCommonizerTest(
|
||||||
@@ -32,18 +30,18 @@ abstract class LoweringVisibilityCommonizerTest(
|
|||||||
final override fun createCommonizer() = VisibilityCommonizer.lowering(allowPrivate = allowPrivate)
|
final override fun createCommonizer() = VisibilityCommonizer.lowering(allowPrivate = allowPrivate)
|
||||||
|
|
||||||
protected fun Visibility.toMock() = object : CirFunctionOrProperty {
|
protected fun Visibility.toMock() = object : CirFunctionOrProperty {
|
||||||
override val visibility: Visibility = this@toMock
|
override val visibility = this@toMock
|
||||||
override val modality: Modality get() = if (areMembersVirtual) Modality.OPEN else Modality.FINAL
|
override val modality get() = if (areMembersVirtual) Modality.OPEN else Modality.FINAL
|
||||||
override val containingClassModality: Modality? get() = if (areMembersVirtual) Modality.OPEN else null
|
override val containingClassModality get() = if (areMembersVirtual) Modality.OPEN else null
|
||||||
override val containingClassKind: ClassKind? get() = if (areMembersVirtual) ClassKind.CLASS else null
|
override val containingClassKind get() = if (areMembersVirtual) ClassKind.CLASS else null
|
||||||
override val isExternal: Boolean get() = unsupported()
|
override val isExternal get() = unsupported()
|
||||||
override val extensionReceiver: CirExtensionReceiver? get() = unsupported()
|
override val extensionReceiver get() = unsupported()
|
||||||
override val returnType: CirType get() = unsupported()
|
override val returnType get() = unsupported()
|
||||||
override val kind: CallableMemberDescriptor.Kind get() = unsupported()
|
override val kind get() = unsupported()
|
||||||
override val annotations: Annotations get() = unsupported()
|
override val annotations get() = unsupported()
|
||||||
override val name: Name get() = unsupported()
|
override val name get() = unsupported()
|
||||||
override val containingClassIsData: Boolean? get() = unsupported()
|
override val containingClassIsData get() = unsupported()
|
||||||
override val typeParameters: List<CirTypeParameter> get() = unsupported()
|
override val typeParameters get() = unsupported()
|
||||||
}
|
}
|
||||||
|
|
||||||
class PrivateMembers : LoweringVisibilityCommonizerTest(true, false) {
|
class PrivateMembers : LoweringVisibilityCommonizerTest(true, false) {
|
||||||
|
|||||||
+12
@@ -412,11 +412,23 @@ internal class ComparingDeclarationsVisitor(
|
|||||||
|
|
||||||
check(actual != null && expected != null)
|
check(actual != null && expected != null)
|
||||||
|
|
||||||
|
visitAnnotations(
|
||||||
|
expected.annotations,
|
||||||
|
actual.annotations,
|
||||||
|
context.nextLevel("Type annotations")
|
||||||
|
)
|
||||||
|
|
||||||
val expectedUnwrapped = expected.getAbbreviation() ?: expected.unwrap()
|
val expectedUnwrapped = expected.getAbbreviation() ?: expected.unwrap()
|
||||||
val actualUnwrapped = actual.getAbbreviation() ?: actual.unwrap()
|
val actualUnwrapped = actual.getAbbreviation() ?: actual.unwrap()
|
||||||
|
|
||||||
if (expectedUnwrapped === actualUnwrapped) return
|
if (expectedUnwrapped === actualUnwrapped) return
|
||||||
|
|
||||||
|
visitAnnotations(
|
||||||
|
expectedUnwrapped.annotations,
|
||||||
|
actualUnwrapped.annotations,
|
||||||
|
context.nextLevel("Unwrapped/unabbreviated type annotations")
|
||||||
|
)
|
||||||
|
|
||||||
val expectedFqName = expectedUnwrapped.fqName
|
val expectedFqName = expectedUnwrapped.fqName
|
||||||
val actualFqName = actualUnwrapped.fqName
|
val actualFqName = actualUnwrapped.fqName
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user