mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-23 15:51:59 +00:00
Implement "Show non-public" filter for Kotlin structure view
#KT-14217 Fixed
This commit is contained in:
@@ -25,6 +25,8 @@ import com.intellij.psi.NavigatablePsiElement
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -109,6 +111,9 @@ class KotlinStructureViewElement(val element: NavigatablePsiElement,
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
val isPublic: Boolean
|
||||
get() = (descriptor as? DeclarationDescriptorWithVisibility)?.visibility == Visibilities.PUBLIC
|
||||
}
|
||||
|
||||
fun KtClassOrObject.getStructureDeclarations() = getPrimaryConstructorParameters().filter { it.hasValOrVar() } + declarations
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
package org.jetbrains.kotlin.idea.structureView
|
||||
|
||||
import com.intellij.ide.structureView.StructureViewModelBase
|
||||
import com.intellij.ide.util.treeView.smartTree.Sorter
|
||||
import com.intellij.ide.util.treeView.smartTree.*
|
||||
import com.intellij.util.PlatformIcons
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
@@ -30,7 +31,26 @@ class KotlinStructureViewModel(ktFile: KtFile) : StructureViewModelBase(ktFile,
|
||||
|
||||
override fun getNodeProviders() = NODE_PROVIDERS
|
||||
|
||||
override fun getFilters() = FILTERS
|
||||
|
||||
companion object {
|
||||
private val NODE_PROVIDERS = listOf(KotlinInheritedMembersNodeProvider())
|
||||
private val FILTERS = arrayOf<Filter>(PublicElementsFilter)
|
||||
}
|
||||
}
|
||||
|
||||
object PublicElementsFilter : Filter {
|
||||
override fun isVisible(treeNode: TreeElement): Boolean {
|
||||
return (treeNode as? KotlinStructureViewElement)?.isPublic ?: true
|
||||
}
|
||||
|
||||
override fun getPresentation(): ActionPresentation {
|
||||
return ActionPresentationData("Show non-public", null, PlatformIcons.PRIVATE_ICON)
|
||||
}
|
||||
|
||||
override fun getName() = ID
|
||||
|
||||
override fun isReverted() = true
|
||||
|
||||
const val ID = "KOTLIN_SHOW_NON_PUBLIC"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user