Uast: support extendsList for reified types (KT-38173)
This commit is contained in:
@@ -6,13 +6,13 @@
|
|||||||
package org.jetbrains.uast.kotlin.psi
|
package org.jetbrains.uast.kotlin.psi
|
||||||
|
|
||||||
import com.intellij.psi.*
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.impl.light.LightMethodBuilder
|
import com.intellij.psi.impl.light.*
|
||||||
import com.intellij.psi.impl.light.LightModifierList
|
|
||||||
import com.intellij.psi.impl.light.LightParameterListBuilder
|
|
||||||
import com.intellij.psi.impl.light.LightTypeParameterBuilder
|
|
||||||
import org.jetbrains.kotlin.asJava.elements.KotlinLightTypeParameterListBuilder
|
import org.jetbrains.kotlin.asJava.elements.KotlinLightTypeParameterListBuilder
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
import org.jetbrains.kotlin.psi.KtFunction
|
||||||
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
import org.jetbrains.uast.UastErrorType
|
import org.jetbrains.uast.UastErrorType
|
||||||
@@ -30,7 +30,12 @@ internal class UastFakeLightMethod(original: KtFunction, containingClass: PsiCla
|
|||||||
p.name ?: "__no_name__",
|
p.name ?: "__no_name__",
|
||||||
this,
|
this,
|
||||||
i
|
i
|
||||||
)
|
).apply {
|
||||||
|
p.extendsBound?.getType()
|
||||||
|
?.toPsiType(this@UastFakeLightMethod, original, false)
|
||||||
|
?.safeAs<PsiClassType>()
|
||||||
|
?.let { extendsList.addReference(it) }
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,6 @@
|
|||||||
inline fun <T> function1(t: T, i: Int, s: String) {}
|
inline fun <T> function1(t: T, i: Int, s: String) {}
|
||||||
inline fun <T> function2(t: T, i: Int, s: String): T = t
|
inline fun <T> function2(t: T, i: Int, s: String): T = t
|
||||||
|
inline fun <T : CharSequence> function2CharSequence(t: T, i: Int, s: String): T = t
|
||||||
inline fun <reified T> function3(t: T, i: Int, s: String) {}
|
inline fun <reified T> function3(t: T, i: Int, s: String) {}
|
||||||
inline fun <reified T> function4(t: T, i: Int, s: String): T = t
|
inline fun <reified T> function4(t: T, i: Int, s: String): T = t
|
||||||
inline fun <reified T> function5(t: T, i: Int, s: String): Int = 42
|
inline fun <reified T> function5(t: T, i: Int, s: String): Int = 42
|
||||||
@@ -8,4 +9,5 @@ inline fun <reified T> function7(t: T, i: Int, s: String): T = t
|
|||||||
private inline fun <reified T> function8(t: T, i: Int, s: String): T = t
|
private inline fun <reified T> function8(t: T, i: Int, s: String): T = t
|
||||||
internal inline fun <reified T> function9(t: T, i: Int, s: String): T = t
|
internal inline fun <reified T> function9(t: T, i: Int, s: String): T = t
|
||||||
public inline fun <reified T> function10(t: T, i: Int, s: String): T = t
|
public inline fun <reified T> function10(t: T, i: Int, s: String): T = t
|
||||||
inline fun <reified T> T.function11(t: T, i: Int, s: String): T = t
|
inline fun <reified T> T.function11(t: T, i: Int, s: String): T = t
|
||||||
|
inline fun <reified T : CharSequence> T.function11CharSequence(t: T, i: Int, s: String): T = t
|
||||||
@@ -18,6 +18,16 @@ UFile (package = )
|
|||||||
UBlockExpression
|
UBlockExpression
|
||||||
UReturnExpression
|
UReturnExpression
|
||||||
USimpleNameReferenceExpression (identifier = t)
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = function2CharSequence)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
UMethod (name = function3)
|
UMethod (name = function3)
|
||||||
UParameter (name = t)
|
UParameter (name = t)
|
||||||
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
UAnnotation (fqName = org.jetbrains.annotations.Nullable)
|
||||||
@@ -110,3 +120,15 @@ UFile (package = )
|
|||||||
UBlockExpression
|
UBlockExpression
|
||||||
UReturnExpression
|
UReturnExpression
|
||||||
USimpleNameReferenceExpression (identifier = t)
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
UMethod (name = function11CharSequence)
|
||||||
|
UParameter (name = $this$function11CharSequence)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = t)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = i)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UParameter (name = s)
|
||||||
|
UAnnotation (fqName = org.jetbrains.annotations.NotNull)
|
||||||
|
UBlockExpression
|
||||||
|
UReturnExpression
|
||||||
|
USimpleNameReferenceExpression (identifier = t)
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ public final class ReifiedReturnTypeKt {
|
|||||||
public static final fun function2(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
public static final fun function2(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
public static final fun function2CharSequence(@org.jetbrains.annotations.NotNull t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
static fun function3(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : void {
|
static fun function3(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : void {
|
||||||
}
|
}
|
||||||
static fun function4(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
static fun function4(@org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
@@ -30,4 +33,7 @@ public final class ReifiedReturnTypeKt {
|
|||||||
static fun function11(@org.jetbrains.annotations.Nullable $this$function11: T, @org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
static fun function11(@org.jetbrains.annotations.Nullable $this$function11: T, @org.jetbrains.annotations.Nullable t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
static fun function11CharSequence(@org.jetbrains.annotations.NotNull $this$function11CharSequence: T, @org.jetbrains.annotations.NotNull t: T, @org.jetbrains.annotations.NotNull i: int, @org.jetbrains.annotations.NotNull s: java.lang.String) : T {
|
||||||
|
return t
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.jetbrains.uast.test.kotlin
|
|||||||
|
|
||||||
import com.intellij.psi.PsiAnnotation
|
import com.intellij.psi.PsiAnnotation
|
||||||
import com.intellij.psi.PsiClass
|
import com.intellij.psi.PsiClass
|
||||||
|
import com.intellij.psi.PsiClassType
|
||||||
import com.intellij.psi.PsiModifier
|
import com.intellij.psi.PsiModifier
|
||||||
import com.intellij.testFramework.RunAll
|
import com.intellij.testFramework.RunAll
|
||||||
import com.intellij.testFramework.UsefulTestCase
|
import com.intellij.testFramework.UsefulTestCase
|
||||||
@@ -12,6 +13,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
|||||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.assertedCast
|
import org.jetbrains.kotlin.utils.addToStdlib.assertedCast
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
import org.jetbrains.uast.*
|
import org.jetbrains.uast.*
|
||||||
import org.jetbrains.uast.expressions.UInjectionHost
|
import org.jetbrains.uast.expressions.UInjectionHost
|
||||||
@@ -660,6 +662,7 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
|||||||
assertEquals("""
|
assertEquals("""
|
||||||
function1 -> PsiType:void
|
function1 -> PsiType:void
|
||||||
function2 -> PsiType:T
|
function2 -> PsiType:T
|
||||||
|
function2CharSequence -> PsiType:T extends PsiType:CharSequence
|
||||||
function3 -> PsiType:void
|
function3 -> PsiType:void
|
||||||
function4 -> PsiType:T
|
function4 -> PsiType:T
|
||||||
function5 -> PsiType:int
|
function5 -> PsiType:int
|
||||||
@@ -669,7 +672,18 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
|||||||
function9 -> PsiType:T
|
function9 -> PsiType:T
|
||||||
function10 -> PsiType:T
|
function10 -> PsiType:T
|
||||||
function11 -> PsiType:T
|
function11 -> PsiType:T
|
||||||
""".trimIndent(), methods.joinToString("\n") { m -> m.name + " -> " + m.returnType.toString() })
|
function11CharSequence -> PsiType:T extends PsiType:CharSequence
|
||||||
|
""".trimIndent(), methods.joinToString("\n") { m ->
|
||||||
|
buildString {
|
||||||
|
append(m.name).append(" -> ")
|
||||||
|
append(m.returnType)
|
||||||
|
m.returnType.safeAs<PsiClassType>()?.resolve()?.extendsList?.referencedTypes?.takeIf { it.isNotEmpty() }?.let { e ->
|
||||||
|
append(" extends ")
|
||||||
|
append(e.joinToString { it.toString() })
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
for (method in methods.drop(3)) {
|
for (method in methods.drop(3)) {
|
||||||
assertEquals("assert return types comparable for '${method.name}'", method.returnType, method.returnType)
|
assertEquals("assert return types comparable for '${method.name}'", method.returnType, method.returnType)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user