[LC] PsiClassRenderer: render type parameter annotations

^KT-65112
This commit is contained in:
Dmitrii Gridin
2024-02-14 16:57:59 +01:00
committed by Space Team
parent 3e3c932bf6
commit 717dd08fd4
7 changed files with 25 additions and 9 deletions
@@ -0,0 +1,3 @@
public final class C /* one.C*/<@one.Anno() T> {
public C();// .ctor()
}
@@ -0,0 +1,2 @@
public abstract interface C /* one.C*/<@one.Anno() T> {
}
@@ -0,0 +1,5 @@
public final class C /* one.C*/ {
public C();// .ctor()
public final <@one.Anno() T> void foo(T);// <@one.Anno() T> foo(T)
}
@@ -1,5 +1,5 @@
public final class C /* one.C*/ { public final class C /* one.C*/ {
public C();// .ctor() public C();// .ctor()
public final <T> int getFoo(T);// <T> getFoo(T) public final <@one.Anno() T> int getFoo(T);// <@one.Anno() T> getFoo(T)
} }
@@ -0,0 +1,3 @@
public final class FunctionTypeParameterAnnotationKt /* one.FunctionTypeParameterAnnotationKt*/ {
public static final <@one.Anno() T> void foo(T);// <@one.Anno() T> foo(T)
}
@@ -1,3 +1,3 @@
public final class PropertyTypeParameterAnnotationKt /* one.PropertyTypeParameterAnnotationKt*/ { public final class PropertyTypeParameterAnnotationKt /* one.PropertyTypeParameterAnnotationKt*/ {
public static final <T> int getFoo(T);// <T> getFoo(T) public static final <@one.Anno() T> int getFoo(T);// <@one.Anno() T> getFoo(T)
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -146,11 +146,14 @@ class PsiClassRenderer private constructor(
private fun Array<PsiTypeParameter>.renderTypeParams() = private fun Array<PsiTypeParameter>.renderTypeParams() =
if (isEmpty()) "" if (isEmpty()) ""
else "<" + joinToString { else "<" + joinToString {
val bounds = val extendsListTypes = it.extendsListTypes
if (it.extendsListTypes.isNotEmpty()) val bounds = if (extendsListTypes.isNotEmpty()) {
" extends " + it.extendsListTypes.joinToString(" & ", transform = { it.renderType() }) " extends " + extendsListTypes.joinToString(" & ", transform = { it.renderType() })
else "" } else {
it.name!! + bounds ""
}
it.renderModifiers() + it.name!! + bounds
} + "> " } + "> "
private fun KtLightPsiLiteral.renderKtLightPsiLiteral(): String { private fun KtLightPsiLiteral.renderKtLightPsiLiteral(): String {
@@ -294,7 +297,7 @@ class PsiClassRenderer private constructor(
val renderedAnnotation = annotation.renderAnnotation() val renderedAnnotation = annotation.renderAnnotation()
if (renderedAnnotation.isNotEmpty()) { if (renderedAnnotation.isNotEmpty()) {
annotationsBuffer.add( annotationsBuffer.add(
renderedAnnotation + (if (this is PsiParameter) " " else "\n") renderedAnnotation + (if (this is PsiParameter || this is PsiTypeParameter) " " else "\n")
) )
} }
} }