Add ConstantValueKind to KtSimpleConstantValue

This commit is contained in:
Stanislav Erokhin
2021-01-11 14:20:43 +01:00
parent d24331955e
commit d50a5e7517
5 changed files with 9 additions and 7 deletions
@@ -58,7 +58,7 @@ object DebugSymbolRenderer {
}
"${value::class.simpleName!!}($symbolTag)"
}
is KtSimpleConstantValue<*> -> renderValue(value.constant)
is KtSimpleConstantValue<*> -> renderValue(value.value)
is KtNamedConstantValue -> "${renderValue(value.name)} = ${renderValue(value.expression)}"
is KtAnnotationCall ->
"${renderValue(value.classId)}${value.arguments.joinToString(prefix = "(", postfix = ")") { renderValue(it) }}"
@@ -5,7 +5,9 @@
package org.jetbrains.kotlin.idea.frontend.api.symbols.markers
import org.jetbrains.kotlin.types.ConstantValueKind
sealed class KtConstantValue
object KtUnsupportedConstantValue : KtConstantValue()
data class KtSimpleConstantValue<T>(val constant: T?) : KtConstantValue()
data class KtSimpleConstantValue<T>(val constantValueKind: ConstantValueKind<T>, val value: T) : KtConstantValue()
@@ -17,10 +17,8 @@ import org.jetbrains.kotlin.fir.references.FirNamedReference
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirSymbol
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.mapAnnotationParameters
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFileSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtPropertySymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtAnnotatedSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.markers.KtSimpleConstantValue
import org.jetbrains.kotlin.psi.KtFile
internal fun KtAnnotatedSymbol.hasJvmSyntheticAnnotation(annotationUseSiteTarget: AnnotationUseSiteTarget? = null): Boolean =
hasAnnotation("kotlin/jvm/JvmSynthetic", annotationUseSiteTarget)
@@ -36,7 +34,7 @@ internal fun KtAnnotatedSymbol.getJvmNameFromAnnotation(annotationUseSiteTarget:
}
return annotation?.let {
(it.arguments.firstOrNull()?.expression as? KtSimpleConstantValue<*>)?.constant as? String
(it.arguments.firstOrNull()?.expression as? KtSimpleConstantValue<*>)?.value as? String
}
}
@@ -322,7 +322,7 @@ private fun escapeString(str: String): String = buildString {
}
private fun KtSimpleConstantValue<*>.asStringForPsiLiteral(): String =
when (val value = this.constant) {
when (val value = this.value) {
is String -> "\"${escapeString(value)}\""
is Long -> "${value}L"
is Float -> "${value}f"
@@ -48,8 +48,10 @@ internal fun mapAnnotationParameters(annotationCall: FirAnnotationCall, session:
return resultSet
}
internal fun <T> FirConstExpression<T>.convertConstantExpression(): KtSimpleConstantValue<T> = KtSimpleConstantValue(kind, value)
internal fun FirExpression.convertConstantExpression(): KtConstantValue =
when (this) {
is FirConstExpression<*> -> KtSimpleConstantValue(value)
is FirConstExpression<*> -> convertConstantExpression()
else -> KtUnsupportedConstantValue
}