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

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-59240 Fixed
This commit is contained in:
Dmitrii Gridin
2023-06-12 13:41:58 +02:00
committed by Space Team
parent 67d933185a
commit 6992a707dc
14 changed files with 172 additions and 1 deletions
@@ -60,3 +60,11 @@ internal class JavaElementDelegatingTypeParameterBoundTypeSourceWithSmartPointer
return psi.bounds[boundIndex] as TYPE
}
}
internal class JavaElementDelegatingSuperTypeSourceWithSmartPointer(
override val psiPointer: SmartPsiElementPointer<out PsiClass>,
private val superTypeIndex: Int,
override val factory: JavaElementSourceFactory,
) : JavaElementDelegatingTypeSourceWithSmartPointer<PsiClass, PsiClassType>() {
override fun getType(psi: PsiClass): PsiClassType = psi.superTypes[superTypeIndex]
}
@@ -45,6 +45,18 @@ class JavaElementSourceWithSmartPointerFactory(project: Project) : JavaElementSo
)
}
override fun createSuperTypeSource(
psiTypeParameterSource: JavaElementPsiSource<out PsiClass>,
superTypeIndex: Int
): JavaElementTypeSource<PsiClassType> {
require(psiTypeParameterSource is JavaElementPsiSourceWithSmartPointer)
return JavaElementDelegatingSuperTypeSourceWithSmartPointer(
psiTypeParameterSource.pointer,
superTypeIndex,
psiTypeParameterSource.factory,
)
}
override fun <TYPE : PsiType> createExpressionTypeSource(psiExpressionSource: JavaElementPsiSource<out PsiExpression>): JavaElementTypeSource<TYPE> {
require(psiExpressionSource is JavaElementPsiSourceWithSmartPointer)
return JavaElementDelegatingExpressionTypeSourceWithSmartPointer(psiExpressionSource.pointer, psiExpressionSource.factory)