[LL FIR] Return class as structure element for super type reference

^KT-61755 Fixed
This commit is contained in:
aleksandrina-streltsova
2023-09-08 07:25:36 +00:00
committed by Space Team
parent 3aa635a766
commit f18d600dc8
10 changed files with 72 additions and 3 deletions
@@ -70,6 +70,12 @@ public class Fe10IdeNormalAnalysisSourceModuleCollectDiagnosticsTestGenerated ex
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unresolved.kt");
}
@Test
@TestMetadata("unresolvedSuperConstructorCall.kt")
public void testUnresolvedSuperConstructorCall() throws Exception {
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unresolvedSuperConstructorCall.kt");
}
@Test
@TestMetadata("unusedDestructuring.kt")
public void testUnusedDestructuring() throws Exception {
@@ -70,6 +70,12 @@ public class FirIdeNormalAnalysisSourceModuleCollectDiagnosticsTestGenerated ext
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unresolved.kt");
}
@Test
@TestMetadata("unresolvedSuperConstructorCall.kt")
public void testUnresolvedSuperConstructorCall() throws Exception {
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unresolvedSuperConstructorCall.kt");
}
@Test
@TestMetadata("unusedDestructuring.kt")
public void testUnusedDestructuring() throws Exception {
@@ -70,6 +70,12 @@ public class FirStandaloneNormalAnalysisSourceModuleCollectDiagnosticsTestGenera
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unresolved.kt");
}
@Test
@TestMetadata("unresolvedSuperConstructorCall.kt")
public void testUnresolvedSuperConstructorCall() throws Exception {
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/unresolvedSuperConstructorCall.kt");
}
@Test
@TestMetadata("unusedDestructuring.kt")
public void testUnusedDestructuring() throws Exception {
@@ -0,0 +1,3 @@
package test
class B(): A()
@@ -0,0 +1,4 @@
Diagnostics from elements:
for PSI element of type KtNameReferenceExpression at (3,12-13)
UNRESOLVED_REFERENCE text ranges: [(25,26)]
PSI: KtNameReferenceExpression at (3,12-13)
@@ -89,7 +89,7 @@ internal class FileStructure private constructor(
}
val resultedContainer = when {
container is KtClassOrObject && container.isInsideSuperClassCall(element) -> {
container is KtClassOrObject && container.isPartOfSuperClassCall(element) -> {
container.primaryConstructor
}
else -> null
@@ -98,9 +98,16 @@ internal class FileStructure private constructor(
return resultedContainer ?: container
}
private fun KtClassOrObject.isInsideSuperClassCall(element: KtElement): Boolean {
private fun KtClassOrObject.isPartOfSuperClassCall(element: KtElement): Boolean {
for (entry in superTypeListEntries) {
if (entry is KtSuperTypeCallEntry && entry.isAncestor(element, strict = false)) return true
if (entry !is KtSuperTypeCallEntry) continue
// the structure element for `KtTypeReference` inside super class call is class declaration and not primary constructor
val typeReferenceIsAncestor = entry.calleeExpression.typeReference?.isAncestor(element, strict = false) == true
if (typeReferenceIsAncestor) return false
// the structure element for `KtSuperTypeCallEntry` is primary constructor
if (entry.isAncestor(element, strict = false)) return true
}
return false
@@ -0,0 +1,4 @@
// LOOK_UP_FOR_ELEMENT_OF_TYPE: org.jetbrains.kotlin.psi.KtTypeReference
open class A
class B(): <expr>A</expr>()
@@ -0,0 +1,21 @@
KT element: KtTypeReference
FIR element: FirResolvedTypeRefImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
R|A|
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] superType.kt
public open [ResolvedTo(STATUS)] class A : R|kotlin/Any| {
public [ResolvedTo(STATUS)] [ContainingClassKey=A] constructor(): R|A| {
LAZY_super<R|kotlin/Any|>
}
}
public final [ResolvedTo(BODY_RESOLVE)] class B : R|A| {
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=B] constructor(): R|B| {
super<R|A|>()
}
}
@@ -1087,6 +1087,12 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/types/receiverType.kt");
}
@Test
@TestMetadata("superType.kt")
public void testSuperType() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/types/superType.kt");
}
@Test
@TestMetadata("typeArgument.kt")
public void testTypeArgument() throws Exception {
@@ -1087,6 +1087,12 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/types/receiverType.kt");
}
@Test
@TestMetadata("superType.kt")
public void testSuperType() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/types/superType.kt");
}
@Test
@TestMetadata("typeArgument.kt")
public void testTypeArgument() throws Exception {