Attach super line marker to name identifier

#KT-19843 Fixed
This commit is contained in:
Dmitry Jemerov
2017-08-31 19:23:54 +02:00
parent f008736ef7
commit cc6bfcfc7c
2 changed files with 10 additions and 12 deletions
@@ -220,7 +220,7 @@ private fun collectSuperDeclarationMarkers(declaration: KtDeclaration, result: M
// clearing the whole BindingTrace. // clearing the whole BindingTrace.
result.add(LineMarkerInfo( result.add(LineMarkerInfo(
declaration, anchor,
anchor.textRange, anchor.textRange,
if (implements) IMPLEMENTING_MARK else OVERRIDING_MARK, if (implements) IMPLEMENTING_MARK else OVERRIDING_MARK,
Pass.LINE_MARKERS, Pass.LINE_MARKERS,
@@ -32,13 +32,15 @@ import org.jetbrains.kotlin.idea.core.getDirectlyOverriddenDeclarations
import org.jetbrains.kotlin.idea.search.usagesSearch.propertyDescriptor import org.jetbrains.kotlin.idea.search.usagesSearch.propertyDescriptor
import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.psi.KtParameter
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.RenderingFormat import org.jetbrains.kotlin.renderer.RenderingFormat
import java.awt.event.MouseEvent import java.awt.event.MouseEvent
import java.util.* import java.util.*
object SuperDeclarationMarkerTooltip: Function<KtDeclaration, String> { object SuperDeclarationMarkerTooltip: Function<PsiElement, String> {
override fun `fun`(ktDeclaration: KtDeclaration?): String? { override fun `fun`(element: PsiElement): String? {
val ktDeclaration = element.getParentOfType<KtDeclaration>(false) ?: return null
val (elementDescriptor, overriddenDescriptors) = resolveDeclarationWithParents(ktDeclaration!!) val (elementDescriptor, overriddenDescriptors) = resolveDeclarationWithParents(ktDeclaration!!)
if (overriddenDescriptors.isEmpty()) return "" if (overriddenDescriptors.isEmpty()) return ""
@@ -63,25 +65,21 @@ object SuperDeclarationMarkerTooltip: Function<KtDeclaration, String> {
} }
} }
class SuperDeclarationMarkerNavigationHandler : GutterIconNavigationHandler<KtDeclaration>, TestableLineMarkerNavigator { class SuperDeclarationMarkerNavigationHandler : GutterIconNavigationHandler<PsiElement>, TestableLineMarkerNavigator {
override fun navigate(e: MouseEvent?, element: KtDeclaration?) { override fun navigate(e: MouseEvent?, element: PsiElement?) {
getTargetsPopupDescriptor(element)?.showPopup(e) getTargetsPopupDescriptor(element)?.showPopup(e)
} }
override fun getTargetsPopupDescriptor(element: PsiElement?): NavigationPopupDescriptor? { override fun getTargetsPopupDescriptor(element: PsiElement?): NavigationPopupDescriptor? {
if (element !is KtDeclaration) return null val declaration = element?.getParentOfType<KtDeclaration>(false) ?: return null
val (elementDescriptor, overriddenDescriptors) = resolveDeclarationWithParents(element) val (elementDescriptor, overriddenDescriptors) = resolveDeclarationWithParents(declaration)
if (overriddenDescriptors.isEmpty()) return null if (overriddenDescriptors.isEmpty()) return null
val superDeclarations = ArrayList<NavigatablePsiElement>() val superDeclarations = ArrayList<NavigatablePsiElement>()
for (overriddenMember in overriddenDescriptors) { for (overriddenMember in overriddenDescriptors) {
val declarations = DescriptorToSourceUtilsIde.getAllDeclarations(element.project, overriddenMember) val declarations = DescriptorToSourceUtilsIde.getAllDeclarations(element.project, overriddenMember)
for (declaration in declarations) { superDeclarations += declarations.filterIsInstance<NavigatablePsiElement>()
if (declaration is NavigatablePsiElement) {
superDeclarations.add(declaration)
}
}
} }
val elementName = elementDescriptor!!.name val elementName = elementDescriptor!!.name