K2: Simplify FirToConstantValueTransformer hierarchy
FirToConstantValueTransformerSafe was unused and then there only one FirToConstantValueTransformer left
This commit is contained in:
committed by
Space Team
parent
379ec2fae8
commit
f7e54fa76a
+3
-12
@@ -32,17 +32,13 @@ internal inline fun <reified T : ConstantValue<*>> FirExpression.toConstantValue
|
|||||||
constValueProvider: ConstValueProvider? = null
|
constValueProvider: ConstValueProvider? = null
|
||||||
): T? {
|
): T? {
|
||||||
return constValueProvider?.findConstantValueFor(this) as? T
|
return constValueProvider?.findConstantValueFor(this) as? T
|
||||||
?: accept(FirToConstantValueTransformerUnsafe(), FirToConstantValueTransformerData(session, constValueProvider)) as? T
|
?: accept(FirToConstantValueTransformer, FirToConstantValueTransformerData(session, constValueProvider)) as? T
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun FirExpression?.hasConstantValue(session: FirSession): Boolean {
|
internal fun FirExpression?.hasConstantValue(session: FirSession): Boolean {
|
||||||
return this?.accept(FirToConstantValueChecker, session) == true
|
return this?.accept(FirToConstantValueChecker, session) == true
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class FirToConstantValueTransformerSafe : FirToConstantValueTransformer(failOnNonConst = false)
|
|
||||||
|
|
||||||
internal class FirToConstantValueTransformerUnsafe : FirToConstantValueTransformer(failOnNonConst = true)
|
|
||||||
|
|
||||||
internal data class FirToConstantValueTransformerData(
|
internal data class FirToConstantValueTransformerData(
|
||||||
val session: FirSession,
|
val session: FirSession,
|
||||||
val constValueProvider: ConstValueProvider?,
|
val constValueProvider: ConstValueProvider?,
|
||||||
@@ -50,9 +46,7 @@ internal data class FirToConstantValueTransformerData(
|
|||||||
|
|
||||||
private val constantIntrinsicCalls = setOf("toByte", "toLong", "toShort", "toFloat", "toDouble", "toChar", "unaryMinus")
|
private val constantIntrinsicCalls = setOf("toByte", "toLong", "toShort", "toFloat", "toDouble", "toChar", "unaryMinus")
|
||||||
|
|
||||||
internal abstract class FirToConstantValueTransformer(
|
internal object FirToConstantValueTransformer : FirDefaultVisitor<ConstantValue<*>?, FirToConstantValueTransformerData>() {
|
||||||
private val failOnNonConst: Boolean,
|
|
||||||
) : FirDefaultVisitor<ConstantValue<*>?, FirToConstantValueTransformerData>() {
|
|
||||||
private fun FirExpression.toConstantValue(data: FirToConstantValueTransformerData): ConstantValue<*>? {
|
private fun FirExpression.toConstantValue(data: FirToConstantValueTransformerData): ConstantValue<*>? {
|
||||||
return data.constValueProvider?.findConstantValueFor(this)
|
return data.constValueProvider?.findConstantValueFor(this)
|
||||||
?: accept(this@FirToConstantValueTransformer, data)
|
?: accept(this@FirToConstantValueTransformer, data)
|
||||||
@@ -62,10 +56,7 @@ internal abstract class FirToConstantValueTransformer(
|
|||||||
element: FirElement,
|
element: FirElement,
|
||||||
data: FirToConstantValueTransformerData
|
data: FirToConstantValueTransformerData
|
||||||
): ConstantValue<*>? {
|
): ConstantValue<*>? {
|
||||||
if (failOnNonConst) {
|
error("Illegal element as annotation argument: ${element::class.qualifiedName} -> ${element.render()}")
|
||||||
error("Illegal element as annotation argument: ${element::class.qualifiedName} -> ${element.render()}")
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <T> visitConstExpression(
|
override fun <T> visitConstExpression(
|
||||||
|
|||||||
Reference in New Issue
Block a user