-
Notifications
You must be signed in to change notification settings - Fork 0
Enable SQL File Generation in Multi-Module Projects #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…g and add checks for empty SQL file paths
…cks and improve null handling for SQL file paths
… relying on cached paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances SQL file generation in multi-module projects by collecting all source roots per module and matching DAO file paths against them, ensuring correct relative paths and avoiding mixed build/source paths.
- Add a ModuleRootListener and initial cache refresh to detect module root changes.
- Update DAO SQL path resolution to use multiple source roots and
getSourceRootDir. - Refactor
CommonPathParameterUtilto cache per-module paths (now keyed by module name) and filter out generated directories.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/resources/META-INF/plugin.xml | Register DomaToolsModuleRootListener as a project listener for root changes. |
| src/main/kotlin/.../DomaToolsModuleRootListener.kt | Implement listener to refresh module path cache on rootsChanged. |
| src/main/kotlin/.../DomaToolStartupActivity.kt | Trigger initial cache build and define registerModuleRootListener. |
| src/main/kotlin/.../ProjectExtensions.kt | Add getSourceRootDir extension to retrieve a file’s source root. |
| src/main/kotlin/.../PsiDaoMethod.kt | Refactor SQL file generation to use source-root-aware path resolution. |
| src/main/kotlin/.../DaoMethodUtil.kt | Rewrite DAO lookup logic to derive class from SQL path via source roots. |
| src/main/kotlin/.../CommonPathParameter.kt | Collect and cache all source/test/resource dirs, excluding generated dirs. |
Comments suppressed due to low confidence (3)
src/main/kotlin/org/domaframework/doma/intellij/common/psi/PsiDaoMethod.kt:193
- [nitpick] The variable name
parenDirPathSpiritappears misspelled and unclear. Consider renaming toparentDirSegmentsorparentDirParts. Also remove or use it explicitly if needed.
val parenDirPathSpirit = parentDir.split("/").toTypedArray()
src/main/kotlin/org/domaframework/doma/intellij/common/dao/DaoMethodUtil.kt:137
- The KDoc above this method still describes a
Stringreturn type and path logic. Update the documentation to accurately reflect that it now returns aPsiClass?and describe the new lookup behavior.
): PsiClass? {
src/main/kotlin/org/domaframework/doma/intellij/extension/ProjectExtensions.kt:21
- [nitpick] This import is no longer used in this file and can be removed to keep the code clean.
import com.intellij.openapi.roots.ProjectRootManager
src/main/kotlin/org/domaframework/doma/intellij/setting/DomaToolStartupActivity.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/org/domaframework/doma/intellij/common/CommonPathParameter.kt
Outdated
Show resolved
Hide resolved
…onfiguration retrieval
…he listener implementation to prevent runtime errors.
|
Follow the listener registration guidelines as documented here: |
Fix an issue where generating SQL files from DAO methods in a project with multiple modules (e.g., using Gradle source set configurations) results in an IOException.
Problem
When a subproject contains multiple modules and source sets, the existing logic caches a single directory structure per module, using the module as a key.
This leads to incorrect path resolution when DAO classes exist in different source roots, causing the SQL file generator to produce invalid paths (e.g., mixing build and source paths).
Fix
Cache Update via ModuleRootListener
The module directory structure cache is updated only when IntelliJ IDEA detects changes in the directory structure, using ModuleRootListener.
Minimal Use of Cache for File Resolution
For both DAO → SQL and SQL → DAO resolution, path generation is based on the file's own source root and content root, rather than relying on cached directory mappings.
File Resolution Logic
DAO → SQL
Generate the expected SQL file path from the DAO's content root:
Check if the corresponding file exists within the module’s resource directories using:
ResourceFileUtil.findResourceFileInScopeIf the SQL file does not yet exist, fallback to cached resource directory information.
If no resource directory is explicitly marked, use a default path.
SQL → DAO
From the SQL file path under /META-INF, extract the corresponding package name.
Use the package name and DAO file name to construct a fully qualified class name.
Resolve the class using
JavaPsiFacade, and set the matching DAO file as the navigation target.This approach ensures accurate file linkage in dynamic project structures, improves consistency, and reduces reliance on potentially outdated cached data.