Refactor ConstantValue implementations
Remove KotlinBuiltIns and take a ModuleDescriptor instance in getType instead. This will allow to create constant values in contexts where there's no module or built-ins accessible (such as, deserialization of module annotations during indexing of .kotlin_module files in IDE). Note that some values (KClassValue, EnumValue, AnnotationValue) still take module-dependent objects (KotlinType, ClassDescriptor and AnnotationDescriptor respectively). This is to be refactored later
This commit is contained in:
+4
-4
@@ -43,8 +43,8 @@ class ExtractableSubstringInfo(
|
||||
) {
|
||||
private fun guessLiteralType(literal: String): KotlinType {
|
||||
val facade = template.getResolutionFacade()
|
||||
val builtIns = facade.moduleDescriptor.builtIns
|
||||
val stringType = builtIns.stringType
|
||||
val module = facade.moduleDescriptor
|
||||
val stringType = module.builtIns.stringType
|
||||
|
||||
if (startEntry != endEntry || startEntry !is KtLiteralStringTemplateEntry) return stringType
|
||||
|
||||
@@ -56,10 +56,10 @@ class ExtractableSubstringInfo(
|
||||
val tempContext = expr.analyzeInContext(scope, template)
|
||||
val trace = DelegatingBindingTrace(tempContext, "Evaluate '$literal'")
|
||||
val languageVersionSettings = facade.getFrontendService(LanguageVersionSettings::class.java)
|
||||
val value = ConstantExpressionEvaluator(builtIns, languageVersionSettings).evaluateExpression(expr, trace)
|
||||
val value = ConstantExpressionEvaluator(module, languageVersionSettings).evaluateExpression(expr, trace)
|
||||
if (value == null || value.isError) return stringType
|
||||
|
||||
return value.toConstantValue(TypeUtils.NO_EXPECTED_TYPE).type
|
||||
return value.toConstantValue(TypeUtils.NO_EXPECTED_TYPE).getType(module)
|
||||
}
|
||||
|
||||
val template: KtStringTemplateExpression = startEntry.parent as KtStringTemplateExpression
|
||||
|
||||
Reference in New Issue
Block a user