Skip to content

Commit 8ec011c

Browse files
authored
Support Immutable inheritors vision
1 parent 4f1471e commit 8ec011c

File tree

7 files changed

+133
-4
lines changed

7 files changed

+133
-4
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2025 Enaium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package cn.enaium.jimmer.buddy.utitlity
18+
19+
import com.intellij.codeInsight.navigation.NavigationUtil.getPsiElementPopup
20+
import com.intellij.openapi.ui.popup.JBPopup
21+
import com.intellij.psi.PsiElement
22+
23+
/**
24+
* @author Enaium
25+
*/
26+
fun getPsiElementPopup(elements: List<PsiElement>, title: String): JBPopup {
27+
return getPsiElementPopup(elements.toTypedArray(), title)
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2025 Enaium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package cn.enaium.jimmer.buddy.utitlity
18+
19+
import com.intellij.codeInsight.navigation.getPsiElementPopup
20+
import com.intellij.openapi.ui.popup.JBPopup
21+
import com.intellij.psi.PsiElement
22+
23+
/**
24+
* @author Enaium
25+
*/
26+
fun getPsiElementPopup(elements: List<PsiElement>, title: String): JBPopup {
27+
return getPsiElementPopup(elements.toTypedArray(), title)
28+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ A plugin that adds first-class support for Project Jimmer
2020
- DTO class member go to DTO file.
2121
- Execute SQL to clipboard.
2222
- DTO type count and navigation.
23+
- Immutable inheritor count and navigation.
2324

2425
### First-class DTO development
2526

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.code.style=official
2-
version=1.6.0
2+
version=1.7.0
33
kotlin.daemon.jvmargs=-Xmx3G
44
org.gradle.jvmargs=-Xmx3G

shared/main/kotlin/cn/enaium/jimmer/buddy/extensions/insight/DtoTypeTargetCodeVisionProvider.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ package cn.enaium.jimmer.buddy.extensions.insight
1818

1919
import cn.enaium.jimmer.buddy.extensions.dto.psi.DtoPsiDtoType
2020
import cn.enaium.jimmer.buddy.extensions.dto.psi.DtoPsiRoot
21-
import com.intellij.codeInsight.navigation.NavigationUtil.getPsiElementPopup
21+
import cn.enaium.jimmer.buddy.utitlity.getPsiElementPopup
2222
import com.intellij.openapi.editor.Editor
2323
import com.intellij.openapi.project.Project
24-
import com.intellij.openapi.ui.popup.JBPopup
2524
import com.intellij.psi.PsiElement
2625
import com.intellij.psi.PsiFile
2726
import com.intellij.psi.search.FilenameIndex
@@ -60,7 +59,7 @@ class DtoTypeTargetCodeVisionProvider : ImmutableCodeVisionProvider() {
6059
val project = editor.project ?: return
6160
val qualifiedName = element.toUElementOfType<UClass>()?.qualifiedName ?: return
6261
getPsiElementPopup(
63-
findDtoTypes(project, qualifiedName).toTypedArray(),
62+
findDtoTypes(project, qualifiedName),
6463
"Choose DTO Type"
6564
).showInBestPositionFor(editor)
6665
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2025 Enaium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package cn.enaium.jimmer.buddy.extensions.insight
18+
19+
import cn.enaium.jimmer.buddy.utility.isImmutable
20+
import cn.enaium.jimmer.buddy.utitlity.getPsiElementPopup
21+
import com.intellij.openapi.editor.Editor
22+
import com.intellij.psi.PsiClass
23+
import com.intellij.psi.PsiElement
24+
import com.intellij.psi.PsiFile
25+
import com.intellij.psi.search.searches.ClassInheritorsSearch
26+
import org.babyfish.jimmer.sql.MappedSuperclass
27+
import org.jetbrains.kotlin.idea.base.util.allScope
28+
import org.jetbrains.uast.UClass
29+
import org.jetbrains.uast.toUElementOfType
30+
import java.awt.event.MouseEvent
31+
32+
/**
33+
* @author Enaium
34+
*/
35+
class ImmutableInheritorCodeVisionProvider : ImmutableCodeVisionProvider() {
36+
37+
override val id: String
38+
get() = "JimmerBuddy.immutable.inheritor"
39+
override val name: String
40+
get() = "Immutable Inheritor"
41+
42+
override fun getHint(element: PsiElement, file: PsiFile): String? {
43+
val uClass = element.toUElementOfType<UClass>() ?: return null
44+
uClass.uAnnotations.find { it.qualifiedName == MappedSuperclass::class.qualifiedName } ?: return null
45+
46+
val count = findInheritors(uClass.javaPsi).size
47+
48+
return if (count > 0) {
49+
"$count Inheritors"
50+
} else {
51+
null
52+
}
53+
}
54+
55+
override fun handleClick(
56+
editor: Editor,
57+
element: PsiElement,
58+
event: MouseEvent?
59+
) {
60+
val uClass = element.toUElementOfType<UClass>() ?: return
61+
getPsiElementPopup(
62+
findInheritors(uClass.javaPsi),
63+
"Choose Inheritors"
64+
).showInBestPositionFor(editor)
65+
}
66+
67+
private fun findInheritors(psiClass: PsiClass): List<PsiClass> {
68+
return ClassInheritorsSearch.search(psiClass, psiClass.project.allScope(), false)
69+
.filter { it.isImmutable() }
70+
}
71+
}

shared/main/resources/META-INF/plugin.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@
152152
order="first"/>
153153
<codeInsight.daemonBoundCodeVisionProvider
154154
implementation="cn.enaium.jimmer.buddy.extensions.insight.DtoTypeTargetCodeVisionProvider"/>
155+
<codeInsight.daemonBoundCodeVisionProvider
156+
implementation="cn.enaium.jimmer.buddy.extensions.insight.ImmutableInheritorCodeVisionProvider"/>
155157
</extensions>
156158
<extensions defaultExtensionNs="org.jetbrains.kotlin">
157159
<supportsKotlinPluginMode supportsK1="true" supportsK2="${supportsK2}"/>

0 commit comments

Comments
 (0)