FIR IDE: add test case for resolving call as value argument
This commit is contained in:
Vendored
+7
@@ -0,0 +1,7 @@
|
|||||||
|
infix fun <A, B> A.to(other: B) = this
|
||||||
|
|
||||||
|
open class A<T>(x: T)
|
||||||
|
|
||||||
|
class B : A(<selection>1 to 2</selection>)
|
||||||
|
|
||||||
|
// CALL: KtFunctionCall: targetFunction = to(<receiver>: A, other: B): A
|
||||||
+10
-7
@@ -11,6 +11,7 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.testFramework.LightCodeInsightTestCase
|
import com.intellij.testFramework.LightCodeInsightTestCase
|
||||||
import org.jetbrains.kotlin.idea.addExternalTestFiles
|
import org.jetbrains.kotlin.idea.addExternalTestFiles
|
||||||
import org.jetbrains.kotlin.idea.executeOnPooledThreadInReadAction
|
import org.jetbrains.kotlin.idea.executeOnPooledThreadInReadAction
|
||||||
|
import org.jetbrains.kotlin.idea.frontend.api.KtAnalysisSession
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.analyze
|
import org.jetbrains.kotlin.idea.frontend.api.analyze
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.calls.KtCall
|
import org.jetbrains.kotlin.idea.frontend.api.calls.KtCall
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.calls.KtErrorCallTarget
|
import org.jetbrains.kotlin.idea.frontend.api.calls.KtErrorCallTarget
|
||||||
@@ -22,6 +23,7 @@ import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
|||||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
import org.jetbrains.kotlin.psi.KtValueArgument
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.elementsInRange
|
import org.jetbrains.kotlin.psi.psiUtil.elementsInRange
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||||
@@ -44,13 +46,7 @@ abstract class AbstractResolveCallTest : @Suppress("DEPRECATION") LightCodeInsig
|
|||||||
|
|
||||||
val actualText = executeOnPooledThreadInReadAction {
|
val actualText = executeOnPooledThreadInReadAction {
|
||||||
val callInfos = analyze(file as KtFile) {
|
val callInfos = analyze(file as KtFile) {
|
||||||
elements.map { element ->
|
elements.map { resolveCall(it) }
|
||||||
when (element) {
|
|
||||||
is KtCallExpression -> element.resolveCall()
|
|
||||||
is KtBinaryExpression -> element.resolveCall()
|
|
||||||
else -> error("Selected should be either KtCallExpression or KtBinaryExpression but was $element")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callInfos.isEmpty()) {
|
if (callInfos.isEmpty()) {
|
||||||
@@ -72,6 +68,13 @@ abstract class AbstractResolveCallTest : @Suppress("DEPRECATION") LightCodeInsig
|
|||||||
KotlinTestUtils.assertEqualsToFile(File(path), actualText)
|
KotlinTestUtils.assertEqualsToFile(File(path), actualText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun KtAnalysisSession.resolveCall(element: PsiElement): KtCall? = when (element) {
|
||||||
|
is KtCallExpression -> element.resolveCall()
|
||||||
|
is KtBinaryExpression -> element.resolveCall()
|
||||||
|
is KtValueArgument -> resolveCall(element.getArgumentExpression()!!)
|
||||||
|
else -> error("Selected should be either KtCallExpression or KtBinaryExpression but was $element")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getSingleSelectedElement(selection: CaretState): PsiElement {
|
private fun getSingleSelectedElement(selection: CaretState): PsiElement {
|
||||||
val selectionRange = selection.getTextRange()
|
val selectionRange = selection.getTextRange()
|
||||||
|
|||||||
+5
@@ -59,6 +59,11 @@ public class ResolveCallTestGenerated extends AbstractResolveCallTest {
|
|||||||
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/javaFunctionCall.kt");
|
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/javaFunctionCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("resolveCallInSuperConstructorParam.kt")
|
||||||
|
public void testResolveCallInSuperConstructorParam() throws Exception {
|
||||||
|
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/resolveCallInSuperConstructorParam.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simpleCallWithNonMatchingArgs.kt")
|
@TestMetadata("simpleCallWithNonMatchingArgs.kt")
|
||||||
public void testSimpleCallWithNonMatchingArgs() throws Exception {
|
public void testSimpleCallWithNonMatchingArgs() throws Exception {
|
||||||
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/simpleCallWithNonMatchingArgs.kt");
|
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/simpleCallWithNonMatchingArgs.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user