[AA] provide psiType#asKtType conversion

it's useful for IDE's features such as write UAST or refactorings

^KT-62302 fixed

Merge-request: KT-MR-12414
Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
This commit is contained in:
Anna Kozlova
2023-10-05 15:18:55 +00:00
committed by Space Team
parent 62544ec9c8
commit da385210d8
26 changed files with 623 additions and 1 deletions
@@ -20,6 +20,11 @@ public abstract class KtPsiTypeProvider : KtAnalysisSessionComponent() {
isAnnotationMethod: Boolean,
allowErrorTypes: Boolean
): PsiTypeElement?
public abstract fun asKtType(
psiType: PsiType,
useSitePosition: PsiElement
): KtType?
}
public interface KtPsiTypeProviderMixIn : KtAnalysisSessionMixIn {
@@ -68,4 +73,14 @@ public interface KtPsiTypeProviderMixIn : KtAnalysisSessionMixIn {
isAnnotationMethod: Boolean = false
): PsiType? =
asPsiTypeElement(useSitePosition, allowErrorTypes, mode, isAnnotationMethod)?.type
/**
* Converts given [PsiType] to [KtType].
*
* @receiver PsiType to be converted.
* @return The converted KtType, or null if conversion is not possible e.g., [PsiType] is not resolved
*/
public fun PsiType.asKtType(useSitePosition: PsiElement): KtType? = withValidityAssertion {
analysisSession.psiTypeProvider.asKtType(this, useSitePosition)
}
}
@@ -0,0 +1,11 @@
// FILE: B.kt
class A<caret_onAirContext>K: A<String>() {
}
// FILE: A.java
class A<T> {
A<T> a = new A<>() {
T f<caret>oo() {
}
}
}
@@ -0,0 +1,2 @@
PsiType: PsiType:T
KtType: T?
@@ -0,0 +1,8 @@
// FILE: B.kt
interface B: A {
fun f<caret_onAirContext>oo(): java.util.List<String?>?
}
// FILE: A.java
public interface A {
java.util.List<? extends String> fo<caret>o();
}
@@ -0,0 +1,2 @@
PsiType: PsiType:List<? extends String>
KtType: kotlin.collections.List<kotlin.String?>?
@@ -0,0 +1,10 @@
// FILE: B.kt
class B: A<String> {
override fun <K : String?> f<caret_onAirContext>oo(): K? {
TODO("Not yet implemented")
}
}
// FILE: A.java
public interface A<T> {
<K extends T> K fo<caret>o();
}
@@ -0,0 +1,2 @@
PsiType: PsiType:K
KtType: K?
@@ -0,0 +1,8 @@
// FILE: B.kt
interface B: A {
fun fo<caret_onAirContext>o(): java.util.List<String?>?
}
// FILE: A.java
public interface A {
java.util.List<String> fo<caret>o();
}
@@ -0,0 +1,2 @@
PsiType: PsiType:List<String>
KtType: kotlin.collections.List<kotlin.String?>?
@@ -0,0 +1,8 @@
// FILE: B.kt
interface B: A {
fun f<caret_onAirContext>oo(): String?
}
// FILE: A.java
public interface A {
String fo<caret>o();
}
@@ -0,0 +1,2 @@
PsiType: PsiType:String
KtType: kotlin.String?
@@ -0,0 +1,8 @@
// FILE: B.kt
interface B: A {
fun fo<caret_onAirContext>o(): Int
}
// FILE: A.java
public interface A {
int fo<caret>o();
}
@@ -0,0 +1,2 @@
PsiType: PsiType:int
KtType: kotlin.Int
@@ -0,0 +1,8 @@
// FILE: B.kt
interface B: A<String> {
fun f<caret_onAirContext>oo(): String?
}
// FILE: A.java
public interface A<T> {
T f<caret>oo();
}
@@ -0,0 +1,2 @@
PsiType: PsiType:T
KtType: T?
@@ -0,0 +1,13 @@
// FILE: B.kt
class AK: A<String>() {
inner class BK: B<String>() {
override fun <K : String?> f<caret_onAirContext>oo(): K {
}
}
}
// FILE: A.java
class A<T> {
abstract class B<S extends T> {
abstract <K extends S> K f<caret>oo();
}
}
@@ -0,0 +1,2 @@
PsiType: PsiType:K
KtType: K?