[LL FIR] FileStructure: support dangling modifier list in non-end position
The root cause of the exception is that we missed such an element, and it led to unresolved declaration during iteration over file declarations ^KT-65562 Fixed
This commit is contained in:
committed by
Space Team
parent
80240198d2
commit
31852c6c05
+12
@@ -52,6 +52,18 @@ public class Fe10IdeNormalAnalysisSourceModuleCollectDiagnosticsTestGenerated ex
|
|||||||
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddleWithComment.kt")
|
||||||
|
public void testDanglingAnnotationInMiddleWithComment() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddleWithComment.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("declarationErrors.kt")
|
@TestMetadata("declarationErrors.kt")
|
||||||
public void testDeclarationErrors() throws Exception {
|
public void testDeclarationErrors() throws Exception {
|
||||||
|
|||||||
+12
@@ -52,6 +52,18 @@ public class FirIdeNormalAnalysisSourceModuleCollectDiagnosticsTestGenerated ext
|
|||||||
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddleWithComment.kt")
|
||||||
|
public void testDanglingAnnotationInMiddleWithComment() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddleWithComment.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("declarationErrors.kt")
|
@TestMetadata("declarationErrors.kt")
|
||||||
public void testDeclarationErrors() throws Exception {
|
public void testDeclarationErrors() throws Exception {
|
||||||
|
|||||||
+12
@@ -52,6 +52,18 @@ public class FirIdeNormalAnalysisSourceModuleDanglingFileCollectDiagnosticsTestG
|
|||||||
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddleWithComment.kt")
|
||||||
|
public void testDanglingAnnotationInMiddleWithComment() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddleWithComment.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("declarationErrors.kt")
|
@TestMetadata("declarationErrors.kt")
|
||||||
public void testDeclarationErrors() throws Exception {
|
public void testDeclarationErrors() throws Exception {
|
||||||
|
|||||||
+12
@@ -52,6 +52,18 @@ public class FirStandaloneNormalAnalysisSourceModuleCollectDiagnosticsTestGenera
|
|||||||
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddleWithComment.kt")
|
||||||
|
public void testDanglingAnnotationInMiddleWithComment() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddleWithComment.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("declarationErrors.kt")
|
@TestMetadata("declarationErrors.kt")
|
||||||
public void testDeclarationErrors() throws Exception {
|
public void testDeclarationErrors() throws Exception {
|
||||||
|
|||||||
+12
@@ -52,6 +52,18 @@ public class FirStandaloneNormalAnalysisSourceModuleDanglingFileCollectDiagnosti
|
|||||||
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/annotationWithEnumFromDuplicatedLibrary.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddleWithComment.kt")
|
||||||
|
public void testDanglingAnnotationInMiddleWithComment() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/diagnosticsProvider/diagnostics/danglingAnnotationInMiddleWithComment.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("declarationErrors.kt")
|
@TestMetadata("declarationErrors.kt")
|
||||||
public void testDeclarationErrors() throws Exception {
|
public void testDeclarationErrors() throws Exception {
|
||||||
|
|||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
@MyAnn
|
||||||
|
fin class Foo
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
Diagnostics from elements:
|
||||||
|
for PSI element of type KtNameReferenceExpression at (1,2-7)
|
||||||
|
UNRESOLVED_REFERENCE text ranges: [(1,6)]
|
||||||
|
PSI: KtNameReferenceExpression at (1,2-7)
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
@MyAnn // comment
|
||||||
|
/*comment*/ope class Foo
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
Diagnostics from elements:
|
||||||
|
for PSI element of type KtNameReferenceExpression at (1,2-7)
|
||||||
|
UNRESOLVED_REFERENCE text ranges: [(1,6)]
|
||||||
|
PSI: KtNameReferenceExpression at (1,2-7)
|
||||||
+6
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor
|
|||||||
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
import org.jetbrains.kotlin.fir.resolve.providers.firProvider
|
||||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||||
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
|
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
|
||||||
@@ -73,7 +74,7 @@ internal class FileStructure private constructor(
|
|||||||
container = declaration
|
container = declaration
|
||||||
} else {
|
} else {
|
||||||
val modifierList = PsiTreeUtil.getParentOfType(element, KtModifierList::class.java, false)
|
val modifierList = PsiTreeUtil.getParentOfType(element, KtModifierList::class.java, false)
|
||||||
container = if (modifierList != null && modifierList.nextSibling is PsiErrorElement) {
|
container = if (modifierList != null && modifierList.getNextSiblingIgnoringWhitespaceAndComments() is PsiErrorElement) {
|
||||||
modifierList
|
modifierList
|
||||||
} else {
|
} else {
|
||||||
element.containingKtFile
|
element.containingKtFile
|
||||||
@@ -207,7 +208,9 @@ internal class FileStructure private constructor(
|
|||||||
RootStructureElement(firFile, moduleComponents)
|
RootStructureElement(firFile, moduleComponents)
|
||||||
}
|
}
|
||||||
container is KtDeclaration -> createDeclarationStructure(container)
|
container is KtDeclaration -> createDeclarationStructure(container)
|
||||||
container is KtModifierList && container.nextSibling is PsiErrorElement -> createDanglingModifierListStructure(container)
|
container is KtModifierList && container.getNextSiblingIgnoringWhitespaceAndComments() is PsiErrorElement -> {
|
||||||
|
createDanglingModifierListStructure(container)
|
||||||
|
}
|
||||||
else -> errorWithAttachment("Invalid container ${container::class}") {
|
else -> errorWithAttachment("Invalid container ${container::class}") {
|
||||||
withPsiEntry("container", container)
|
withPsiEntry("container", container)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
annotation class MyAnn/* ClassDeclarationStructureElement */
|
||||||
|
|
||||||
|
@MyAnn/* DeclarationStructureElement */
|
||||||
|
fin class Foo/* ClassDeclarationStructureElement */
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
FILE: [ResolvedTo(BODY_RESOLVE)] danglingAnnotationInMiddle.kt
|
||||||
|
public final [ResolvedTo(BODY_RESOLVE)] annotation class MyAnn : R|kotlin/Annotation| {
|
||||||
|
public [ResolvedTo(BODY_RESOLVE)] constructor(): R|MyAnn| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public final [ResolvedTo(BODY_RESOLVE)] class Foo : R|kotlin/Any| {
|
||||||
|
public [ResolvedTo(BODY_RESOLVE)] constructor(): R|Foo| {
|
||||||
|
super<R|kotlin/Any|>()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
[ResolvedTo(BODY_RESOLVE)] @R|MyAnn|[Types]() <DANGLING MODIFIER: Top level declaration expected>
|
||||||
+6
@@ -102,6 +102,12 @@ public class FirOutOfContentRootContextCollectionTestGenerated extends AbstractF
|
|||||||
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("danglingAnnotationTopLevel.kt")
|
@TestMetadata("danglingAnnotationTopLevel.kt")
|
||||||
public void testDanglingAnnotationTopLevel() throws Exception {
|
public void testDanglingAnnotationTopLevel() throws Exception {
|
||||||
|
|||||||
+6
@@ -102,6 +102,12 @@ public class FirSourceContextCollectionTestGenerated extends AbstractFirSourceCo
|
|||||||
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("danglingAnnotationTopLevel.kt")
|
@TestMetadata("danglingAnnotationTopLevel.kt")
|
||||||
public void testDanglingAnnotationTopLevel() throws Exception {
|
public void testDanglingAnnotationTopLevel() throws Exception {
|
||||||
|
|||||||
+6
@@ -102,6 +102,12 @@ public class SourceDiagnosticTraversalCounterTestGenerated extends AbstractSourc
|
|||||||
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("danglingAnnotationTopLevel.kt")
|
@TestMetadata("danglingAnnotationTopLevel.kt")
|
||||||
public void testDanglingAnnotationTopLevel() throws Exception {
|
public void testDanglingAnnotationTopLevel() throws Exception {
|
||||||
|
|||||||
+2
-1
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
|||||||
import org.jetbrains.kotlin.fir.psi
|
import org.jetbrains.kotlin.fir.psi
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.jetbrains.kotlin.test.model.TestModule
|
import org.jetbrains.kotlin.test.model.TestModule
|
||||||
import org.jetbrains.kotlin.test.services.TestServices
|
import org.jetbrains.kotlin.test.services.TestServices
|
||||||
@@ -76,7 +77,7 @@ abstract class AbstractFileStructureTest : AbstractAnalysisApiBasedTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PsiTreeUtil.getChildrenOfTypeAsList(mainFile, KtModifierList::class.java).forEach {
|
PsiTreeUtil.getChildrenOfTypeAsList(mainFile, KtModifierList::class.java).forEach {
|
||||||
if (it.nextSibling is PsiErrorElement) {
|
if (it.getNextSiblingIgnoringWhitespaceAndComments() is PsiErrorElement) {
|
||||||
val structureElement = declarationToStructureElement[it] ?: return@forEach
|
val structureElement = declarationToStructureElement[it] ?: return@forEach
|
||||||
val comment = structureElement.createComment()
|
val comment = structureElement.createComment()
|
||||||
elementToComment[it] = comment
|
elementToComment[it] = comment
|
||||||
|
|||||||
+6
@@ -102,6 +102,12 @@ public class OutOfContentRootFileStructureTestGenerated extends AbstractOutOfCon
|
|||||||
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("danglingAnnotationTopLevel.kt")
|
@TestMetadata("danglingAnnotationTopLevel.kt")
|
||||||
public void testDanglingAnnotationTopLevel() throws Exception {
|
public void testDanglingAnnotationTopLevel() throws Exception {
|
||||||
|
|||||||
+6
@@ -102,6 +102,12 @@ public class SourceFileStructureTestGenerated extends AbstractSourceFileStructur
|
|||||||
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("danglingAnnotationTopLevel.kt")
|
@TestMetadata("danglingAnnotationTopLevel.kt")
|
||||||
public void testDanglingAnnotationTopLevel() throws Exception {
|
public void testDanglingAnnotationTopLevel() throws Exception {
|
||||||
|
|||||||
+6
@@ -102,6 +102,12 @@ public class OutOfContentRootWholeFileResolvePhaseTestGenerated extends Abstract
|
|||||||
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("danglingAnnotationTopLevel.kt")
|
@TestMetadata("danglingAnnotationTopLevel.kt")
|
||||||
public void testDanglingAnnotationTopLevel() throws Exception {
|
public void testDanglingAnnotationTopLevel() throws Exception {
|
||||||
|
|||||||
+6
@@ -102,6 +102,12 @@ public class SourceWholeFileResolvePhaseTestGenerated extends AbstractSourceWhol
|
|||||||
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationClassLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("danglingAnnotationInMiddle.kt")
|
||||||
|
public void testDanglingAnnotationInMiddle() throws Exception {
|
||||||
|
runTest("analysis/low-level-api-fir/testData/fileStructure/danglingAnnotationInMiddle.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("danglingAnnotationTopLevel.kt")
|
@TestMetadata("danglingAnnotationTopLevel.kt")
|
||||||
public void testDanglingAnnotationTopLevel() throws Exception {
|
public void testDanglingAnnotationTopLevel() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user