Implement "Show non-public" filter for Kotlin structure view
#KT-14217 Fixed
This commit is contained in:
+5
@@ -25,6 +25,8 @@ import com.intellij.psi.NavigatablePsiElement
|
|||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.annotations.TestOnly
|
import org.jetbrains.annotations.TestOnly
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
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.caches.resolve.resolveToDescriptor
|
||||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -109,6 +111,9 @@ class KotlinStructureViewElement(val element: NavigatablePsiElement,
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val isPublic: Boolean
|
||||||
|
get() = (descriptor as? DeclarationDescriptorWithVisibility)?.visibility == Visibilities.PUBLIC
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtClassOrObject.getStructureDeclarations() = getPrimaryConstructorParameters().filter { it.hasValOrVar() } + declarations
|
fun KtClassOrObject.getStructureDeclarations() = getPrimaryConstructorParameters().filter { it.hasValOrVar() } + declarations
|
||||||
|
|||||||
+21
-1
@@ -17,7 +17,8 @@
|
|||||||
package org.jetbrains.kotlin.idea.structureView
|
package org.jetbrains.kotlin.idea.structureView
|
||||||
|
|
||||||
import com.intellij.ide.structureView.StructureViewModelBase
|
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.KtDeclaration
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
|
||||||
@@ -30,7 +31,26 @@ class KotlinStructureViewModel(ktFile: KtFile) : StructureViewModelBase(ktFile,
|
|||||||
|
|
||||||
override fun getNodeProviders() = NODE_PROVIDERS
|
override fun getNodeProviders() = NODE_PROVIDERS
|
||||||
|
|
||||||
|
override fun getFilters() = FILTERS
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val NODE_PROVIDERS = listOf(KotlinInheritedMembersNodeProvider())
|
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