Use anchor for element to avoid working with invalid element (KT-22631)
Element in constructor can be invalidated when dumb mode begins/ends. Working with invalid elements can produce nodes without icons and bad presentation. #KT-22631 Fixed
This commit is contained in:
+15
-9
@@ -35,7 +35,7 @@ import kotlin.properties.ReadWriteProperty
|
|||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class KotlinStructureViewElement(
|
class KotlinStructureViewElement(
|
||||||
val element: NavigatablePsiElement,
|
element: NavigatablePsiElement,
|
||||||
private val isInherited: Boolean = false
|
private val isInherited: Boolean = false
|
||||||
) : PsiTreeElementBase<NavigatablePsiElement>(element), Queryable {
|
) : PsiTreeElementBase<NavigatablePsiElement>(element), Queryable {
|
||||||
|
|
||||||
@@ -74,6 +74,8 @@ class KotlinStructureViewElement(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getChildrenBase(): Collection<StructureViewTreeElement> {
|
override fun getChildrenBase(): Collection<StructureViewTreeElement> {
|
||||||
|
val element = element
|
||||||
|
|
||||||
val children = when (element) {
|
val children = when (element) {
|
||||||
is KtFile -> element.declarations
|
is KtFile -> element.declarations
|
||||||
is KtClass -> element.getStructureDeclarations()
|
is KtClass -> element.getStructureDeclarations()
|
||||||
@@ -104,14 +106,18 @@ class KotlinStructureViewElement(
|
|||||||
private fun isPublic(descriptor: DeclarationDescriptor?) =
|
private fun isPublic(descriptor: DeclarationDescriptor?) =
|
||||||
(descriptor as? DeclarationDescriptorWithVisibility)?.visibility == Visibilities.PUBLIC
|
(descriptor as? DeclarationDescriptorWithVisibility)?.visibility == Visibilities.PUBLIC
|
||||||
|
|
||||||
private fun countDescriptor(): DeclarationDescriptor? = when {
|
private fun countDescriptor(): DeclarationDescriptor? {
|
||||||
!element.isValid -> null
|
val element = element
|
||||||
element !is KtDeclaration -> null
|
return when {
|
||||||
element is KtAnonymousInitializer -> null
|
element == null -> null
|
||||||
else -> runReadAction {
|
!element.isValid -> null
|
||||||
if (!DumbService.isDumb(element.getProject())) {
|
element !is KtDeclaration -> null
|
||||||
element.resolveToDescriptorIfAny()
|
element is KtAnonymousInitializer -> null
|
||||||
} else null
|
else -> runReadAction {
|
||||||
|
if (!DumbService.isDumb(element.getProject())) {
|
||||||
|
element.resolveToDescriptorIfAny()
|
||||||
|
} else null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user