Skip to content

Commit f4eb99f

Browse files
committed
Refactor SQL annotation conversion actions to use a common supported types definition
1 parent 9c23aa8 commit f4eb99f

File tree

4 files changed

+21
-51
lines changed

4 files changed

+21
-51
lines changed

src/main/kotlin/org/domaframework/doma/intellij/action/dao/ConvertSqlAnnotationToFileAction.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.domaframework.doma.intellij.action.dao
1717

18+
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
1819
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo
1920
import com.intellij.codeInsight.intention.preview.IntentionPreviewUtils
2021
import com.intellij.openapi.command.WriteCommandAction
@@ -32,7 +33,7 @@ import org.domaframework.doma.intellij.common.util.PluginLoggerUtil
3233
/**
3334
* Intention action to convert @Sql annotation to SQL file
3435
*/
35-
class ConvertSqlAnnotationToFileAction : ConvertSqlIntentionAction() {
36+
class ConvertSqlAnnotationToFileAction : PsiElementBaseIntentionAction() {
3637
override fun getFamilyName(): String = MessageBundle.message("convert.sql.annotation.to.file.family")
3738

3839
override fun getText(): String = MessageBundle.message("convert.sql.annotation.to.file.text")
@@ -54,7 +55,7 @@ class ConvertSqlAnnotationToFileAction : ConvertSqlIntentionAction() {
5455
return false
5556
}
5657

57-
return supportedTypes.any { it.getPsiAnnotation(method) != null }
58+
return SqlAnnotationConverter.supportedTypes.any { it.getPsiAnnotation(method) != null }
5859
}
5960

6061
override fun generatePreview(

src/main/kotlin/org/domaframework/doma/intellij/action/dao/ConvertSqlFileToAnnotationAction.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.domaframework.doma.intellij.action.dao
1717

18+
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
1819
import com.intellij.codeInsight.intention.preview.IntentionPreviewUtils
1920
import com.intellij.openapi.command.WriteCommandAction
2021
import com.intellij.openapi.editor.Editor
@@ -33,7 +34,7 @@ import org.domaframework.doma.intellij.common.util.PluginLoggerUtil
3334
/**
3435
* Intention action to convert SQL file to @Sql annotation
3536
*/
36-
class ConvertSqlFileToAnnotationAction : ConvertSqlIntentionAction() {
37+
class ConvertSqlFileToAnnotationAction : PsiElementBaseIntentionAction() {
3738
override fun getFamilyName(): String = MessageBundle.message("convert.sql.file.to.annotation.family")
3839

3940
override fun getText(): String = MessageBundle.message("convert.sql.file.to.annotation.text")
@@ -83,7 +84,7 @@ class ConvertSqlFileToAnnotationAction : ConvertSqlIntentionAction() {
8384
}
8485

8586
val hasAnnotation =
86-
supportedTypes.any { type ->
87+
SqlAnnotationConverter.supportedTypes.any { type ->
8788
val annotation = type.getPsiAnnotation(daoMethod)
8889
annotation != null
8990
}

src/main/kotlin/org/domaframework/doma/intellij/action/dao/ConvertSqlIntentionAction.kt

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/main/kotlin/org/domaframework/doma/intellij/action/dao/SqlAnnotationConverter.kt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ class SqlAnnotationConverter(
4848
private val psiDaoMethod = PsiDaoMethod(project, method)
4949
private val elementFactory = JavaPsiFacade.getElementFactory(project)
5050

51+
companion object {
52+
val supportedTypes =
53+
setOf(
54+
DomaAnnotationType.Select,
55+
DomaAnnotationType.Script,
56+
DomaAnnotationType.SqlProcessor,
57+
DomaAnnotationType.Insert,
58+
DomaAnnotationType.Update,
59+
DomaAnnotationType.Delete,
60+
DomaAnnotationType.BatchInsert,
61+
DomaAnnotationType.BatchUpdate,
62+
DomaAnnotationType.BatchDelete,
63+
)
64+
}
65+
5166
/**
5267
* Convert @Sql annotation to SQL file
5368
*/
@@ -95,19 +110,6 @@ class SqlAnnotationConverter(
95110
}
96111

97112
private fun findTargetAnnotation(): PsiAnnotation? {
98-
val supportedTypes =
99-
listOf(
100-
DomaAnnotationType.Select,
101-
DomaAnnotationType.Script,
102-
DomaAnnotationType.SqlProcessor,
103-
DomaAnnotationType.Insert,
104-
DomaAnnotationType.Update,
105-
DomaAnnotationType.Delete,
106-
DomaAnnotationType.BatchInsert,
107-
DomaAnnotationType.BatchUpdate,
108-
DomaAnnotationType.BatchDelete,
109-
)
110-
111113
for (type in supportedTypes) {
112114
val annotation = type.getPsiAnnotation(method)
113115
if (annotation != null) {

0 commit comments

Comments
 (0)