File tree Expand file tree Collapse file tree 4 files changed +11
-4
lines changed
src/main/kotlin/org/domaframework/doma/intellij Expand file tree Collapse file tree 4 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import com.intellij.psi.PsiFile
2525import com.intellij.psi.PsiMethod
2626import com.intellij.psi.util.PsiTreeUtil
2727import org.domaframework.doma.intellij.bundle.MessageBundle
28+ import org.domaframework.doma.intellij.common.dao.getDaoClass
2829import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
2930import org.domaframework.doma.intellij.common.util.PluginLoggerUtil
3031
@@ -47,7 +48,9 @@ class ConvertSqlAnnotationToFileAction : ConvertSqlIntentionAction() {
4748 // Check if method has @Sql annotation
4849 // When a Sql annotation is present, a virtual SQL file is associated;
4950 // therefore, check the parent and exclude the injected (inline) SQL.
50- if (! psiDaoMethod.useSqlAnnotation() || psiDaoMethod.sqlFile != null && psiDaoMethod.sqlFile?.parent != null ) {
51+ if (getDaoClass(method.containingFile) == null || ! psiDaoMethod.useSqlAnnotation() ||
52+ psiDaoMethod.sqlFile != null && psiDaoMethod.sqlFile?.parent != null
53+ ) {
5154 return false
5255 }
5356
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import com.intellij.psi.PsiMethod
2424import com.intellij.psi.util.PsiTreeUtil
2525import org.domaframework.doma.intellij.bundle.MessageBundle
2626import org.domaframework.doma.intellij.common.dao.findDaoMethod
27+ import org.domaframework.doma.intellij.common.dao.getDaoClass
2728import org.domaframework.doma.intellij.common.isJavaOrKotlinFileType
2829import org.domaframework.doma.intellij.common.isSupportFileType
2930import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
@@ -42,8 +43,8 @@ class ConvertSqlFileToAnnotationAction : ConvertSqlIntentionAction() {
4243 editor : Editor ? ,
4344 element : PsiElement ,
4445 ): Boolean {
45- val file = element.containingFile
46- if (isJavaOrKotlinFileType(file)) {
46+ val file = element.containingFile ? : return false
47+ if (isJavaOrKotlinFileType(file) && getDaoClass(file) != null ) {
4748 return checkOnMethod(element, project)
4849 }
4950
Original file line number Diff line number Diff line change @@ -18,8 +18,9 @@ package org.domaframework.doma.intellij.common.dao
1818import com.intellij.psi.PsiClass
1919import com.intellij.psi.PsiFile
2020import com.intellij.psi.util.PsiTreeUtil
21+ import org.domaframework.doma.intellij.common.util.DomaClassName
2122
2223fun getDaoClass (file : PsiFile ): PsiClass ? =
2324 PsiTreeUtil
2425 .findChildrenOfType(file, PsiClass ::class .java)
25- .firstOrNull { it.hasAnnotation(" org.seasar.doma.Dao " ) }
26+ .firstOrNull { it.hasAnnotation(DomaClassName . DAO .className ) }
Original file line number Diff line number Diff line change @@ -18,6 +18,8 @@ package org.domaframework.doma.intellij.common.util
1818enum class DomaClassName (
1919 val className : String ,
2020) {
21+ DAO (" org.seasar.doma.Dao" ),
22+
2123 OPTIONAL (" java.util.Optional" ),
2224 OPTIONAL_INT (" java.util.OptionalInt" ),
2325 OPTIONAL_DOUBLE (" java.util.OptionalDouble" ),
You can’t perform that action at this time.
0 commit comments