[FIR] JavaTypeParameterStack: allow nullable return from get
It is not always possible to have the correct mapping, at least on the Analysis API side ^KT-66530 Fixed
This commit is contained in:
committed by
Space Team
parent
eb8054ac1e
commit
675bf36049
+30
@@ -57,6 +57,24 @@ public class FirIdeDependentAnalysisSourceModuleAnalysisApiKtTypeByPsiTypeProvid
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/extends.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameterWithKotlinUseSite.kt")
|
||||
public void testMethodTypeParameterWithKotlinUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/methodTypeParameterWithKotlinUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameterWithMethodUseSite.kt")
|
||||
public void testMethodTypeParameterWithMethodUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/methodTypeParameterWithMethodUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameterWithTypeParameterUseSite.kt")
|
||||
public void testMethodTypeParameterWithTypeParameterUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/methodTypeParameterWithTypeParameterUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameters.kt")
|
||||
public void testMethodTypeParameters() {
|
||||
@@ -81,6 +99,18 @@ public class FirIdeDependentAnalysisSourceModuleAnalysisApiKtTypeByPsiTypeProvid
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/primitive.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameterWithKotlinUseSite.kt")
|
||||
public void testTypeParameterWithKotlinUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/typeParameterWithKotlinUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameterWithMethodUseSite.kt")
|
||||
public void testTypeParameterWithMethodUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/typeParameterWithMethodUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameters.kt")
|
||||
public void testTypeParameters() {
|
||||
|
||||
+30
@@ -57,6 +57,24 @@ public class FirIdeNormalAnalysisSourceModuleAnalysisApiKtTypeByPsiTypeProviderT
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/extends.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameterWithKotlinUseSite.kt")
|
||||
public void testMethodTypeParameterWithKotlinUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/methodTypeParameterWithKotlinUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameterWithMethodUseSite.kt")
|
||||
public void testMethodTypeParameterWithMethodUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/methodTypeParameterWithMethodUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameterWithTypeParameterUseSite.kt")
|
||||
public void testMethodTypeParameterWithTypeParameterUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/methodTypeParameterWithTypeParameterUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameters.kt")
|
||||
public void testMethodTypeParameters() {
|
||||
@@ -81,6 +99,18 @@ public class FirIdeNormalAnalysisSourceModuleAnalysisApiKtTypeByPsiTypeProviderT
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/primitive.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameterWithKotlinUseSite.kt")
|
||||
public void testTypeParameterWithKotlinUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/typeParameterWithKotlinUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameterWithMethodUseSite.kt")
|
||||
public void testTypeParameterWithMethodUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/typeParameterWithMethodUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameters.kt")
|
||||
public void testTypeParameters() {
|
||||
|
||||
+30
-9
@@ -5,13 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.psiTypeProvider
|
||||
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedTest
|
||||
import org.jetbrains.kotlin.analysis.test.framework.project.structure.ktModuleProvider
|
||||
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
|
||||
import org.jetbrains.kotlin.analysis.test.framework.utils.executeOnPooledThreadInReadAction
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.parentOfType
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
@@ -21,19 +21,14 @@ import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
abstract class AbstractAnalysisApiKtTypeByPsiTypeProviderTest : AbstractAnalysisApiBasedTest() {
|
||||
override fun doTestByMainFile(mainFile: KtFile, mainModule: TestModule, testServices: TestServices) {
|
||||
val psiMethod = testServices.moduleStructure.modules.map { module ->
|
||||
val psiFiles = testServices.ktModuleProvider.getModuleFiles(module).filterIsInstance<PsiJavaFile>()
|
||||
val javaFile = psiFiles.first()
|
||||
val offset = testServices.expressionMarkerProvider.getCaretPosition(javaFile)
|
||||
PsiTreeUtil.getParentOfType(javaFile.findElementAt(offset), PsiMethod::class.java)
|
||||
}.single()!!
|
||||
val (psiMethod, useSitePosition) = getTestDataContext(testServices)
|
||||
|
||||
val actual = buildString {
|
||||
executeOnPooledThreadInReadAction {
|
||||
analyseForTest(mainFile) {
|
||||
val returnType = psiMethod.returnType
|
||||
testServices.assertions.assertNotNull(returnType)
|
||||
val asKtTypeSuper = returnType!!.asKtType(psiMethod)!!
|
||||
val asKtTypeSuper = returnType!!.asKtType(useSitePosition ?: psiMethod)!!
|
||||
appendLine("PsiType: $returnType")
|
||||
appendLine("KtType: ${asKtTypeSuper.render(position = Variance.OUT_VARIANCE)}")
|
||||
}
|
||||
@@ -43,3 +38,29 @@ abstract class AbstractAnalysisApiKtTypeByPsiTypeProviderTest : AbstractAnalysis
|
||||
testServices.assertions.assertEqualsToTestDataFileSibling(actual)
|
||||
}
|
||||
}
|
||||
|
||||
private data class TestDataContext(val targetMethod: PsiMethod, val useSitePosition: PsiElement?)
|
||||
|
||||
private fun getTestDataContext(testServices: TestServices): TestDataContext {
|
||||
var psiMethod: PsiMethod? = null
|
||||
var useSitePosition: PsiElement? = null
|
||||
|
||||
testServices.moduleStructure.modules.forEach { module ->
|
||||
val psiFiles = testServices.ktModuleProvider.getModuleFiles(module)
|
||||
for (psiFile in psiFiles) {
|
||||
val targetOffset = testServices.expressionMarkerProvider.getCaretPositionOrNull(psiFile)
|
||||
if (targetOffset != null) {
|
||||
if (psiMethod != null) error("Only one target method is expected")
|
||||
psiMethod = psiFile.findElementAt(targetOffset)?.parentOfType<PsiMethod>(withSelf = true)
|
||||
}
|
||||
|
||||
val useSiteOffset = testServices.expressionMarkerProvider.getCaretPositionOrNull(psiFile, caretTag = "useSite")
|
||||
if (useSiteOffset != null) {
|
||||
if (useSitePosition != null) error("Only one target method is expected")
|
||||
useSitePosition = psiFile.findElementAt(useSiteOffset)?.parentOfType<PsiElement>(withSelf = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TestDataContext(psiMethod ?: error("Target method is not found"), useSitePosition)
|
||||
}
|
||||
|
||||
+30
@@ -57,6 +57,24 @@ public class FirStandaloneNormalAnalysisSourceModuleAnalysisApiKtTypeByPsiTypePr
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/extends.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameterWithKotlinUseSite.kt")
|
||||
public void testMethodTypeParameterWithKotlinUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/methodTypeParameterWithKotlinUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameterWithMethodUseSite.kt")
|
||||
public void testMethodTypeParameterWithMethodUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/methodTypeParameterWithMethodUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameterWithTypeParameterUseSite.kt")
|
||||
public void testMethodTypeParameterWithTypeParameterUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/methodTypeParameterWithTypeParameterUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("methodTypeParameters.kt")
|
||||
public void testMethodTypeParameters() {
|
||||
@@ -81,6 +99,18 @@ public class FirStandaloneNormalAnalysisSourceModuleAnalysisApiKtTypeByPsiTypePr
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/primitive.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameterWithKotlinUseSite.kt")
|
||||
public void testTypeParameterWithKotlinUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/typeParameterWithKotlinUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameterWithMethodUseSite.kt")
|
||||
public void testTypeParameterWithMethodUseSite() {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/asKtType/typeParameterWithMethodUseSite.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParameters.kt")
|
||||
public void testTypeParameters() {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// FILE: KotlinClass.kt
|
||||
class Kotlin<caret_useSite>Class
|
||||
|
||||
// FILE: A.java
|
||||
class JavaClass {
|
||||
<TYPE> TYPE ma<caret>terialize() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
PsiType: PsiType:TYPE
|
||||
KtType: TYPE
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// FILE: KotlinClass.kt
|
||||
class KotlinClass
|
||||
|
||||
// FILE: A.java
|
||||
class JavaClass {
|
||||
<TYPE> TYPE ma<caret>teria<caret_useSite>lize() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
PsiType: PsiType:TYPE
|
||||
KtType: TYPE?
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// FILE: KotlinClass.kt
|
||||
class KotlinClass
|
||||
|
||||
// FILE: A.java
|
||||
class JavaClass {
|
||||
<TY<caret_useSite>PE> TYPE ma<caret>terialize() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
PsiType: PsiType:TYPE
|
||||
KtType: TYPE
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// FILE: KotlinClass.kt
|
||||
class Kotlin<caret_useSite>Class
|
||||
|
||||
// FILE: A.java
|
||||
public interface A<T> {
|
||||
T f<caret>oo();
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
PsiType: PsiType:T
|
||||
KtType: T
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// FILE: KotlinClass.kt
|
||||
class KotlinClass
|
||||
|
||||
// FILE: A.java
|
||||
public interface A<T> {
|
||||
T f<caret>o<caret_useSite>o();
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
PsiType: PsiType:T
|
||||
KtType: T?
|
||||
Reference in New Issue
Block a user