Spring-Kotlin: Gutter repaired (KT-20550, KT-20566)
Platform now allows Gutter to be placed only on leafs elements, this patch fixes it for `KotlinSpringClassAnnotator`.
This commit is contained in:
committed by
Nikolay Krasko
parent
9e21744bf5
commit
f5e3a5faa4
+17
-1
@@ -22,8 +22,10 @@ import com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo
|
|||||||
import com.intellij.navigation.GotoRelatedItem
|
import com.intellij.navigation.GotoRelatedItem
|
||||||
import com.intellij.openapi.editor.markup.GutterIconRenderer
|
import com.intellij.openapi.editor.markup.GutterIconRenderer
|
||||||
import com.intellij.openapi.util.NotNullLazyValue
|
import com.intellij.openapi.util.NotNullLazyValue
|
||||||
|
import com.intellij.psi.PsiAnnotation
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiNameIdentifierOwner
|
import com.intellij.psi.PsiNameIdentifierOwner
|
||||||
|
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||||
import com.intellij.spring.gutter.SpringClassAnnotator
|
import com.intellij.spring.gutter.SpringClassAnnotator
|
||||||
import com.intellij.util.Function
|
import com.intellij.util.Function
|
||||||
import com.intellij.util.SmartList
|
import com.intellij.util.SmartList
|
||||||
@@ -38,6 +40,7 @@ import org.jetbrains.kotlin.asJava.toLightMethods
|
|||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getCallNameExpression
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||||
import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation
|
import org.jetbrains.kotlin.resolve.annotations.hasJvmStaticAnnotation
|
||||||
import javax.swing.Icon
|
import javax.swing.Icon
|
||||||
@@ -93,6 +96,13 @@ class KotlinSpringClassAnnotator : SpringClassAnnotator() {
|
|||||||
private val iconAlignmentField by lazy { LineMarkerInfo::class.java.getDeclaredField("myIconAlignment").apply { isAccessible = true } }
|
private val iconAlignmentField by lazy { LineMarkerInfo::class.java.getDeclaredField("myIconAlignment").apply { isAccessible = true } }
|
||||||
private val targetsField by lazy { RelatedItemLineMarkerInfo::class.java.getDeclaredField("myTargets").apply { isAccessible = true } }
|
private val targetsField by lazy { RelatedItemLineMarkerInfo::class.java.getDeclaredField("myTargets").apply { isAccessible = true } }
|
||||||
|
|
||||||
|
override fun getIdentifierLocal(annotation: PsiAnnotation): PsiElement? {
|
||||||
|
return when (annotation) {
|
||||||
|
is KtLightAnnotationForSourceEntry -> annotation.kotlinOrigin.getCallNameExpression()?.getIdentifier()
|
||||||
|
else -> super.getIdentifierLocal(annotation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun collectNavigationMarkers(psiElement: PsiElement, result: MutableCollection<in RelatedItemLineMarkerInfo<PsiElement>>) {
|
override fun collectNavigationMarkers(psiElement: PsiElement, result: MutableCollection<in RelatedItemLineMarkerInfo<PsiElement>>) {
|
||||||
val newItems = SmartList<RelatedItemLineMarkerInfo<PsiElement>>()
|
val newItems = SmartList<RelatedItemLineMarkerInfo<PsiElement>>()
|
||||||
|
|
||||||
@@ -101,8 +111,14 @@ class KotlinSpringClassAnnotator : SpringClassAnnotator() {
|
|||||||
newItems.mapNotNullTo(result) { item ->
|
newItems.mapNotNullTo(result) { item ->
|
||||||
val itemElement = item.element
|
val itemElement = item.element
|
||||||
val elementToAnnotate = when (itemElement) {
|
val elementToAnnotate = when (itemElement) {
|
||||||
is KtLightIdentifier -> itemElement.origin
|
is KtLightIdentifier -> itemElement.origin.let { ktElement ->
|
||||||
|
when (ktElement) {
|
||||||
|
is KtParameterList -> ktElement.leftParenthesis
|
||||||
|
else -> ktElement
|
||||||
|
}
|
||||||
|
}
|
||||||
is KtLightElement<*, *> -> itemElement.kotlinOrigin
|
is KtLightElement<*, *> -> itemElement.kotlinOrigin
|
||||||
|
is LeafPsiElement -> itemElement
|
||||||
else -> return@mapNotNullTo item
|
else -> return@mapNotNullTo item
|
||||||
}
|
}
|
||||||
if (elementToAnnotate == null) return@mapNotNullTo null
|
if (elementToAnnotate == null) return@mapNotNullTo null
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
springConfig: ["config.xml"],
|
springConfig: ["config.xml"],
|
||||||
file: "Bean.kt",
|
file: "Bean.kt",
|
||||||
icon: "SpringBeanMethod",
|
icon: "SpringBeanMethod",
|
||||||
tooltip: "Navigate to the spring bean ",
|
tooltip: "Navigate to the spring bean",
|
||||||
naming: "bean",
|
naming: "bean",
|
||||||
targets: ["bean"]
|
targets: ["bean"]
|
||||||
}
|
}
|
||||||
+2
-1
@@ -73,7 +73,8 @@ abstract class AbstractSpringClassAnnotatorTest : KotlinLightCodeInsightFixtureT
|
|||||||
val iconName = config.getString("icon")
|
val iconName = config.getString("icon")
|
||||||
val icon = SpringApiIcons::class.java.getField(iconName)[null]
|
val icon = SpringApiIcons::class.java.getField(iconName)[null]
|
||||||
|
|
||||||
val gutterMark = myFixture.findGutter(fileName)!!.let {
|
val gutter = myFixture.findGutter(fileName) ?: throw AssertionError("no gutter for '$fileName'")
|
||||||
|
val gutterMark = gutter.let {
|
||||||
if (it.icon == icon) it
|
if (it.icon == icon) it
|
||||||
else myFixture.findGuttersAtCaret().let { gutters ->
|
else myFixture.findGuttersAtCaret().let { gutters ->
|
||||||
gutters.firstOrNull() { it.icon == icon }
|
gutters.firstOrNull() { it.icon == icon }
|
||||||
|
|||||||
Reference in New Issue
Block a user