KT-56843 [SLC] Support unsafe property initializers

This commit is contained in:
Pavel Mikhailovskii
2023-03-28 08:17:37 +00:00
committed by Space Team
parent 6b62499c85
commit 85b5a4521e
28 changed files with 556 additions and 32 deletions
@@ -35,7 +35,7 @@ public class KtConstantInitializerValue(
* See [KtConstantInitializerValue] for more info.
*/
public class KtNonConstantInitializerValue(
override val initializerPsi: KtExpression?
override val initializerPsi: KtExpression?,
) : KtInitializerValue()
/**
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.analysis.api.components
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationValue
import org.jetbrains.kotlin.analysis.api.base.KtConstantValue
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
import org.jetbrains.kotlin.psi.KtExpression
@@ -32,9 +33,22 @@ public abstract class KtCompileTimeConstantProvider : KtAnalysisSessionComponent
expression: KtExpression,
mode: KtConstantEvaluationMode,
): KtConstantValue?
public abstract fun evaluateAsAnnotationValue(expression: KtExpression): KtAnnotationValue?
}
public interface KtCompileTimeConstantProviderMixIn : KtAnalysisSessionMixIn {
/**
* Tries to evaluate the provided expression using the specified mode.
* Returns a [KtConstantValue] if the expression evaluates to a compile-time constant, otherwise returns null..
*/
public fun KtExpression.evaluate(mode: KtConstantEvaluationMode): KtConstantValue? =
withValidityAssertion { analysisSession.compileTimeConstantProvider.evaluate(this, mode) }
/**
* Returns a [KtConstantValue] if the expression evaluates to a value that can be used as an annotation parameter value,
* e.g. an array of constants, otherwise returns null.
*/
public fun KtExpression.evaluateAsAnnotationValue(): KtAnnotationValue? =
withValidityAssertion { analysisSession.compileTimeConstantProvider.evaluateAsAnnotationValue(this) }
}