[FIR] FirRenderer: render receiver annotation

^KT-54417
This commit is contained in:
Dmitrii Gridin
2022-11-02 16:31:43 +01:00
committed by Space Team
parent 649bf92d98
commit 40c64c672d
3 changed files with 12 additions and 9 deletions
@@ -1,10 +1,10 @@
public final class A : R|kotlin/Any| { public final class A : R|kotlin/Any| {
public final fun R|kotlin/String|.myLength(@R|test/Ann|() q: R|kotlin/String|): R|kotlin/Int| public final fun @RECEIVER:R|test/Ann|() R|kotlin/String|.myLength(@R|test/Ann|() q: R|kotlin/String|): R|kotlin/Int|
public final val R|kotlin/String|.myLength2: R|kotlin/Int| public final val @RECEIVER:R|test/Ann|() R|kotlin/String|.myLength2: R|kotlin/Int|
public get(): R|kotlin/Int| public get(): R|kotlin/Int|
public final var R|kotlin/String|.myLength3: R|kotlin/Int| public final var @RECEIVER:R|test/Ann|() R|kotlin/String|.myLength3: R|kotlin/Int|
public get(): R|kotlin/Int| public get(): R|kotlin/Int|
public set(v: R|kotlin/Int|): R|kotlin/Unit| public set(v: R|kotlin/Int|): R|kotlin/Unit|
@@ -19,22 +19,23 @@ open class FirAnnotationRenderer {
protected val printer get() = components.printer protected val printer get() = components.printer
protected val callArgumentsRenderer get() = components.callArgumentsRenderer protected val callArgumentsRenderer get() = components.callArgumentsRenderer
fun render(annotationContainer: FirAnnotationContainer) { fun render(annotationContainer: FirAnnotationContainer, explicitAnnotationUseSiteTarget: AnnotationUseSiteTarget? = null) {
renderAnnotations(annotationContainer.annotations) renderAnnotations(annotationContainer.annotations, explicitAnnotationUseSiteTarget)
} }
internal fun renderAnnotations(annotations: List<FirAnnotation>) { internal fun renderAnnotations(annotations: List<FirAnnotation>, explicitAnnotationUseSiteTarget: AnnotationUseSiteTarget? = null) {
for (annotation in annotations) { for (annotation in annotations) {
renderAnnotation(annotation) renderAnnotation(annotation, explicitAnnotationUseSiteTarget)
} }
} }
internal fun renderAnnotation(annotation: FirAnnotation) { internal fun renderAnnotation(annotation: FirAnnotation, explicitAnnotationUseSiteTarget: AnnotationUseSiteTarget? = null) {
printer.print("@") printer.print("@")
annotation.useSiteTarget?.let { (explicitAnnotationUseSiteTarget ?: annotation.useSiteTarget)?.let {
printer.print(it.name) printer.print(it.name)
printer.print(":") printer.print(":")
} }
annotation.annotationTypeRef.accept(visitor) annotation.annotationTypeRef.accept(visitor)
when (annotation) { when (annotation) {
is FirAnnotationCall -> if (annotation.calleeReference.let { it is FirResolvedNamedReference || it is FirErrorNamedReference }) { is FirAnnotationCall -> if (annotation.calleeReference.let { it is FirResolvedNamedReference || it is FirErrorNamedReference }) {
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.renderer package org.jetbrains.kotlin.fir.renderer
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.contracts.FirContractDescription import org.jetbrains.kotlin.fir.contracts.FirContractDescription
import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration import org.jetbrains.kotlin.fir.contracts.FirEffectDeclaration
@@ -182,6 +183,7 @@ class FirRenderer(
val receiverParameter = callableDeclaration.receiverParameter val receiverParameter = callableDeclaration.receiverParameter
print(" ") print(" ")
if (receiverParameter != null) { if (receiverParameter != null) {
annotationRenderer?.render(receiverParameter, AnnotationUseSiteTarget.RECEIVER)
receiverParameter.type.accept(this) receiverParameter.type.accept(this)
print(".") print(".")
} }