[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:
committed by
Space Team
parent
67d933185a
commit
6992a707dc
+8
@@ -60,3 +60,11 @@ internal class JavaElementDelegatingTypeParameterBoundTypeSourceWithSmartPointer
|
|||||||
return psi.bounds[boundIndex] as TYPE
|
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]
|
||||||
|
}
|
||||||
|
|||||||
+12
@@ -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> {
|
override fun <TYPE : PsiType> createExpressionTypeSource(psiExpressionSource: JavaElementPsiSource<out PsiExpression>): JavaElementTypeSource<TYPE> {
|
||||||
require(psiExpressionSource is JavaElementPsiSourceWithSmartPointer)
|
require(psiExpressionSource is JavaElementPsiSourceWithSmartPointer)
|
||||||
return JavaElementDelegatingExpressionTypeSourceWithSmartPointer(psiExpressionSource.pointer, psiExpressionSource.factory)
|
return JavaElementDelegatingExpressionTypeSourceWithSmartPointer(psiExpressionSource.pointer, psiExpressionSource.factory)
|
||||||
|
|||||||
+12
@@ -27,6 +27,18 @@ public class DiagnosticCompilerTestFirTestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport2.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport2() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllFilesPresentInResolve() throws Exception {
|
public void testAllFilesPresentInResolve() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
|
|||||||
+12
@@ -27,6 +27,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport2.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport2() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllFilesPresentInResolve() throws Exception {
|
public void testAllFilesPresentInResolve() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
|
|||||||
+10
@@ -30,6 +30,16 @@ public class LazyBodyIsNotTouchedTestGenerated extends AbstractLazyBodyIsNotTouc
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport2.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport2() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
public void testAllFilesPresentInResolve() throws Exception {
|
public void testAllFilesPresentInResolve() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
FILE: useSite.kt
|
||||||
|
public final fun foo(): R|kotlin/Int| {
|
||||||
|
^foo Int(4)
|
||||||
|
}
|
||||||
|
FILE: KotlinInterface.kt
|
||||||
|
public abstract interface KotlinInterface : R|kotlin/Any| {
|
||||||
|
public abstract var selectedOptions: R|kotlin/Int|
|
||||||
|
public get(): R|kotlin/Int|
|
||||||
|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
// FILE: useSite.kt
|
||||||
|
|
||||||
|
import InspectionProfileImpl.INIT_INSPECTIONS
|
||||||
|
|
||||||
|
fun foo(): Int = 4
|
||||||
|
|
||||||
|
// FILE: InspectionProfileImpl.java
|
||||||
|
import static Configuration.StaticConfigurationClass
|
||||||
|
|
||||||
|
public class InspectionProfileImpl extends StaticConfigurationClass {
|
||||||
|
public static boolean INIT_INSPECTIONS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: Configuration.java
|
||||||
|
public class Configuration implements KotlinInterface {
|
||||||
|
public static class StaticConfigurationClass {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: KotlinInterface.kt
|
||||||
|
interface KotlinInterface {
|
||||||
|
var selectedOptions: Int
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
FILE: useSite.kt
|
||||||
|
public final fun foo(): R|kotlin/Int| {
|
||||||
|
^foo Int(4)
|
||||||
|
}
|
||||||
|
FILE: KotlinInterface.kt
|
||||||
|
public abstract interface KotlinInterface : R|kotlin/Any| {
|
||||||
|
public abstract var selectedOptions: R|kotlin/Int|
|
||||||
|
public get(): R|kotlin/Int|
|
||||||
|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
// FILE: useSite.kt
|
||||||
|
|
||||||
|
import InspectionProfileImpl.INIT_INSPECTIONS
|
||||||
|
|
||||||
|
fun foo(): Int = 4
|
||||||
|
|
||||||
|
// FILE: InspectionProfileImpl.java
|
||||||
|
import static Configuration.StaticConfigurationClass
|
||||||
|
|
||||||
|
public class InspectionProfileImpl extends InspectionProfile<StaticConfigurationClass> {
|
||||||
|
public static boolean INIT_INSPECTIONS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: InspectionProfile.java
|
||||||
|
public class InspectionProfile <T> {
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: Configuration.java
|
||||||
|
public class Configuration implements KotlinInterface {
|
||||||
|
public static class StaticConfigurationClass {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: KotlinInterface.kt
|
||||||
|
interface KotlinInterface {
|
||||||
|
var selectedOptions: Int
|
||||||
|
}
|
||||||
+12
@@ -27,6 +27,18 @@ public class FirLightTreeDiagnosticsTestGenerated extends AbstractFirLightTreeDi
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport2.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport2() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllFilesPresentInResolve() throws Exception {
|
public void testAllFilesPresentInResolve() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
|
|||||||
+12
@@ -27,6 +27,18 @@ public class FirPsiDiagnosticTestGenerated extends AbstractFirPsiDiagnosticTest
|
|||||||
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaImport.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("accessJavaFromKotlinViaStaticImport2.kt")
|
||||||
|
public void testAccessJavaFromKotlinViaStaticImport2() throws Exception {
|
||||||
|
runTest("compiler/fir/analysis-tests/testData/resolve/accessJavaFromKotlinViaStaticImport2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllFilesPresentInResolve() throws Exception {
|
public void testAllFilesPresentInResolve() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolve"), Pattern.compile("^([^.]+)\\.kt$"), null, true);
|
||||||
|
|||||||
+3
-1
@@ -84,7 +84,9 @@ class JavaClassImpl(psiClassSource: JavaElementPsiSource<PsiClass>) : JavaClassi
|
|||||||
get() = typeParameters(psi.typeParameters, sourceFactory)
|
get() = typeParameters(psi.typeParameters, sourceFactory)
|
||||||
|
|
||||||
override val supertypes: Collection<JavaClassifierType>
|
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>
|
override val methods: Collection<JavaMethod>
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
+6
@@ -32,6 +32,12 @@ inline fun <Psi, Java> Array<Psi>.convert(factory: (Psi) -> Java): List<Java> =
|
|||||||
else -> map(factory)
|
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> =
|
fun <Psi, Java> Collection<Psi>.convert(factory: (Psi) -> Java): List<Java> =
|
||||||
when (size) {
|
when (size) {
|
||||||
0 -> emptyList()
|
0 -> emptyList()
|
||||||
|
|||||||
+11
@@ -19,6 +19,11 @@ abstract class JavaElementSourceFactory {
|
|||||||
boundIndex: Int,
|
boundIndex: Int,
|
||||||
): JavaElementTypeSource<TYPE>
|
): JavaElementTypeSource<TYPE>
|
||||||
|
|
||||||
|
abstract fun createSuperTypeSource(
|
||||||
|
psiTypeParameterSource: JavaElementPsiSource<out PsiClass>,
|
||||||
|
superTypeIndex: Int,
|
||||||
|
): JavaElementTypeSource<PsiClassType>
|
||||||
|
|
||||||
abstract fun <TYPE : PsiType> createExpressionTypeSource(psiExpressionSource: JavaElementPsiSource<out PsiExpression>): JavaElementTypeSource<TYPE>
|
abstract fun <TYPE : PsiType> createExpressionTypeSource(psiExpressionSource: JavaElementPsiSource<out PsiExpression>): JavaElementTypeSource<TYPE>
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -51,6 +56,12 @@ class JavaFixedElementSourceFactory : JavaElementSourceFactory() {
|
|||||||
return createTypeSource(psiTypeParameterSource.psi.bounds[boundIndex] as TYPE)
|
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> {
|
override fun <TYPE : PsiType> createExpressionTypeSource(psiExpressionSource: JavaElementPsiSource<out PsiExpression>): JavaElementTypeSource<TYPE> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
|||||||
Reference in New Issue
Block a user