[cls] include property constant initializer in stubs
^KTIJ-24667 this would allow building FirElements from stubs
This commit is contained in:
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeProjection
|
||||
@@ -233,6 +234,7 @@ interface DescriptorRendererOptions {
|
||||
var boldOnlyForNamesInHtml: Boolean
|
||||
|
||||
var includePropertyConstant: Boolean
|
||||
var propertyConstantRenderer: ((ConstantValue<*>) -> String?)?
|
||||
var parameterNameRenderingPolicy: ParameterNameRenderingPolicy
|
||||
var withoutTypeParameters: Boolean
|
||||
var receiverAfterName: Boolean
|
||||
|
||||
@@ -491,9 +491,10 @@ internal class DescriptorRendererImpl(
|
||||
return (defaultList + argumentList).sorted()
|
||||
}
|
||||
|
||||
private fun renderConstant(value: ConstantValue<*>): String {
|
||||
private fun renderConstant(value: ConstantValue<*>): String? {
|
||||
options.propertyConstantRenderer?.let { return it.invoke(value) }
|
||||
return when (value) {
|
||||
is ArrayValue -> value.value.joinToString(", ", "{", "}") { renderConstant(it) }
|
||||
is ArrayValue -> value.value.mapNotNull { renderConstant(it) }.joinToString(", ", "{", "}")
|
||||
is AnnotationValue -> renderAnnotation(value.value).removePrefix("@")
|
||||
is KClassValue -> when (val classValue = value.value) {
|
||||
is KClassValue.Value.LocalClass -> "${classValue.type}::class"
|
||||
@@ -986,7 +987,8 @@ internal class DescriptorRendererImpl(
|
||||
private fun renderInitializer(variable: VariableDescriptor, builder: StringBuilder) {
|
||||
if (includePropertyConstant) {
|
||||
variable.compileTimeInitializer?.let { constant ->
|
||||
builder.append(" = ").append(escape(renderConstant(constant)))
|
||||
val renderedConstant = renderConstant(constant)
|
||||
if (renderedConstant != null) builder.append(" = ").append(escape(renderedConstant))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import java.lang.IllegalStateException
|
||||
import java.lang.reflect.Modifier
|
||||
@@ -87,6 +88,7 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
|
||||
override var actualPropertiesInPrimaryConstructor: Boolean by property(false)
|
||||
override var uninferredTypeParameterAsName by property(false)
|
||||
override var includePropertyConstant by property(false)
|
||||
override var propertyConstantRenderer: ((ConstantValue<*>) -> String?)? by property(null)
|
||||
override var withoutTypeParameters by property(false)
|
||||
override var withoutSuperTypes by property(false)
|
||||
override var typeNormalizer by property<(KotlinType) -> KotlinType>({ it })
|
||||
|
||||
Reference in New Issue
Block a user