Skip to content

Commit 1a63822

Browse files
committed
Refactor SQL file path handling to use Paths for module base name checks and improve null handling for SQL file paths
1 parent cedac12 commit 1a63822

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/main/kotlin/org/domaframework/doma/intellij/common/dao/DaoMethodUtil.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import org.domaframework.doma.intellij.extension.getContentRoot
4040
import org.domaframework.doma.intellij.extension.getJavaClazz
4141
import org.domaframework.doma.intellij.extension.getModule
4242
import org.jetbrains.kotlin.idea.base.util.module
43+
import java.nio.file.Paths
4344

4445
/**
4546
* Get DAO method corresponding to SQL file
@@ -147,7 +148,7 @@ private fun searchDaoFile(
147148
val pathParams = module?.let { CommonPathParameterUtil.getModulePaths(it) } ?: return null
148149
val moduleBaseName =
149150
pathParams.moduleBasePaths
150-
.find { baseName -> contentRootPath.contains(baseName.path) }
151+
.find { baseName -> Paths.get(contentRootPath).startsWith(Paths.get(baseName.path)) }
151152
?.nameWithoutExtension ?: ""
152153
// TODO: Add Support Kotlin
153154
val relativeDaoFilePaths =
@@ -218,19 +219,20 @@ fun getRelativeSqlFilePathFromDaoFilePath(
218219
): String {
219220
if (module == null) return ""
220221
val extension = daoFile.fileType.defaultExtension
222+
val daoFilePath = daoFile.path
221223
val pathParams = CommonPathParameterUtil.getModulePaths(module)
222224
val containsModuleBaseName =
223225
pathParams.moduleBasePaths
224-
.find { basePath -> daoFile.path.contains("${basePath.path}/") }
226+
.find { basePath -> daoFilePath.contains("${basePath.path}/") }
225227
?.path ?: return ""
226228
var relativeSqlFilePath =
227-
daoFile.path
229+
daoFilePath
228230
.replaceFirst(containsModuleBaseName, "")
229231
.replace(".$extension", "")
230232
val sources = CommonPathParameterUtil.getSources(module, daoFile)
231233
sources
232234
.find {
233-
daoFile.path
235+
daoFilePath
234236
.startsWith(containsModuleBaseName.plus("/${it.nameWithoutExtension}/"))
235237
}?.let { source ->
236238
val startSourceName = "/${source.nameWithoutExtension}"

src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiDaoMethod.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,15 @@ class PsiDaoMethod(
140140
sqlFile = jarRoot?.findFileByRelativePath(sqlFilePath)
141141
return
142142
} else {
143-
if (sqlFilePath.isNotEmpty()) {
144-
sqlFile =
143+
sqlFile =
144+
if (sqlFilePath.isNotEmpty()) {
145145
module.getResourcesSQLFile(
146146
sqlFilePath,
147147
isTest,
148148
)
149-
}
149+
} else {
150+
null
151+
}
150152
return
151153
}
152154
}

0 commit comments

Comments
 (0)