DescriptorRenderer to skip @ExtensionFunctionType and @ParameterName only when it's redundant

This commit is contained in:
Valentin Kipyatkov
2016-10-07 14:57:28 +03:00
parent ec51076355
commit 968a6cfd04
7 changed files with 22 additions and 16 deletions
@@ -223,9 +223,7 @@ object ExcludedTypeAnnotations {
val internalAnnotationsForResolve = setOf(
FqName("kotlin.internal.NoInfer"),
FqName("kotlin.internal.Exact"),
KotlinBuiltIns.FQ_NAMES.extensionFunctionType,
KotlinBuiltIns.FQ_NAMES.parameterName
FqName("kotlin.internal.Exact")
)
}
@@ -46,6 +46,13 @@ internal class DescriptorRendererImpl(
assert(options.isLocked)
}
private val functionTypeAnnotationsRenderer: DescriptorRendererImpl by lazy {
this.withOptions { excludedTypeAnnotationClasses += listOf(KotlinBuiltIns.FQ_NAMES.extensionFunctionType) } as DescriptorRendererImpl
}
private val functionTypeParameterTypesRenderer: DescriptorRenderer by lazy {
this.withOptions { excludedTypeAnnotationClasses += listOf(KotlinBuiltIns.FQ_NAMES.parameterName) }
}
/* FORMATTING */
private fun renderKeyword(keyword: String): String {
when (textFormat) {
@@ -294,7 +301,10 @@ internal class DescriptorRendererImpl(
private fun StringBuilder.renderFunctionType(type: KotlinType) {
val lengthBefore = length
renderAnnotations(type)
// we need special renderer to skip @ExtensionFunctionType
with(functionTypeAnnotationsRenderer) {
renderAnnotations(type)
}
val hasAnnotations = length != lengthBefore
val isNullable = type.isMarkedNullable
@@ -335,7 +345,8 @@ internal class DescriptorRendererImpl(
append(renderName(name))
append(": ")
}
append(renderTypeProjection(typeProjection))
append(functionTypeParameterTypesRenderer.renderTypeProjection(typeProjection))
}
append(") ").append(arrow()).append(" ")