Analysis API: rename KtConstantValue -> KtAnnotationValue as it is annotation specific

This commit is contained in:
Ilya Kirillov
2021-11-23 15:55:23 +01:00
parent 760e35d3b7
commit b1c8a9e886
23 changed files with 108 additions and 132 deletions
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.analysis.api
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtConstantValue
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationValue
import org.jetbrains.kotlin.psi.KtExpression
public sealed class KtInitializerValue {
@@ -13,7 +13,7 @@ public sealed class KtInitializerValue {
}
public class KtConstantInitializerValue(
public val constant: KtConstantValue,
public val constant: KtAnnotationValue,
override val initializerPsi: KtExpression?
) : KtInitializerValue()
@@ -3,9 +3,8 @@
* 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.analysis.api.symbols.markers
package org.jetbrains.kotlin.analysis.api.annotations
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedConstantValue
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.KtCallElement
@@ -22,12 +21,12 @@ import org.jetbrains.kotlin.types.ConstantValueKind
* * other annotation types, and
* * array of aforementioned types
*
* [KtLiteralConstantValue] covers first two kinds;
* [KtEnumEntryConstantValue] corresponds to enum types;
* [KtAnnotationConstantValue] represents annotation types (with annotation fq name and arguments); and
* [KtArrayConstantValue] abstracts an array of [KtConstantValue]s.
* [KtLiteralAnnotationValue] covers first two kinds;
* [KtEnumEntryAnnotationValue] corresponds to enum types;
* [KtAnnotationAnnotationValue] represents annotation types (with annotation fq name and arguments); and
* [KtArrayAnnotationValue] abstracts an array of [KtAnnotationValue]s.
*/
public sealed class KtConstantValue(
public sealed class KtAnnotationValue(
public open val sourcePsi: KtElement? = null
)
@@ -36,34 +35,34 @@ public sealed class KtConstantValue(
*/
public class KtErrorValue(
public val message: String
) : KtConstantValue()
) : KtAnnotationValue()
/**
* This represents an unsupported expression used as an annotation value.
*/
public object KtUnsupportedConstantValue : KtConstantValue()
public object KtUnsupportedAnnotationValue : KtAnnotationValue()
public class KtArrayConstantValue(
public val values: Collection<KtConstantValue>,
public class KtArrayAnnotationValue(
public val values: Collection<KtAnnotationValue>,
override val sourcePsi: KtElement?,
) : KtConstantValue()
) : KtAnnotationValue()
public class KtAnnotationConstantValue(
public class KtAnnotationAnnotationValue(
public val classId: ClassId?,
public val arguments: List<KtNamedConstantValue>,
override val sourcePsi: KtCallElement?,
) : KtConstantValue()
) : KtAnnotationValue()
public class KtEnumEntryConstantValue(
public class KtEnumEntryAnnotationValue(
public val callableId: CallableId?,
override val sourcePsi: KtElement?,
) : KtConstantValue()
) : KtAnnotationValue()
public class KtLiteralConstantValue<T>(
public class KtLiteralAnnotationValue<T>(
public val constantValueKind: ConstantValueKind<T>,
public val value: T,
override val sourcePsi: KtElement?,
) : KtConstantValue() {
) : KtAnnotationValue() {
public fun toConst(): Any? {
return (value as? Long)?.let {
when (constantValueKind) {
@@ -5,6 +5,4 @@
package org.jetbrains.kotlin.analysis.api.annotations
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtConstantValue
public data class KtNamedConstantValue(val name: String, val expression: KtConstantValue)
public data class KtNamedConstantValue(val name: String, val expression: KtAnnotationValue)
@@ -5,14 +5,14 @@
package org.jetbrains.kotlin.analysis.api.components
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtConstantValue
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationValue
import org.jetbrains.kotlin.psi.KtExpression
public abstract class KtCompileTimeConstantProvider : KtAnalysisSessionComponent() {
public abstract fun evaluate(expression: KtExpression): KtConstantValue?
public abstract fun evaluate(expression: KtExpression): KtAnnotationValue?
}
public interface KtCompileTimeConstantProviderMixIn : KtAnalysisSessionMixIn {
public fun KtExpression.evaluate(): KtConstantValue? =
public fun KtExpression.evaluate(): KtAnnotationValue? =
analysisSession.compileTimeConstantProvider.evaluate(this)
}
@@ -11,10 +11,7 @@ import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.KtConstantInitializerValue
import org.jetbrains.kotlin.analysis.api.KtInitializerValue
import org.jetbrains.kotlin.analysis.api.KtNonConstantInitializerValue
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationApplication
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationsList
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedConstantValue
import org.jetbrains.kotlin.analysis.api.annotations.annotations
import org.jetbrains.kotlin.analysis.api.annotations.*
import org.jetbrains.kotlin.analysis.api.components.KtSymbolInfoProviderMixIn
import org.jetbrains.kotlin.analysis.api.symbols.markers.*
import org.jetbrains.kotlin.analysis.api.types.KtClassErrorType
@@ -141,7 +138,7 @@ public object DebugSymbolRenderer {
append(")")
}
private fun Block.renderConstantValue(value: KtConstantValue) {
private fun Block.renderConstantValue(value: KtAnnotationValue) {
append(KtConstantValueRenderer.render(value))
}
@@ -191,7 +188,7 @@ public object DebugSymbolRenderer {
// Symbol-related values
is KtSymbol -> renderSymbolTag(value)
is KtType -> renderType(value)
is KtConstantValue -> renderConstantValue(value)
is KtAnnotationValue -> renderConstantValue(value)
is KtNamedConstantValue -> renderNamedConstantValue(value)
is KtInitializerValue -> renderKtInitializerValue(value)
is KtAnnotationApplication -> renderAnnotationApplication(value)
@@ -5,38 +5,38 @@
package org.jetbrains.kotlin.analysis.api.symbols.markers
import org.jetbrains.kotlin.analysis.api.annotations.KtNamedConstantValue
import org.jetbrains.kotlin.analysis.api.annotations.*
import org.jetbrains.kotlin.types.ConstantValueKind
public object KtConstantValueRenderer {
public fun render(value: KtConstantValue): String = buildString {
public fun render(value: KtAnnotationValue): String = buildString {
renderConstantValue(value)
}
private fun StringBuilder.renderConstantValue(value: KtConstantValue) {
private fun StringBuilder.renderConstantValue(value: KtAnnotationValue) {
when (value) {
is KtAnnotationConstantValue -> {
is KtAnnotationAnnotationValue -> {
renderAnnotationConstantValue(value)
}
is KtArrayConstantValue -> {
is KtArrayAnnotationValue -> {
renderArrayConstantValue(value)
}
is KtEnumEntryConstantValue -> {
is KtEnumEntryAnnotationValue -> {
renderEnumEntryConstantValue(value)
}
is KtErrorValue -> {
append("ERROR")
}
is KtLiteralConstantValue<*> -> {
is KtLiteralAnnotationValue<*> -> {
renderLiteralConstantValue(value)
}
KtUnsupportedConstantValue -> {
KtUnsupportedAnnotationValue -> {
append("KtUnsupportedConstantValue")
}
}
}
private fun StringBuilder.renderLiteralConstantValue(value: KtLiteralConstantValue<*>) {
private fun StringBuilder.renderLiteralConstantValue(value: KtLiteralAnnotationValue<*>) {
when (value.constantValueKind) {
ConstantValueKind.String -> {
append('"')
@@ -54,11 +54,11 @@ public object KtConstantValueRenderer {
}
}
private fun StringBuilder.renderEnumEntryConstantValue(value: KtEnumEntryConstantValue) {
private fun StringBuilder.renderEnumEntryConstantValue(value: KtEnumEntryAnnotationValue) {
append(value.callableId?.asSingleFqName()?.asString())
}
private fun StringBuilder.renderAnnotationConstantValue(value: KtAnnotationConstantValue) {
private fun StringBuilder.renderAnnotationConstantValue(value: KtAnnotationAnnotationValue) {
append(value.classId)
if (value.arguments.isNotEmpty()) {
append("(")
@@ -67,13 +67,13 @@ public object KtConstantValueRenderer {
}
}
private fun StringBuilder.renderArrayConstantValue(value: KtArrayConstantValue) {
private fun StringBuilder.renderArrayConstantValue(value: KtArrayAnnotationValue) {
append("[")
renderConstantValueList(value.values)
append("]")
}
private fun StringBuilder.renderConstantValueList(list: Collection<KtConstantValue>) {
private fun StringBuilder.renderConstantValueList(list: Collection<KtAnnotationValue>) {
renderWithSeparator(list, ", ") { constantValue ->
renderConstantValue(constantValue)
}