Skip to content

Commit 3441cd2

Browse files
committed
Supporting subscribe for Enum when statically imported #10
1 parent b7ff2e4 commit 3441cd2

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ compileTestKotlin {
3434

3535
patchPluginXml {
3636
changeNotes """
37-
- Support for `@file:JvmName()` <br>
38-
- Performance improvement <br>
3937
- Option to view usages in "Find" tool window <br>
4038
- Improved the UI of the usages popup <br>
39+
- Support for Enums <br>
40+
- Support for `@file:JvmName()` <br>
41+
- Performance improvement <br>
4142
"""
4243
}

src/main/kotlin/com/madrapps/eventbus/subscribe/SubscribeLineMarkerProvider.kt

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import com.intellij.openapi.application.ApplicationManager
66
import com.intellij.openapi.application.ReadAction
77
import com.intellij.openapi.editor.markup.GutterIconRenderer.Alignment.RIGHT
88
import com.intellij.openapi.util.IconLoader
9+
import com.intellij.psi.PsiClass
910
import com.intellij.psi.PsiElement
11+
import com.intellij.psi.PsiEnumConstant
1012
import com.intellij.psi.impl.source.PsiClassReferenceType
1113
import com.intellij.ui.awt.RelativePoint
1214
import com.intellij.usageView.UsageInfo
@@ -75,9 +77,17 @@ private class SubscribeLineMarkerInfo(
7577
val elementToSearch =
7678
(uElement.uastParameters[0].type as PsiClassReferenceType).reference.resolve()
7779
if (elementToSearch != null) {
78-
usages = search(elementToSearch)
79-
.filter(UsageInfo::isPost)
80-
.map(::UsageInfo2UsageAdapter)
80+
val psiClassElement = elementToSearch.toUElement()
81+
usages = if((psiClassElement as? PsiClass)?.isEnum == true) {
82+
val elementsToSearch = psiClassElement.allFields.filterIsInstance<PsiEnumConstant>()
83+
search(elementsToSearch)
84+
.filter(UsageInfo::isPost)
85+
.map(::UsageInfo2UsageAdapter)
86+
} else {
87+
search(elementToSearch)
88+
.filter(UsageInfo::isPost)
89+
.map(::UsageInfo2UsageAdapter)
90+
}
8191
}
8292
}
8393
ApplicationManager.getApplication().invokeLater {

0 commit comments

Comments
 (0)