Uast: testing resolve for method called on variables of parametrized types

This commit is contained in:
Nicolay Mitropolsky
2019-02-28 15:27:59 +03:00
parent 5268cd4663
commit ec1badf60d
3 changed files with 54 additions and 19 deletions
+12 -1
View File
@@ -1,4 +1,4 @@
class A { open class A {
fun foo() {} fun foo() {}
inline fun inlineFoo() { inline fun inlineFoo() {
@@ -17,3 +17,14 @@ fun bar() {
intRange.contains(2 as Int) // extension-fun with @JvmName("longRangeContains") intRange.contains(2 as Int) // extension-fun with @JvmName("longRangeContains")
IntRange(1, 2) // constructor from stdlib IntRange(1, 2) // constructor from stdlib
} }
fun <T : A> barT(t: T) {
t.foo()
}
fun <T : List<A>> barTL(listT: T) {
listT.isEmpty()
for (a in listT) {
a.foo()
}
}
+21 -9
View File
@@ -431,7 +431,6 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
@Test @Test
fun testResolvedDeserializedMethod() = doTest("Resolve") { _, file -> fun testResolvedDeserializedMethod() = doTest("Resolve") { _, file ->
val barMethod = file.findElementByTextFromPsi<UElement>("bar").getParentOfType<UMethod>()!!
fun UElement.assertResolveCall(callText: String, methodName: String = callText.substringBefore("(")) { fun UElement.assertResolveCall(callText: String, methodName: String = callText.substringBefore("(")) {
this.findElementByTextFromPsi<UCallExpression>(callText).let { this.findElementByTextFromPsi<UCallExpression>(callText).let {
@@ -439,14 +438,27 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
assertEquals(methodName, resolve.name) assertEquals(methodName, resolve.name)
} }
} }
barMethod.assertResolveCall("foo()")
barMethod.assertResolveCall("inlineFoo()") file.findElementByTextFromPsi<UElement>("bar").getParentOfType<UMethod>()!!.let { barMethod ->
barMethod.assertResolveCall("forEach { println(it) }", "forEach") barMethod.assertResolveCall("foo()")
barMethod.assertResolveCall("joinToString()") barMethod.assertResolveCall("inlineFoo()")
barMethod.assertResolveCall("last()") barMethod.assertResolveCall("forEach { println(it) }", "forEach")
barMethod.assertResolveCall("setValue(\"123\")") barMethod.assertResolveCall("joinToString()")
barMethod.assertResolveCall("contains(2 as Int)", "longRangeContains") barMethod.assertResolveCall("last()")
barMethod.assertResolveCall("IntRange(1, 2)") barMethod.assertResolveCall("setValue(\"123\")")
barMethod.assertResolveCall("contains(2 as Int)", "longRangeContains")
barMethod.assertResolveCall("IntRange(1, 2)")
}
file.findElementByTextFromPsi<UElement>("barT").getParentOfType<UMethod>()!!.let { barMethod ->
barMethod.assertResolveCall("foo()")
}
file.findElementByTextFromPsi<UElement>("listT").getParentOfType<UMethod>()!!.let { barMethod ->
barMethod.assertResolveCall("isEmpty()")
barMethod.assertResolveCall("foo()")
}
} }
@Test @Test
@@ -432,7 +432,6 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
@Test @Test
fun testResolvedDeserializedMethod() = doTest("Resolve") { _, file -> fun testResolvedDeserializedMethod() = doTest("Resolve") { _, file ->
val barMethod = file.findElementByTextFromPsi<UElement>("bar").getParentOfType<UMethod>()!!
fun UElement.assertResolveCall(callText: String, methodName: String = callText.substringBefore("(")) { fun UElement.assertResolveCall(callText: String, methodName: String = callText.substringBefore("(")) {
this.findElementByTextFromPsi<UCallExpression>(callText).let { this.findElementByTextFromPsi<UCallExpression>(callText).let {
@@ -440,14 +439,27 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
assertEquals(methodName, resolve.name) assertEquals(methodName, resolve.name)
} }
} }
barMethod.assertResolveCall("foo()")
barMethod.assertResolveCall("inlineFoo()") file.findElementByTextFromPsi<UElement>("bar").getParentOfType<UMethod>()!!.let { barMethod ->
barMethod.assertResolveCall("forEach { println(it) }", "forEach") barMethod.assertResolveCall("foo()")
barMethod.assertResolveCall("joinToString()") barMethod.assertResolveCall("inlineFoo()")
barMethod.assertResolveCall("last()") barMethod.assertResolveCall("forEach { println(it) }", "forEach")
barMethod.assertResolveCall("setValue(\"123\")") barMethod.assertResolveCall("joinToString()")
barMethod.assertResolveCall("contains(2 as Int)", "longRangeContains") barMethod.assertResolveCall("last()")
barMethod.assertResolveCall("IntRange(1, 2)") barMethod.assertResolveCall("setValue(\"123\")")
barMethod.assertResolveCall("contains(2 as Int)", "longRangeContains")
barMethod.assertResolveCall("IntRange(1, 2)")
}
file.findElementByTextFromPsi<UElement>("barT").getParentOfType<UMethod>()!!.let { barMethod ->
barMethod.assertResolveCall("foo()")
}
file.findElementByTextFromPsi<UElement>("listT").getParentOfType<UMethod>()!!.let { barMethod ->
barMethod.assertResolveCall("isEmpty()")
barMethod.assertResolveCall("foo()")
}
} }
@Test @Test