diff --git a/src/main/kotlin/org/domaframework/doma/intellij/action/dao/GenerateSqlAction.kt b/src/main/kotlin/org/domaframework/doma/intellij/action/dao/GenerateSqlAction.kt index 178adc54..058a5bef 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/action/dao/GenerateSqlAction.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/action/dao/GenerateSqlAction.kt @@ -19,7 +19,6 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.psi.PsiFile import com.intellij.psi.PsiMethod import com.intellij.psi.util.PsiTreeUtil import org.domaframework.doma.intellij.common.dao.getDaoClass @@ -31,22 +30,19 @@ import org.domaframework.doma.intellij.common.util.PluginLoggerUtil * Action class that generates SQL from DAO method */ class GenerateSqlAction : AnAction() { - private var currentFile: PsiFile? = null - override fun update(e: AnActionEvent) { e.presentation.isEnabledAndVisible = false - currentFile = e.getData(CommonDataKeys.PSI_FILE) ?: return + val currentFile = e.getData(CommonDataKeys.PSI_FILE) ?: return val editor = e.getData(CommonDataKeys.EDITOR) ?: return val project = e.project ?: return - val file: PsiFile = currentFile ?: return - if (getDaoClass(file) == null) return - val element = file.findElementAt(editor.caretModel.offset) ?: return + if (getDaoClass(currentFile) == null) return + val element = currentFile.findElementAt(editor.caretModel.offset) ?: return val method = PsiTreeUtil.getParentOfType(element, PsiMethod::class.java) ?: return val psiDaoMethod = PsiDaoMethod(project, method) e.presentation.isEnabledAndVisible = psiDaoMethod.isUseSqlFileMethod() && - isJavaOrKotlinFileType(file) && + isJavaOrKotlinFileType(currentFile) && psiDaoMethod.sqlFile == null } @@ -62,9 +58,9 @@ class GenerateSqlAction : AnAction() { startTime, ) val project = e.project ?: return + val currentFile = e.getData(CommonDataKeys.PSI_FILE) ?: return val editor = e.getData(CommonDataKeys.EDITOR) ?: return - val file: PsiFile = currentFile ?: return - val element = file.findElementAt(editor.caretModel.offset) ?: return + val element = currentFile.findElementAt(editor.caretModel.offset) ?: return val method = PsiTreeUtil.getParentOfType(element, PsiMethod::class.java) ?: return val psiDaoMethod = PsiDaoMethod(project, method) psiDaoMethod.generateSqlFile() diff --git a/src/main/kotlin/org/domaframework/doma/intellij/action/dao/JumpToSQLFromDaoAction.kt b/src/main/kotlin/org/domaframework/doma/intellij/action/dao/JumpToSQLFromDaoAction.kt index 7731b4b2..f84484f4 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/action/dao/JumpToSQLFromDaoAction.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/action/dao/JumpToSQLFromDaoAction.kt @@ -19,7 +19,6 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.psi.PsiFile import com.intellij.psi.PsiMethod import com.intellij.psi.util.PsiTreeUtil import org.domaframework.doma.intellij.common.dao.getDaoClass @@ -29,17 +28,14 @@ import org.domaframework.doma.intellij.common.psi.PsiDaoMethod import org.domaframework.doma.intellij.common.util.PluginLoggerUtil class JumpToSQLFromDaoAction : AnAction() { - private var currentFile: PsiFile? = null - override fun update(e: AnActionEvent) { e.presentation.isEnabledAndVisible = false - currentFile = e.getData(CommonDataKeys.PSI_FILE) ?: return - val file: PsiFile = currentFile ?: return + val currentFile = e.getData(CommonDataKeys.PSI_FILE) ?: return - if (!isJavaOrKotlinFileType(file) || getDaoClass(file) == null) return + if (!isJavaOrKotlinFileType(currentFile) || getDaoClass(currentFile) == null) return val editor = e.getData(CommonDataKeys.EDITOR) ?: return - val element = file.findElementAt(editor.caretModel.offset) ?: return + val element = currentFile.findElementAt(editor.caretModel.offset) ?: return val project = e.project ?: return val method = PsiTreeUtil.getParentOfType(element, PsiMethod::class.java) ?: return val psiDaoMethod = PsiDaoMethod(project, method) @@ -61,7 +57,8 @@ class JumpToSQLFromDaoAction : AnAction() { startTime, ) val editor = e.getData(CommonDataKeys.EDITOR) ?: return - val element = currentFile?.findElementAt(editor.caretModel.offset) ?: return + val currentFile = e.getData(CommonDataKeys.PSI_FILE) ?: return + val element = currentFile.findElementAt(editor.caretModel.offset) ?: return val method = PsiTreeUtil.getParentOfType(element, PsiMethod::class.java) ?: return val project = e.project ?: return val psiDaoMethod = PsiDaoMethod(project, method) diff --git a/src/main/kotlin/org/domaframework/doma/intellij/action/sql/JumpToDaoFromSQLAction.kt b/src/main/kotlin/org/domaframework/doma/intellij/action/sql/JumpToDaoFromSQLAction.kt index 9d1d2b37..3b18fac0 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/action/sql/JumpToDaoFromSQLAction.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/action/sql/JumpToDaoFromSQLAction.kt @@ -19,7 +19,6 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys -import com.intellij.psi.PsiFile import org.domaframework.doma.intellij.common.dao.findDaoFile import org.domaframework.doma.intellij.common.dao.findDaoMethod import org.domaframework.doma.intellij.common.dao.jumpToDaoMethod @@ -30,15 +29,12 @@ import org.domaframework.doma.intellij.common.util.PluginLoggerUtil * Action to jump from SQL file to corresponding DAO function */ class JumpToDaoFromSQLAction : AnAction() { - private var currentFile: PsiFile? = null - override fun update(e: AnActionEvent) { e.presentation.isEnabledAndVisible = false - currentFile = e.getData(CommonDataKeys.PSI_FILE) ?: return - val file = currentFile ?: return - if (findDaoMethod(file) == null) return + val currentFile = e.getData(CommonDataKeys.PSI_FILE) ?: return + if (findDaoMethod(currentFile) == null) return e.presentation.isEnabledAndVisible = - isSupportFileType(file) + isSupportFileType(currentFile) } override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT @@ -52,11 +48,11 @@ class JumpToDaoFromSQLAction : AnAction() { inputEvent, startTime, ) - val file = currentFile ?: return + val currentFile = e.getData(CommonDataKeys.PSI_FILE) ?: return val project = e.project ?: return - val daoFile = findDaoFile(project, file) ?: return + val daoFile = findDaoFile(project, currentFile) ?: return - val sqlFileName = file.virtualFile?.nameWithoutExtension ?: return + val sqlFileName = currentFile.virtualFile?.nameWithoutExtension ?: return jumpToDaoMethod(project, sqlFileName, daoFile) PluginLoggerUtil.countLoggingByAction( this::class.java.simpleName,