[Commonizer] Extract creation of CirTypeAlias from CirTypeAliasFactory
This commit is contained in:
@@ -5,7 +5,40 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.descriptors.commonizer.cir
|
package org.jetbrains.kotlin.descriptors.commonizer.cir
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.Visibility
|
||||||
|
|
||||||
interface CirTypeAlias : CirClassifier, CirLiftedUpDeclaration {
|
interface CirTypeAlias : CirClassifier, CirLiftedUpDeclaration {
|
||||||
val underlyingType: CirClassOrTypeAliasType
|
val underlyingType: CirClassOrTypeAliasType
|
||||||
val expandedType: CirClassType
|
val expandedType: CirClassType
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
inline fun create(
|
||||||
|
annotations: List<CirAnnotation>,
|
||||||
|
name: CirName,
|
||||||
|
typeParameters: List<CirTypeParameter>,
|
||||||
|
visibility: Visibility,
|
||||||
|
underlyingType: CirClassOrTypeAliasType,
|
||||||
|
expandedType: CirClassType
|
||||||
|
): CirTypeAlias = CirTypeAliasImpl(
|
||||||
|
annotations = annotations,
|
||||||
|
name = name,
|
||||||
|
typeParameters = typeParameters,
|
||||||
|
visibility = visibility,
|
||||||
|
underlyingType = underlyingType,
|
||||||
|
expandedType = expandedType
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class CirTypeAliasImpl(
|
||||||
|
override val annotations: List<CirAnnotation>,
|
||||||
|
override val name: CirName,
|
||||||
|
override val typeParameters: List<CirTypeParameter>,
|
||||||
|
override val visibility: Visibility,
|
||||||
|
override val underlyingType: CirClassOrTypeAliasType,
|
||||||
|
override val expandedType: CirClassType // only for commonization algorithm; does not participate in building resulting declarations
|
||||||
|
) : CirTypeAlias {
|
||||||
|
// any TA in "common" fragment is already lifted up
|
||||||
|
override val isLiftedUp get() = true
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-23
@@ -6,9 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.descriptors.commonizer.cir.factory
|
package org.jetbrains.kotlin.descriptors.commonizer.cir.factory
|
||||||
|
|
||||||
import kotlinx.metadata.KmTypeAlias
|
import kotlinx.metadata.KmTypeAlias
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClassOrTypeAliasType
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirName
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirTypeAliasImpl
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirTypeAlias
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.metadata.decodeVisibility
|
import org.jetbrains.kotlin.descriptors.commonizer.metadata.decodeVisibility
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ object CirTypeAliasFactory {
|
|||||||
val underlyingType = CirTypeFactory.create(source.underlyingType, typeResolver) as CirClassOrTypeAliasType
|
val underlyingType = CirTypeFactory.create(source.underlyingType, typeResolver) as CirClassOrTypeAliasType
|
||||||
val expandedType = CirTypeFactory.unabbreviate(underlyingType)
|
val expandedType = CirTypeFactory.unabbreviate(underlyingType)
|
||||||
|
|
||||||
return create(
|
return CirTypeAlias.create(
|
||||||
annotations = CirAnnotationFactory.createAnnotations(source.flags, typeResolver, source::annotations),
|
annotations = CirAnnotationFactory.createAnnotations(source.flags, typeResolver, source::annotations),
|
||||||
name = name,
|
name = name,
|
||||||
typeParameters = source.typeParameters.compactMap { CirTypeParameterFactory.create(it, typeResolver) },
|
typeParameters = source.typeParameters.compactMap { CirTypeParameterFactory.create(it, typeResolver) },
|
||||||
@@ -26,23 +26,4 @@ object CirTypeAliasFactory {
|
|||||||
expandedType = expandedType
|
expandedType = expandedType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
|
||||||
inline fun create(
|
|
||||||
annotations: List<CirAnnotation>,
|
|
||||||
name: CirName,
|
|
||||||
typeParameters: List<CirTypeParameter>,
|
|
||||||
visibility: Visibility,
|
|
||||||
underlyingType: CirClassOrTypeAliasType,
|
|
||||||
expandedType: CirClassType
|
|
||||||
): CirTypeAlias {
|
|
||||||
return CirTypeAliasImpl(
|
|
||||||
annotations = annotations,
|
|
||||||
name = name,
|
|
||||||
typeParameters = typeParameters,
|
|
||||||
visibility = visibility,
|
|
||||||
underlyingType = underlyingType,
|
|
||||||
expandedType = expandedType
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
-21
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2020 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.cir.impl
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
|
||||||
|
|
||||||
data class CirTypeAliasImpl(
|
|
||||||
override val annotations: List<CirAnnotation>,
|
|
||||||
override val name: CirName,
|
|
||||||
override val typeParameters: List<CirTypeParameter>,
|
|
||||||
override val visibility: Visibility,
|
|
||||||
override val underlyingType: CirClassOrTypeAliasType,
|
|
||||||
override val expandedType: CirClassType // only for commonization algorithm; does not participate in building resulting declarations
|
|
||||||
) : CirTypeAlias {
|
|
||||||
// any TA in "common" fragment is already lifted up
|
|
||||||
override val isLiftedUp get() = true
|
|
||||||
}
|
|
||||||
+2
-3
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
|||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeAliasFactory
|
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers
|
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.CirKnownClassifiers
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +49,7 @@ private class TypeAliasShortCircuitingCommonizer(
|
|||||||
private val expandedType = TypeCommonizer(classifiers)
|
private val expandedType = TypeCommonizer(classifiers)
|
||||||
private val visibility = VisibilityCommonizer.lowering()
|
private val visibility = VisibilityCommonizer.lowering()
|
||||||
|
|
||||||
override fun commonizationResult() = CirTypeAliasFactory.create(
|
override fun commonizationResult() = CirTypeAlias.create(
|
||||||
annotations = emptyList(),
|
annotations = emptyList(),
|
||||||
name = name,
|
name = name,
|
||||||
typeParameters = typeParameters.result,
|
typeParameters = typeParameters.result,
|
||||||
@@ -86,7 +85,7 @@ private class TypeAliasLiftingUpCommonizer(classifiers: CirKnownClassifiers) : A
|
|||||||
override fun commonizationResult(): CirTypeAlias {
|
override fun commonizationResult(): CirTypeAlias {
|
||||||
val underlyingType = underlyingType.result as CirClassOrTypeAliasType
|
val underlyingType = underlyingType.result as CirClassOrTypeAliasType
|
||||||
|
|
||||||
return CirTypeAliasFactory.create(
|
return CirTypeAlias.create(
|
||||||
annotations = emptyList(),
|
annotations = emptyList(),
|
||||||
name = name,
|
name = name,
|
||||||
typeParameters = typeParameters.result,
|
typeParameters = typeParameters.result,
|
||||||
|
|||||||
+1
-2
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.Modality
|
|||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.*
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory
|
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirClassFactory
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.factory.CirTypeAliasFactory
|
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.*
|
import org.jetbrains.kotlin.descriptors.commonizer.mergedtree.*
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderStandardKotlinPackages
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.isUnderStandardKotlinPackages
|
||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.mockClassType
|
||||||
@@ -499,7 +498,7 @@ class TypeCommonizerTest : AbstractCommonizerTest<CirType, CirType>() {
|
|||||||
typeAliasId = type.classifierId
|
typeAliasId = type.classifierId
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
node.targetDeclarations[index] = CirTypeAliasFactory.create(
|
node.targetDeclarations[index] = CirTypeAlias.create(
|
||||||
annotations = emptyList(),
|
annotations = emptyList(),
|
||||||
name = type.classifierId.relativeNameSegments.last(),
|
name = type.classifierId.relativeNameSegments.last(),
|
||||||
typeParameters = emptyList(),
|
typeParameters = emptyList(),
|
||||||
|
|||||||
Reference in New Issue
Block a user