Skip to content

Commit 0f9d791

Browse files
committed
Add check for generated directories in module path handling
1 parent 1a63822 commit 0f9d791

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package org.domaframework.doma.intellij.common
1717

18+
import com.intellij.compiler.CompilerConfiguration
1819
import com.intellij.openapi.module.Module
20+
import com.intellij.openapi.project.Project
1921
import com.intellij.openapi.roots.ModuleRootManager
2022
import com.intellij.openapi.vfs.VirtualFile
2123
import org.domaframework.doma.intellij.common.CommonPathParameterUtil.refreshModulePaths
@@ -59,6 +61,25 @@ object CommonPathParameterUtil {
5961
*/
6062
fun getModulePaths(module: Module): ModulePaths = modulePathCache[module.hashCode()] ?: refreshModulePaths(module)
6163

64+
/**
65+
* Checks if a given path is a generated directory based on annotation processor settings.
66+
*
67+
* @param module The module to check.
68+
* @param path The path to check.
69+
* @return True if the path is a generated directory, false otherwise.
70+
*/
71+
private fun isGeneratedDirectory(
72+
module: Module,
73+
path: String,
74+
): Boolean {
75+
val project: Project = module.project
76+
val compilerConfiguration = CompilerConfiguration.getInstance(project).getAnnotationProcessingConfiguration(module)
77+
val annotationProcessingConfiguration = compilerConfiguration.getGeneratedSourcesDirectoryName(false)
78+
79+
// Check if the path matches any of the generated source directories
80+
return path.contains("/build/$annotationProcessingConfiguration/")
81+
}
82+
6283
/**
6384
* Refreshes the directory information for the specified module and updates the cache.
6485
* Call this method when the module's directory structure changes.
@@ -75,38 +96,30 @@ object CommonPathParameterUtil {
7596

7697
val moduleManager = ModuleRootManager.getInstance(module)
7798
moduleManager.contentEntries.forEach { entry ->
78-
if (entry.file != null && entry.file?.path?.contains("/build/") != true) {
99+
val entryFile = entry.file
100+
if (entryFile != null && !isGeneratedDirectory(module, entryFile.path)) {
79101
entry.file?.let { basePath.add(it) }
80102
entry.sourceFolders.forEach { folder ->
81103
val file = folder.file
82104
if (file != null) {
83105
when (folder.rootType) {
84106
JavaSourceRootType.SOURCE ->
85107
if (!sourceDirs.contains(file)) {
86-
sourceDirs.add(
87-
file,
88-
)
108+
sourceDirs.add(file)
89109
}
90110

91111
JavaSourceRootType.TEST_SOURCE ->
92112
if (!testSourceDirs.contains(file)) {
93-
testSourceDirs.add(
94-
file,
95-
)
113+
testSourceDirs.add(file)
96114
}
97115

98116
JavaResourceRootType.RESOURCE ->
99117
if (!resourceDirs.contains(file)) {
100-
resourceDirs.add(
101-
file,
102-
)
118+
resourceDirs.add(file)
103119
}
104120

105121
JavaResourceRootType.TEST_RESOURCE ->
106-
if (!testResourceDirs.contains(
107-
file,
108-
)
109-
) {
122+
if (!testResourceDirs.contains(file)) {
110123
testResourceDirs.add(file)
111124
}
112125
}

0 commit comments

Comments
 (0)