Skip to content

Commit 776c2cf

Browse files
committed
Refactor file type check logic and improve subproject path retrieval
1 parent 6db946f commit 776c2cf

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/main/kotlin/org/domaframework/doma/intellij/common/FileTypeCheck.kt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ fun isJavaOrKotlinFileType(daoFile: PsiFile): Boolean {
4646
}
4747
}
4848

49-
fun isJavaOrKotlinFileType(file: VirtualFile): Boolean {
50-
val fileType = file.fileType
51-
return when (fileType.name) {
52-
"JAVA", "Kotlin", "CLASS" -> true
53-
else -> false
54-
}
55-
}
56-
5749
/*
5850
* Determine whether the open file is an SQL template file extension
5951
*/
@@ -85,16 +77,27 @@ fun searchDaoFile(
8577
): VirtualFile? {
8678
val projectRootPath = contentRoot?.path ?: return null
8779
if (projectRootPath.endsWith(SRC_MAIN_PATH)) {
80+
println("Find Dao file path in Project")
8881
return contentRoot.findFileByRelativePath(relativeDaoFilePath)
8982
}
9083

9184
if (projectRootPath.length > originFilePath.length) {
9285
return null
9386
}
9487

95-
val subProject =
96-
originFilePath.substring(projectRootPath.length, originFilePath.indexOf(SRC_MAIN_PATH))
97-
return contentRoot
98-
.findFileByRelativePath(subProject)
99-
?.findFileByRelativePath(relativeDaoFilePath)
88+
// TODO Dynamically build the source directory path and retrieve subproject info
89+
// by inspecting file metadata instead of using string manipulation.
90+
println("Find Dao file path in Sub Project")
91+
val index = originFilePath.indexOf(SRC_MAIN_PATH)
92+
val projectRootPathBefore = projectRootPath.substringBefore(SRC_MAIN_PATH)
93+
if (index < 0 || projectRootPath.length < index) return null
94+
val subProjectName =
95+
originFilePath.substring(projectRootPathBefore.length, index)
96+
97+
val daoFile =
98+
contentRoot
99+
.findFileByRelativePath(subProjectName)
100+
?.findFileByRelativePath(relativeDaoFilePath)
101+
102+
return daoFile
100103
}

0 commit comments

Comments
 (0)