From 4b666495ab9d76d87b1ada7a4b0fa1d53e67cb56 Mon Sep 17 00:00:00 2001 From: xterao Date: Fri, 16 May 2025 10:10:49 +0900 Subject: [PATCH] Refactor file type check logic and improve subproject path retrieval --- .../doma/intellij/common/FileTypeCheck.kt | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/org/domaframework/doma/intellij/common/FileTypeCheck.kt b/src/main/kotlin/org/domaframework/doma/intellij/common/FileTypeCheck.kt index aa8d7ce8..f8c15f56 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/common/FileTypeCheck.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/common/FileTypeCheck.kt @@ -46,14 +46,6 @@ fun isJavaOrKotlinFileType(daoFile: PsiFile): Boolean { } } -fun isJavaOrKotlinFileType(file: VirtualFile): Boolean { - val fileType = file.fileType - return when (fileType.name) { - "JAVA", "Kotlin", "CLASS" -> true - else -> false - } -} - /* * Determine whether the open file is an SQL template file extension */ @@ -92,9 +84,18 @@ fun searchDaoFile( return null } - val subProject = - originFilePath.substring(projectRootPath.length, originFilePath.indexOf(SRC_MAIN_PATH)) - return contentRoot - .findFileByRelativePath(subProject) - ?.findFileByRelativePath(relativeDaoFilePath) + // TODO Dynamically build the source directory path and retrieve subproject info + // by inspecting file metadata instead of using string manipulation. + val index = originFilePath.indexOf(SRC_MAIN_PATH) + val projectRootPathBefore = projectRootPath.substringBefore(SRC_MAIN_PATH) + if (index < 0 || projectRootPathBefore.length < index) return null + val subProjectName = + originFilePath.substring(projectRootPathBefore.length, index) + + val daoFile = + contentRoot + .findFileByRelativePath(subProjectName) + ?.findFileByRelativePath(relativeDaoFilePath) + + return daoFile }