Analysis API FE1.0: consider rendering parameters when rendering annotations

This commit is contained in:
Ilya Kirillov
2021-11-30 13:03:35 +01:00
parent 2d032112fd
commit 5cffcfaf9f
2 changed files with 8 additions and 5 deletions
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.analysis.api.components.KtTypeRendererOptions
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.classId
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.getKtNamedAnnotationArguments
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.maybeLocalClassId
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtConstantValue
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
@@ -32,7 +31,6 @@ import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.NewCapturedType
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
import org.jetbrains.kotlin.types.typeUtil.builtIns
import kotlin.reflect.KClass
internal class KtFe10TypeRenderer(private val options: KtTypeRendererOptions, private val isDebugText: Boolean = false) {
private companion object {
@@ -47,7 +45,11 @@ internal class KtFe10TypeRenderer(private val options: KtTypeRendererOptions, pr
if (isDebugText) {
renderTypeAnnotationsDebug(type)
} else {
renderFe10Annotations(type.annotations, isSingleLineAnnotations = true) { classId ->
renderFe10Annotations(
type.annotations,
isSingleLineAnnotations = true,
renderAnnotationWithShortNames = options.shortQualifiedNames
) { classId ->
classId != StandardClassIds.Annotations.ExtensionFunctionType
}
}
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.analysis.api.descriptors.utils
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.classId
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtConstantValue
import org.jetbrains.kotlin.analysis.api.annotations.KtAnnotationValueRenderer
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtAnnotationValue
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
@@ -20,6 +19,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
internal fun PrettyPrinter.renderFe10Annotations(
annotations: Annotations,
isSingleLineAnnotations: Boolean,
renderAnnotationWithShortNames: Boolean,
predicate: (ClassId) -> Boolean = { true }
) {
val separator = if (isSingleLineAnnotations) " " else "\n"
@@ -32,7 +32,8 @@ internal fun PrettyPrinter.renderFe10Annotations(
if (annotationClass.fqNameSafe != StandardNames.FqNames.parameterName) {
append('@')
append(annotation.fqName?.shortName()?.asString() ?: "ERROR")
val rendered = if (renderAnnotationWithShortNames) annotation.fqName?.shortName()?.render() else annotation.fqName?.render()
append(rendered ?: "ERROR")
val valueArguments = annotation.allValueArguments.entries.sortedBy { it.key.asString() }
printCollectionIfNotEmpty(valueArguments, separator = ", ", prefix = "(", postfix = ")") { (name, value) ->