[Analysis API] reuse PsiClassRenderer for PsiType render
To align the format with light classes as now we are powered by them ^KT-66603
This commit is contained in:
committed by
Space Team
parent
54aee57fec
commit
2fbde7a85c
+2
-1
@@ -13,6 +13,7 @@ import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport
|
||||
import org.jetbrains.kotlin.asJava.PsiClassRenderer
|
||||
import org.jetbrains.kotlin.asJava.classes.KtLightClass
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightElement
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
@@ -26,7 +27,7 @@ object AnalysisApiPsiTypeProviderTestUtils {
|
||||
context(KtAnalysisSession)
|
||||
fun render(type: KtType?, variance: Variance = Variance.INVARIANT): String? = type?.render(position = variance)
|
||||
|
||||
fun render(type: PsiType?): String? = type?.getCanonicalText(/* annotated = */ true)
|
||||
fun render(type: PsiType?): String? = type?.let(PsiClassRenderer::renderType)
|
||||
|
||||
internal fun getContainingKtLightClass(
|
||||
declaration: KtDeclaration,
|
||||
|
||||
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
PsiType: @MyAnno KotlinClass
|
||||
PsiType: @MyAnno() KotlinClass
|
||||
KtType: @MyAnno KotlinClass?
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
PsiType: java.lang.@MyAnno String
|
||||
PsiType: @MyAnno() java.lang.String
|
||||
KtType: @MyAnno kotlin.String?
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: @foo.MyAnno(s = "outer") kotlin.collections.List<@foo.MyAnno(s = "middle") kotlin.collections.List<@foo.AnotherAnnotation(k = foo.Nested::class) kotlin.String>>
|
||||
PsiType: java.util.@foo.MyAnno("outer") List<? extends java.util.@foo.MyAnno("middle") List<? extends java.lang.@foo.AnotherAnnotation(Nested::class) String>>
|
||||
PsiType: @foo.MyAnno(s = "outer") java.util.List<? extends @foo.MyAnno(s = "middle") java.util.List<? extends @foo.AnotherAnnotation(k = foo.Nested.class) java.lang.String>>
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: suspend (kotlin.Int) -> kotlin.Unit
|
||||
PsiType: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super kotlin.coroutines.Continuation<? super kotlin.Unit>,? extends java.lang.Object>
|
||||
PsiType: kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super kotlin.coroutines.Continuation<? super kotlin.Unit>, ? extends java.lang.Object>
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: suspend (kotlin.Int) -> kotlin.Unit
|
||||
PsiType: PsiType:Function2<? super Integer, ? super NonExistentClass<Unit>, ? extends Object>
|
||||
PsiType: kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super error.NonExistentClass<kotlin.Unit>, ? extends java.lang.Object>
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: suspend (kotlin.Int) -> kotlin.Unit
|
||||
PsiType: kotlin.jvm.functions.Function2<? super java.lang.Integer,? super kotlin.coroutines.Continuation<? super kotlin.Unit>,? extends java.lang.Object>
|
||||
PsiType: kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super kotlin.coroutines.Continuation<? super kotlin.Unit>, ? extends java.lang.Object>
|
||||
|
||||
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: @foo.MyAnno(s = "str1") kotlin.String
|
||||
PsiType: java.lang.@foo.MyAnno("str" + "1") String
|
||||
PsiType: @foo.MyAnno(s = "str1") java.lang.String
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: @kotlin.jvm.JvmSuppressWildcards(suppress = false) (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)?
|
||||
PsiType: kotlin.jvm.functions.Function1<? super .AnimatedContentTransitionScope<.NavBackStackEntry>,? extends .EnterTransition>
|
||||
PsiType: kotlin.jvm.functions.Function1<? super .AnimatedContentTransitionScope<.NavBackStackEntry>, ? extends .EnterTransition>
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: @kotlin.jvm.JvmSuppressWildcards(suppress = false) (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)?
|
||||
PsiType: kotlin.jvm.functions.@kotlin.jvm.JvmSuppressWildcards(suppress = false) Function1<? super AnimatedContentTransitionScope<NavBackStackEntry>,? extends EnterTransition>
|
||||
PsiType: @kotlin.jvm.JvmSuppressWildcards(suppress = false) kotlin.jvm.functions.Function1<? super AnimatedContentTransitionScope<NavBackStackEntry>, ? extends EnterTransition>
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: @kotlin.jvm.JvmSuppressWildcards(suppress = true) (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)?
|
||||
PsiType: kotlin.jvm.functions.Function1<.AnimatedContentTransitionScope<.NavBackStackEntry>,.EnterTransition>
|
||||
PsiType: kotlin.jvm.functions.Function1<.AnimatedContentTransitionScope<.NavBackStackEntry>, .EnterTransition>
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
KtType: @kotlin.jvm.JvmSuppressWildcards(suppress = true) (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)?
|
||||
PsiType: kotlin.jvm.functions.@kotlin.jvm.JvmSuppressWildcards(suppress = true) Function1<AnimatedContentTransitionScope<NavBackStackEntry>,EnterTransition>
|
||||
PsiType: @kotlin.jvm.JvmSuppressWildcards(suppress = true) kotlin.jvm.functions.Function1<AnimatedContentTransitionScope<NavBackStackEntry>, EnterTransition>
|
||||
|
||||
@@ -44,6 +44,10 @@ class PsiClassRenderer private constructor(
|
||||
membersFilter: MembersFilter = MembersFilter.DEFAULT
|
||||
): String =
|
||||
PsiClassRenderer(renderInner, membersFilter).renderClass(psiClass)
|
||||
|
||||
fun renderType(psiType: PsiType): String = with(PsiClassRenderer(renderInner = false, membersFilter = MembersFilter.DEFAULT)) {
|
||||
psiType.renderType()
|
||||
}
|
||||
}
|
||||
|
||||
private fun PrettyPrinter.renderClass(psiClass: PsiClass) {
|
||||
|
||||
Reference in New Issue
Block a user