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:
Alexander Udalov
2017-12-29 13:04:36 +01:00
parent 5e97517c8b
commit 907f53e539
22 changed files with 207 additions and 247 deletions
@@ -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