diff --git a/src/main/kotlin/org/domaframework/doma/intellij/common/CommonPathParameter.kt b/src/main/kotlin/org/domaframework/doma/intellij/common/CommonPathParameter.kt index 6af8e78c..6b953c2d 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/common/CommonPathParameter.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/common/CommonPathParameter.kt @@ -15,7 +15,9 @@ */ package org.domaframework.doma.intellij.common +import com.intellij.compiler.CompilerConfiguration import com.intellij.openapi.module.Module +import com.intellij.openapi.project.Project import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.vfs.VirtualFile import org.jetbrains.jps.model.java.JavaResourceRootType @@ -32,14 +34,12 @@ object CommonPathParameterUtil { /** * Holds directory information for a module. * - * @property moduleBasePath The base path of the module. * @property moduleSourceDirectories List of source directories. * @property moduleResourceDirectories List of resource directories. * @property moduleTestSourceDirectories List of test source directories. * @property moduleTestResourceDirectories List of test resource directories. */ data class ModulePaths( - val moduleBasePath: VirtualFile?, val moduleSourceDirectories: List, val moduleResourceDirectories: List, val moduleTestSourceDirectories: List, @@ -51,12 +51,30 @@ object CommonPathParameterUtil { /** * Returns the directory information for the specified module (uses cache if available). - * If the module's directory structure has changed, call [refreshModulePaths] to update the cache. * * @param module The module to retrieve directory information for. * @return The cached or newly computed ModulePaths. */ - fun getModulePaths(module: Module): ModulePaths = modulePathCache[module] ?: refreshModulePaths(module) + fun getModulePaths(module: Module): ModulePaths? = modulePathCache[module] + + /** + * Checks if a given path is a generated directory based on annotation processor settings. + * + * @param module The module to check. + * @param path The path to check. + * @return True if the path is a generated directory, false otherwise. + */ + private fun isGeneratedDirectory( + module: Module, + path: String, + ): Boolean { + val project: Project = module.project + val compilerConfiguration = CompilerConfiguration.getInstance(project).getAnnotationProcessingConfiguration(module) + val annotationProcessingConfiguration = compilerConfiguration.getGeneratedSourcesDirectoryName(false) + + // Check if the path matches any of the generated source directories + return path.contains("/build/$annotationProcessingConfiguration/") + } /** * Refreshes the directory information for the specified module and updates the cache. @@ -65,38 +83,53 @@ object CommonPathParameterUtil { * @param module The module to refresh. * @return The updated ModulePaths. */ - fun refreshModulePaths(module: Module): ModulePaths { - var basePath: VirtualFile? = null + fun refreshModulePaths(module: Module) { val sourceDirs = mutableListOf() val resourceDirs = mutableListOf() val testSourceDirs = mutableListOf() val testResourceDirs = mutableListOf() val moduleManager = ModuleRootManager.getInstance(module) - moduleManager.contentEntries.firstOrNull()?.let { entry -> - basePath = entry.file - entry.sourceFolders.forEach { folder -> - val file = folder.file - if (file != null) { - when (folder.rootType) { - JavaSourceRootType.SOURCE -> sourceDirs.add(file) - JavaSourceRootType.TEST_SOURCE -> testSourceDirs.add(file) - JavaResourceRootType.RESOURCE -> resourceDirs.add(file) - JavaResourceRootType.TEST_RESOURCE -> testResourceDirs.add(file) + moduleManager.contentEntries.forEach { entry -> + val entryFile = entry.file + if (entryFile != null && !isGeneratedDirectory(module, entryFile.path)) { + entry.sourceFolders.forEach { folder -> + val file = folder.file + if (file != null) { + when (folder.rootType) { + JavaSourceRootType.SOURCE -> + if (!sourceDirs.contains(file)) { + sourceDirs.add(file) + } + + JavaSourceRootType.TEST_SOURCE -> + if (!testSourceDirs.contains(file)) { + testSourceDirs.add(file) + } + + JavaResourceRootType.RESOURCE -> + if (!resourceDirs.contains(file)) { + resourceDirs.add(file) + } + + JavaResourceRootType.TEST_RESOURCE -> + if (!testResourceDirs.contains(file)) { + testResourceDirs.add(file) + } + } } } } } + val paths = ModulePaths( - basePath, sourceDirs, resourceDirs, testSourceDirs, testResourceDirs, ) modulePathCache[module] = paths - return paths } /** @@ -110,7 +143,7 @@ object CommonPathParameterUtil { module: Module, file: VirtualFile, ): Boolean { - val paths = getModulePaths(module) + val paths = getModulePaths(module) ?: return false if (paths.moduleTestSourceDirectories.any { file.path.contains(it.path) }) return true if (paths.moduleTestResourceDirectories.any { file.path.contains(it.path) }) return true return false @@ -127,30 +160,14 @@ object CommonPathParameterUtil { fun getResources( module: Module, file: VirtualFile, - ): List = - if (isTest(module, file)) { - getModulePaths(module).moduleTestResourceDirectories - } else { - getModulePaths(module).moduleResourceDirectories - } - - /** - * Returns the source directories for the given file in the specified module. - * If the file is in a test directory, test source directories are returned. - * - * @param module The module to check. - * @param file The file to check. - * @return List of source directories. - */ - fun getSources( - module: Module, - file: VirtualFile, - ): List = - if (isTest(module, file)) { - getModulePaths(module).moduleTestSourceDirectories + ): List { + val modulePaths = getModulePaths(module) ?: return emptyList() + return if (isTest(module, file)) { + modulePaths.moduleTestResourceDirectories } else { - getModulePaths(module).moduleSourceDirectories + modulePaths.moduleResourceDirectories } + } /** * Clears the module directory cache. Call this if the module structure changes. diff --git a/src/main/kotlin/org/domaframework/doma/intellij/common/config/DomaCompileConfigUtil.kt b/src/main/kotlin/org/domaframework/doma/intellij/common/config/DomaCompileConfigUtil.kt index f9a84d84..8b720e3b 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/common/config/DomaCompileConfigUtil.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/common/config/DomaCompileConfigUtil.kt @@ -15,9 +15,8 @@ */ package org.domaframework.doma.intellij.common.config -import com.intellij.openapi.project.Project -import com.intellij.openapi.vfs.VirtualFile -import org.domaframework.doma.intellij.common.CommonPathParameterUtil +import com.intellij.openapi.module.Module +import org.domaframework.doma.intellij.extension.getResourcesFile import java.util.concurrent.ConcurrentHashMap object DomaCompileConfigUtil { @@ -30,40 +29,34 @@ object DomaCompileConfigUtil { /** * Get the value of the specified key from doma.compile.config - * @param project active project - * @param resourcePaths the path to the resource directories + * @param module the module to retrieve the configuration from + * @param isTest true if the configuration is for test sources, false for main sources * @param key the key to retrieve the value for * @return the value associated with the key, or null if not found */ fun getConfigValue( - project: Project, - resourcePaths: List, + module: Module, + isTest: Boolean, key: String, ): String? { - resourcePaths.forEach { resourcePath -> - if (resourcePath.isValid) { - val configVFile = resourcePath.findChild("doma.compile.config") - val cacheKey = "${project.basePath}/${resourcePath.path}/doma.compile.config" - val lastModified = configVFile?.timeStamp ?: 0L - val cached = configCache[cacheKey] + val settingFileName = "doma.compile.config" + val settingFile = module.getResourcesFile(settingFileName, isTest) + val cacheKey = "${settingFile?.path}/$settingFileName" + val lastModified = settingFile?.timeStamp ?: 0L + val cached = configCache[cacheKey] - val props = - if (cached == null || cached.second != lastModified) { - val loadedProps = - configVFile?.inputStream?.use { input -> - java.util.Properties().apply { load(input) } - } ?: java.util.Properties() - configCache[cacheKey] = loadedProps to lastModified - loadedProps - } else { - cached.first - } - val propProperty = props.getProperty(key) - if (propProperty != null) return propProperty + val props = + if (cached == null || cached.second != lastModified) { + val loadedProps = + settingFile?.inputStream?.use { input -> + java.util.Properties().apply { load(input) } + } ?: java.util.Properties() + configCache[cacheKey] = loadedProps to lastModified + loadedProps } else { - CommonPathParameterUtil.clearCache() + cached.first } - } - return null + val propProperty = props.getProperty(key) + return propProperty } } diff --git a/src/main/kotlin/org/domaframework/doma/intellij/common/dao/DaoMethodUtil.kt b/src/main/kotlin/org/domaframework/doma/intellij/common/dao/DaoMethodUtil.kt index 6c14f7a8..05a57736 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/common/dao/DaoMethodUtil.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/common/dao/DaoMethodUtil.kt @@ -34,11 +34,10 @@ import org.domaframework.doma.intellij.common.getJarRoot import org.domaframework.doma.intellij.common.getMethodDaoFilePath import org.domaframework.doma.intellij.common.isInjectionSqlFile import org.domaframework.doma.intellij.common.isSupportFileType -import org.domaframework.doma.intellij.common.sourceExtensionNames -import org.domaframework.doma.intellij.extension.findFile import org.domaframework.doma.intellij.extension.getContentRoot import org.domaframework.doma.intellij.extension.getJavaClazz import org.domaframework.doma.intellij.extension.getModule +import org.domaframework.doma.intellij.extension.getSourceRootDir import org.jetbrains.kotlin.idea.base.util.module /** @@ -57,36 +56,24 @@ fun findDaoMethod( return PsiTreeUtil.getParentOfType(originalFile.context, PsiMethod::class.java) } } else if (isSupportFileType(originalFile)) { - // TODO: Add Support Kotlin val methodName = virtualFile.nameWithoutExtension val daoFile = daoFile ?: findDaoFile(project, originalFile) ?: return null if (module != null) { - val relativePath = + val contentRootPath = project.getContentRoot(virtualFile)?.path ?: return null + val daoJavaFile = getDaoPathFromSqlFilePath( originalFile, - project.getContentRoot(virtualFile)?.path ?: "", - ) - // get ClassPath with package name - val daoClassName: String = - relativePath - .substringBefore(".") - .replace("/", ".") - .replace("\\", ".") - .replace("..", ".") - .trim('.') + contentRootPath, + ) ?: return null - val daoJavaFile = project.findFile(daoFile) - val isTest = CommonPathParameterUtil.isTest(module, originalFile.virtualFile) - findDaoClass(module, isTest, daoClassName) - ?.let { daoClass -> - val daoMethod = - // TODO Support Kotlin Project - when (daoJavaFile) { - is PsiJavaFile -> findUseSqlDaoMethod(daoJavaFile, methodName) - else -> null - } - return daoMethod + // TODO Support Kotlin Project + val daoFile = daoJavaFile.containingFile + val daoMethod = + when (daoFile) { + is PsiJavaFile -> findUseSqlDaoMethod(daoFile, methodName) + else -> null } + return daoMethod } else { val fileType = getExtension(daoFile.fileType.name) val jarRootPath = virtualFile.path.substringBefore("jar!").plus("jar!") @@ -132,75 +119,36 @@ fun findDaoFile( if (contentRoot == null) { return getJarRoot(virtualFile, sqlFile) } - return searchDaoFile(sqlFile.module, contentRoot, sqlFile) + return getDaoPathFromSqlFilePath( + sqlFile, + contentRoot.path, + )?.containingFile?.virtualFile } -/** - * DAO file search for SQL file - */ -private fun searchDaoFile( - module: Module?, - contentRoot: VirtualFile?, - sqlFile: PsiFile, -): VirtualFile? { - val contentRootPath = contentRoot?.path ?: return null - val pathParams = module?.let { CommonPathParameterUtil.getModulePaths(it) } ?: return null - val moduleBaseName = pathParams.moduleBasePath?.nameWithoutExtension ?: "" - // TODO: Add Support Kotlin - val relativeDaoFilePaths = - getDaoPathFromSqlFilePath(sqlFile, contentRoot.path) - val sources = CommonPathParameterUtil.getSources(module, sqlFile.virtualFile) - - if (contentRootPath.endsWith(moduleBaseName) == true) { - sources.forEach { source -> - sourceExtensionNames.forEach { extension -> - val fileExtension = getExtension(extension) - val findDaoFile = - contentRoot.findFileByRelativePath("${source.nameWithoutExtension}$relativeDaoFilePaths.$fileExtension") - if (findDaoFile != null) return findDaoFile - } - } - } - return null -} - -private fun findDaoClass( - module: Module, - includeTest: Boolean, - daoClassName: String, -): PsiClass? = module.getJavaClazz(includeTest, daoClassName) - /** * Generate DAO deployment path from SQL file path * @param sqlFile SQL File - * @param projectRootPath project content Root Path + * @param contentRootPath project content Root Path * @return */ private fun getDaoPathFromSqlFilePath( sqlFile: PsiFile, - projectRootPath: String, -): String { + contentRootPath: String, +): PsiClass? { if (isInjectionSqlFile(sqlFile)) { - return "" - } - val module = sqlFile.module - val sqlPath = sqlFile.virtualFile?.path ?: return "" - var relativeFilePath = sqlPath.substring(projectRootPath.length) - if (!relativeFilePath.startsWith("/")) { - relativeFilePath = "/$relativeFilePath" + return null } - val resources = - module?.let { CommonPathParameterUtil.getResources(it, sqlFile.virtualFile) } - ?: emptyList() + val module = sqlFile.module ?: return null + val sqlPath = sqlFile.virtualFile?.path ?: return null + val relativePath = + sqlPath.substringAfter(contentRootPath, "").replace("/$RESOURCES_META_INF_PATH", "") + val resourcesRootPath = module.project.getSourceRootDir(sqlFile.virtualFile)?.name ?: "" + val isTest = CommonPathParameterUtil.isTest(module, sqlFile.virtualFile) - return resources - .firstOrNull { resource -> - relativeFilePath.startsWith("/" + resource.nameWithoutExtension) - }?.let { resource -> - relativeFilePath - .replace("${resource.nameWithoutExtension}/$RESOURCES_META_INF_PATH/", "") - .replace("/${sqlFile.name}", "") - } ?: "" + val packageName = relativePath.replaceFirst("/$resourcesRootPath/", "").replace("/${sqlFile.name}", "").replace("/", ".") + val daoClassFile = module.getJavaClazz(isTest, packageName) + + return daoClassFile } /** @@ -215,18 +163,14 @@ fun getRelativeSqlFilePathFromDaoFilePath( ): String { if (module == null) return "" val extension = daoFile.fileType.defaultExtension - val pathParams = CommonPathParameterUtil.getModulePaths(module) - var relativeSqlFilePath = - daoFile.path - .replaceFirst(pathParams.moduleBasePath?.path ?: "", "") - .replace(".$extension", "") - val sources = CommonPathParameterUtil.getSources(module, daoFile) - sources.forEach { source -> - relativeSqlFilePath = - relativeSqlFilePath.replaceFirst( - "/" + source.nameWithoutExtension, - RESOURCES_META_INF_PATH, - ) - } - return relativeSqlFilePath + val sourceRoot = module.project.getSourceRootDir(daoFile) ?: return "" + + val project = module.project + val sourceRootParent = project.getContentRoot(daoFile) ?: return "" + val daoFilePath = daoFile.path + + return daoFilePath + .substringAfter(sourceRootParent.path) + .replaceFirst("/${sourceRoot.name}", RESOURCES_META_INF_PATH) + .replace(".$extension", "") } diff --git a/src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiDaoMethod.kt b/src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiDaoMethod.kt index 74e6ee70..58705838 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiDaoMethod.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiDaoMethod.kt @@ -39,7 +39,8 @@ import org.domaframework.doma.intellij.common.getExtension import org.domaframework.doma.intellij.extension.findFile import org.domaframework.doma.intellij.extension.getContentRoot import org.domaframework.doma.intellij.extension.getModule -import org.domaframework.doma.intellij.extension.getResourcesSQLFile +import org.domaframework.doma.intellij.extension.getResourcesFile +import org.domaframework.doma.intellij.extension.getSourceRootDir import org.domaframework.doma.intellij.extension.psi.DomaAnnotationType import org.domaframework.doma.intellij.setting.SqlLanguage import org.jetbrains.kotlin.idea.base.util.module @@ -141,7 +142,7 @@ class PsiDaoMethod( return } else { sqlFile = - module.getResourcesSQLFile( + module.getResourcesFile( sqlFilePath, isTest, ) @@ -172,14 +173,19 @@ class PsiDaoMethod( fun generateSqlFile() { ApplicationManager.getApplication().runReadAction { + if (sqlFilePath.isEmpty()) return@runReadAction val rootDir = psiProject.getContentRoot(daoFile) ?: return@runReadAction val sqlFile = File(sqlFilePath) val sqlFileName = sqlFile.name - val resourceDir = - psiMethod.module - ?.let { CommonPathParameterUtil.getResources(it, daoFile).firstOrNull() } - ?: return@runReadAction - val parentDir = "${resourceDir.nameWithoutExtension}/${sqlFile.parent?.replace("\\", "/")}" + val module = psiMethod.module ?: return@runReadAction + val isTest = CommonPathParameterUtil.isTest(module, daoFile) + + val sqlDir = sqlFilePath.replace("/$sqlFileName", "") + val existSqlDir = module.getResourcesFile(sqlDir, isTest) + val resourceDir = existSqlDir ?.let { psiProject.getSourceRootDir(it) } + val resourcesDirPath = resourceDir?.nameWithoutExtension ?: "resources" + + val parentDir = "$resourcesDirPath/${sqlFile.parent?.replace("\\", "/")}" val parenDirPathSpirit = parentDir.split("/").toTypedArray() WriteCommandAction.runWriteCommandAction(psiProject) { diff --git a/src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/FunctionCallCollector.kt b/src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/FunctionCallCollector.kt index fe5d7527..a6427405 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/FunctionCallCollector.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/collector/FunctionCallCollector.kt @@ -36,23 +36,15 @@ class FunctionCallCollector( public override fun collect(): List? { var functions = mutableSetOf() val project = file?.project - val module = file?.module - val resourcePaths = - if (file?.virtualFile != null && module != null) { - CommonPathParameterUtil - .getResources(module, file.virtualFile) - } else { - emptyList() - } + val module = file?.module ?: return null + val isTest = CommonPathParameterUtil.isTest(module, file.virtualFile) val customFunctionClassName = - project?.let { - DomaCompileConfigUtil.getConfigValue( - it, - resourcePaths, - "doma.expr.functions", - ) - } + DomaCompileConfigUtil.getConfigValue( + module, + isTest, + "doma.expr.functions", + ) val expressionFunctionInterface = project?.let { ExpressionFunctionsHelper.setExpressionFunctionsInterface(it) } diff --git a/src/main/kotlin/org/domaframework/doma/intellij/extension/ModuleExtensions.kt b/src/main/kotlin/org/domaframework/doma/intellij/extension/ModuleExtensions.kt index 947a4f4e..14c94349 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/extension/ModuleExtensions.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/extension/ModuleExtensions.kt @@ -34,7 +34,7 @@ fun Module.getPackagePathFromDaoPath(daoFile: VirtualFile): VirtualFile? { getRelativeSqlFilePathFromDaoFilePath(daoFile, this) } ?: "" val isTest = CommonPathParameterUtil.isTest(this, daoFile) - return this.getResourcesSQLFile( + return this.getResourcesFile( packagePath, isTest, ) @@ -57,7 +57,7 @@ fun Module.getJavaClazz( * @param includeTest true: test source, false: main source * @return SQL file */ -fun Module.getResourcesSQLFile( +fun Module.getResourcesFile( relativePath: String, includeTest: Boolean, ): VirtualFile? = diff --git a/src/main/kotlin/org/domaframework/doma/intellij/extension/ProjectExtensions.kt b/src/main/kotlin/org/domaframework/doma/intellij/extension/ProjectExtensions.kt index cd78c5e1..00c3867b 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/extension/ProjectExtensions.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/extension/ProjectExtensions.kt @@ -17,6 +17,7 @@ package org.domaframework.doma.intellij.extension import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project +import com.intellij.openapi.roots.ProjectFileIndex import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.JavaPsiFacade @@ -51,3 +52,5 @@ fun Project.getJavaClazz(fqdn: String): PsiClass? { GlobalSearchScope.allScope(this), ) } + +fun Project.getSourceRootDir(file: VirtualFile): VirtualFile? = ProjectFileIndex.getInstance(this).getSourceRootForFile(file) diff --git a/src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/processor/InspectionFunctionCallVisitorProcessor.kt b/src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/processor/InspectionFunctionCallVisitorProcessor.kt index a3e5d9f3..d053c050 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/processor/InspectionFunctionCallVisitorProcessor.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/processor/InspectionFunctionCallVisitorProcessor.kt @@ -34,15 +34,13 @@ class InspectionFunctionCallVisitorProcessor( ) : InspectionVisitorProcessor(shortName) { fun check(holder: ProblemsHolder) { val project = element.project + val module = element.module ?: return val expressionHelper = ExpressionFunctionsHelper val expressionFunctionalInterface = expressionHelper.setExpressionFunctionsInterface(project) val functionName = element.elIdExpr - val resources = - element.module - ?.let { CommonPathParameterUtil.getResources(it, element.containingFile.virtualFile) } - ?: emptyList() - val customFunctionClassName = DomaCompileConfigUtil.getConfigValue(project, resources, "doma.expr.functions") + val isTest = CommonPathParameterUtil.isTest(module, element.containingFile.virtualFile) + val customFunctionClassName = DomaCompileConfigUtil.getConfigValue(module, isTest, "doma.expr.functions") var result: ValidationResult = ValidationInvalidFunctionCallResult( diff --git a/src/main/kotlin/org/domaframework/doma/intellij/refactoring/dao/DaoPackageRenameListenerProcessor.kt b/src/main/kotlin/org/domaframework/doma/intellij/refactoring/dao/DaoPackageRenameListenerProcessor.kt index 7397703f..41eb0e94 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/refactoring/dao/DaoPackageRenameListenerProcessor.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/refactoring/dao/DaoPackageRenameListenerProcessor.kt @@ -33,7 +33,7 @@ import org.domaframework.doma.intellij.common.CommonPathParameterUtil import org.domaframework.doma.intellij.common.RESOURCES_META_INF_PATH import org.domaframework.doma.intellij.common.dao.getDaoClass import org.domaframework.doma.intellij.common.util.PluginLoggerUtil -import org.domaframework.doma.intellij.extension.getResourcesSQLFile +import org.domaframework.doma.intellij.extension.getResourcesFile import org.jetbrains.kotlin.idea.base.util.module import java.io.IOException @@ -149,7 +149,7 @@ class DaoPackageRenameListenerProcessor : RefactoringElementListenerProvider { try { val newDir = VfsUtil.createDirectories(newPath) val oldResourcePath = - module.getResourcesSQLFile( + module.getResourcesFile( RESOURCES_META_INF_PATH + "/" + oldQualifiedName.replace(".", "/"), isTest, ) diff --git a/src/main/kotlin/org/domaframework/doma/intellij/reference/SqlElFunctionCallExprReference.kt b/src/main/kotlin/org/domaframework/doma/intellij/reference/SqlElFunctionCallExprReference.kt index 2523d3e6..0648e7fa 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/reference/SqlElFunctionCallExprReference.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/reference/SqlElFunctionCallExprReference.kt @@ -37,22 +37,20 @@ class SqlElFunctionCallExprReference( val variableName = functionCallExpr.elIdExpr.text ?: "" val project = element.project - val module = file.module + val module = file.module ?: return null val expressionFunctionsInterface = ExpressionFunctionsHelper.setExpressionFunctionsInterface(project) ?: return null - val resourcePaths = - module?.let { - CommonPathParameterUtil - .getResources(it, file.virtualFile) - } ?: emptyList() - - val customFunctionClassName = DomaCompileConfigUtil.getConfigValue(project, resourcePaths, "doma.expr.functions") + val isTest = + CommonPathParameterUtil + .isTest(module, file.virtualFile) + val customFunctionClassName = DomaCompileConfigUtil.getConfigValue(module, isTest, "doma.expr.functions") val implementsClass = if (customFunctionClassName != null) { - val expressionFunction = project.getJavaClazz(customFunctionClassName) + val customFunctionClass = customFunctionClassName + val expressionFunction = project.getJavaClazz(customFunctionClass) if (ExpressionFunctionsHelper.isInheritor(expressionFunction)) { expressionFunction } else { diff --git a/src/main/kotlin/org/domaframework/doma/intellij/setting/DomaToolStartupActivity.kt b/src/main/kotlin/org/domaframework/doma/intellij/setting/DomaToolStartupActivity.kt index 3c9cb78a..f28b3a9d 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/setting/DomaToolStartupActivity.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/setting/DomaToolStartupActivity.kt @@ -22,12 +22,15 @@ import org.domaframework.doma.intellij.common.util.PluginUtil class DomaToolStartupActivity : ProjectActivity { override suspend fun execute(project: Project) { + setProperty() + } + + private fun setProperty() { System.setProperty("org.domaframework.doma.intellij.log.path", PathManager.getLogPath()) System.setProperty( "org.domaframework.doma.intellij.plugin.version", PluginUtil.getVersion(), ) - println("PluginVersion: ${System.getProperty("org.domaframework.doma.intellij.plugin.version")} ") } } diff --git a/src/main/kotlin/org/domaframework/doma/intellij/setting/DomaToolsModuleRootListener.kt b/src/main/kotlin/org/domaframework/doma/intellij/setting/DomaToolsModuleRootListener.kt new file mode 100644 index 00000000..bfd0e582 --- /dev/null +++ b/src/main/kotlin/org/domaframework/doma/intellij/setting/DomaToolsModuleRootListener.kt @@ -0,0 +1,39 @@ +/* + * Copyright Doma Tools Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.domaframework.doma.intellij.setting + +import com.intellij.openapi.module.ModuleManager +import com.intellij.openapi.project.Project +import com.intellij.openapi.roots.ModuleRootEvent +import com.intellij.openapi.roots.ModuleRootListener +import org.domaframework.doma.intellij.common.CommonPathParameterUtil + +class DomaToolsModuleRootListener( + private val project: Project, +) : ModuleRootListener { + override fun rootsChanged(event: ModuleRootEvent) { + updateModuleDirectoryCache(project) + } + + fun updateModuleDirectoryCache(project: Project) { + val modules = ModuleManager.getInstance(project).modules + modules + .filter { module -> module.name != project.name } + .forEach { module -> + CommonPathParameterUtil.refreshModulePaths(module) + } + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 975b1d5b..b54ebd8f 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -15,6 +15,12 @@ messages.DomaToolsBundle messages.LLMInstallerBundle + + + + diff --git a/src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt b/src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt index 6d247f80..7ea34e49 100644 --- a/src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt +++ b/src/test/kotlin/org/domaframework/doma/intellij/DomaSqlTest.kt @@ -30,7 +30,7 @@ import com.intellij.testFramework.PsiTestUtil import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import org.domaframework.doma.intellij.common.CommonPathParameterUtil import org.domaframework.doma.intellij.common.RESOURCES_META_INF_PATH -import org.domaframework.doma.intellij.extension.getResourcesSQLFile +import org.domaframework.doma.intellij.extension.getResourcesFile import org.jetbrains.jps.model.java.JavaResourceRootType import org.jetbrains.jps.model.java.JavaSourceRootType import org.junit.Ignore @@ -231,7 +231,7 @@ open class DomaSqlTest : LightJavaCodeInsightFixtureTestCase() { ): VirtualFile? { val module = myFixture.module val sqlFileName = "$RESOURCES_META_INF_PATH/$packageName/dao/$sqlName" - return module?.getResourcesSQLFile( + return module?.getResourcesFile( sqlFileName, false, )