Uast: implicit receiver for function variables calls (KT-25524)
This commit is contained in:
@@ -384,6 +384,29 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLambdaParamCall() {
|
||||
doTest("Lambdas") { _, file ->
|
||||
val lambdaCall = file.findElementByTextFromPsi<UCallExpression>("selectItemFunction()")
|
||||
assertEquals(
|
||||
"UIdentifier (Identifier (selectItemFunction))",
|
||||
lambdaCall.methodIdentifier?.asLogString()
|
||||
)
|
||||
assertEquals(
|
||||
"selectItemFunction",
|
||||
lambdaCall.methodIdentifier?.name
|
||||
)
|
||||
assertEquals(
|
||||
"invoke",
|
||||
lambdaCall.methodName
|
||||
)
|
||||
val receiver = lambdaCall.receiver ?: kotlin.test.fail("receiver expected")
|
||||
assertEquals("UReferenceExpression", receiver.asLogString())
|
||||
val uParameter = (receiver as UReferenceExpression).resolve().toUElement() ?: kotlin.test.fail("uelement expected")
|
||||
assertEquals("UParameter (name = selectItemFunction)", uParameter.asLogString())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun <T, R> Iterable<T>.assertedFind(value: R, transform: (T) -> R): T =
|
||||
|
||||
@@ -227,6 +227,29 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
val uCallExpression = lambda.uastParent.assertedCast<UCallExpression> { "UCallExpression expected" }
|
||||
assertTrue(uCallExpression.valueArguments.contains(lambda))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLambdaParamCall() {
|
||||
doTest("Lambdas") { _, file ->
|
||||
val lambdaCall = file.findElementByTextFromPsi<UCallExpression>("selectItemFunction()")
|
||||
assertEquals(
|
||||
"UIdentifier (Identifier (selectItemFunction))",
|
||||
lambdaCall.methodIdentifier?.asLogString()
|
||||
)
|
||||
assertEquals(
|
||||
"selectItemFunction",
|
||||
lambdaCall.methodIdentifier?.name
|
||||
)
|
||||
assertEquals(
|
||||
"invoke",
|
||||
lambdaCall.methodName
|
||||
)
|
||||
val receiver = lambdaCall.receiver ?: kotlin.test.fail("receiver expected")
|
||||
assertEquals("UReferenceExpression", receiver.asLogString())
|
||||
val uParameter = (receiver as UReferenceExpression).resolve().toUElement() ?: kotlin.test.fail("uelement expected")
|
||||
assertEquals("UParameter (name = selectItemFunction)", uParameter.asLogString())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -348,6 +348,29 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLambdaParamCall() {
|
||||
doTest("Lambdas") { _, file ->
|
||||
val lambdaCall = file.findElementByTextFromPsi<UCallExpression>("selectItemFunction()")
|
||||
assertEquals(
|
||||
"UIdentifier (Identifier (selectItemFunction))",
|
||||
lambdaCall.methodIdentifier?.asLogString()
|
||||
)
|
||||
assertEquals(
|
||||
"selectItemFunction",
|
||||
lambdaCall.methodIdentifier?.name
|
||||
)
|
||||
assertEquals(
|
||||
"invoke",
|
||||
lambdaCall.methodName
|
||||
)
|
||||
val receiver = lambdaCall.receiver ?: kotlin.test.fail("receiver expected")
|
||||
assertEquals("UReferenceExpression", receiver.asLogString())
|
||||
val uParameter = (receiver as UReferenceExpression).resolve().toUElement() ?: kotlin.test.fail("uelement expected")
|
||||
assertEquals("UParameter (name = selectItemFunction)", uParameter.asLogString())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun <T, R> Iterable<T>.assertedFind(value: R, transform: (T) -> R): T = find { transform(it) == value } ?: throw AssertionError("'$value' not found, only ${this.joinToString { transform(it).toString() }}")
|
||||
|
||||
@@ -81,4 +81,7 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() {
|
||||
// disabled due to inconsistent parents for 2-receivers call (KT-22344)
|
||||
check(testName, file, false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLambdas() = doTest("Lambdas")
|
||||
}
|
||||
|
||||
@@ -59,4 +59,7 @@ class SimpleKotlinRenderLogTest : AbstractKotlinRenderLogTest() {
|
||||
|
||||
@Test
|
||||
fun testConstructors() = doTest("Constructors")
|
||||
|
||||
@Test
|
||||
fun testLambdas() = doTest("Lambdas")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user