[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
@@ -84,7 +84,9 @@ class JavaClassImpl(psiClassSource: JavaElementPsiSource<PsiClass>) : JavaClassi
get() = typeParameters(psi.typeParameters, sourceFactory)
override val supertypes: Collection<JavaClassifierType>
get() = classifierTypes(psi.superTypes, sourceFactory)
get() = psi.superTypes.convertIndexed { index, _ ->
JavaClassifierTypeImpl(sourceFactory.createSuperTypeSource(psiElementSource, index))
}
override val methods: Collection<JavaMethod>
get() {
@@ -32,6 +32,12 @@ inline fun <Psi, Java> Array<Psi>.convert(factory: (Psi) -> Java): List<Java> =
else -> map(factory)
}
inline fun <Psi, Java> Array<Psi>.convertIndexed(factory: (Int, Psi) -> Java): List<Java> = when (size) {
0 -> emptyList()
1 -> listOf(factory(0, first()))
else -> mapIndexed(factory)
}
fun <Psi, Java> Collection<Psi>.convert(factory: (Psi) -> Java): List<Java> =
when (size) {
0 -> emptyList()
@@ -19,6 +19,11 @@ abstract class JavaElementSourceFactory {
boundIndex: Int,
): JavaElementTypeSource<TYPE>
abstract fun createSuperTypeSource(
psiTypeParameterSource: JavaElementPsiSource<out PsiClass>,
superTypeIndex: Int,
): JavaElementTypeSource<PsiClassType>
abstract fun <TYPE : PsiType> createExpressionTypeSource(psiExpressionSource: JavaElementPsiSource<out PsiExpression>): JavaElementTypeSource<TYPE>
companion object {
@@ -51,6 +56,12 @@ class JavaFixedElementSourceFactory : JavaElementSourceFactory() {
return createTypeSource(psiTypeParameterSource.psi.bounds[boundIndex] as TYPE)
}
override fun createSuperTypeSource(
psiTypeParameterSource: JavaElementPsiSource<out PsiClass>,
superTypeIndex: Int,
): JavaElementTypeSource<PsiClassType> {
return createTypeSource(psiTypeParameterSource.psi.superTypes[superTypeIndex])
}
override fun <TYPE : PsiType> createExpressionTypeSource(psiExpressionSource: JavaElementPsiSource<out PsiExpression>): JavaElementTypeSource<TYPE> {
@Suppress("UNCHECKED_CAST")