[LL FIR, Java] fix resolve contract violation from java symbol provider

To create a smart psi type pointer, IJ Platform uses resolve.
We cannot use resolve from JavaSymbolProvider, as it may lead to resolve contract violation.

^KT-59133 fixed
This commit is contained in:
Ilya Kirillov
2023-06-07 14:56:56 +02:00
committed by Space Team
parent f590e88bdd
commit b8f15cbbb3
11 changed files with 114 additions and 1 deletions
@@ -47,3 +47,16 @@ internal class JavaElementDelegatingExpressionTypeSourceWithSmartPointer<TYPE :
return psi.type as TYPE
}
}
internal class JavaElementDelegatingTypeParameterBoundTypeSourceWithSmartPointer<TYPE : PsiType>(
override val psiPointer: SmartPsiElementPointer<out PsiTypeParameter>,
private val boundIndex: Int,
override val factory: JavaElementSourceFactory,
) : JavaElementDelegatingTypeSourceWithSmartPointer<PsiTypeParameter, TYPE>() {
override fun getType(psi: PsiTypeParameter): TYPE {
@Suppress("UNCHECKED_CAST")
return psi.bounds[boundIndex] as TYPE
}
}
@@ -33,6 +33,18 @@ class JavaElementSourceWithSmartPointerFactory(project: Project) : JavaElementSo
return JavaElementDelegatingMethodReturnTypeSourceWithSmartPointer(psiMethodSource.pointer, psiMethodSource.factory)
}
override fun <TYPE : PsiType> createTypeParameterUpperBoundTypeSource(
psiTypeParameterSource: JavaElementPsiSource<out PsiTypeParameter>,
boundIndex: Int
): JavaElementTypeSource<TYPE> {
require(psiTypeParameterSource is JavaElementPsiSourceWithSmartPointer)
return JavaElementDelegatingTypeParameterBoundTypeSourceWithSmartPointer(
psiTypeParameterSource.pointer,
boundIndex,
psiTypeParameterSource.factory
)
}
override fun <TYPE : PsiType> createExpressionTypeSource(psiExpressionSource: JavaElementPsiSource<out PsiExpression>): JavaElementTypeSource<TYPE> {
require(psiExpressionSource is JavaElementPsiSourceWithSmartPointer)
return JavaElementDelegatingExpressionTypeSourceWithSmartPointer(psiExpressionSource.pointer, psiExpressionSource.factory)