Skip to content

Commit 959eb71

Browse files
authored
Merge branch 'main' into fix/must-be-called-on-edt
2 parents aa9e41f + a1dc2f6 commit 959eb71

File tree

57 files changed

+735
-648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+735
-648
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,11 @@ Some functions of "Doma Tools" can be customized from the settings screen.
9797
- Customize action shortcut keys
9898
- Toggle the SQL formatting feature on or off
9999
- Specify the class names that define custom functions.
100-
![setting.png](images/setting.png)
100+
101+
**If you want to use custom functions defined in your own ExpressionFunctions implementation class,
102+
place a `doma.compile.config` file directly under the resources directory and describe the `doma.expr.functions` entry.**
103+
104+
ex) doma.compile.config
105+
```properties
106+
doma.expr.functions=example.expression.MyExpressionFunctions
107+
```

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ slf4j = { group = "org.slf4j", name = "slf4j-api", version = "2.0.17" }
1919
kotlinTest = { group = "org.jetbrains.kotlin", name = "kotlin-test" }
2020
domacore = { module = "org.seasar.doma:doma-core", version.ref = "doma" }
2121
google-java-format = { module = "com.google.googlejavaformat:google-java-format", version = "1.27.0" }
22-
ktlint = { module = "com.pinterest.ktlint:ktlint-cli", version = "1.5.0" }
22+
ktlint = { module = "com.pinterest.ktlint:ktlint-cli", version = "1.6.0" }
2323
jackson = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version = "2.19.0" }
2424

2525
[plugins]

images/setting.png

-9.54 KB
Binary file not shown.

src/main/java/org/domaframework/doma/intellij/psi/SqlElCommentExprImpl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ public SqlElCommentExprImpl(@NotNull ASTNode node) {
4141
super(node);
4242
}
4343

44-
@Override
45-
public @NotNull ASTNode getNode() {
46-
return super.getNode();
47-
}
48-
4944
@Override
5045
public @NotNull IElementType getTokenType() {
5146
return getNode().getElementType();

src/main/kotlin/org/domaframework/doma/intellij/action/sql/BindVariableElement.kt

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/main/kotlin/org/domaframework/doma/intellij/action/sql/JumpToDaoFromSQLAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class JumpToDaoFromSQLAction : AnAction() {
5656
val project = e.project ?: return
5757
val daoFile = findDaoFile(project, file) ?: return
5858

59-
val nameWithoutExtension = file.virtualFile?.nameWithoutExtension ?: return
60-
jumpToDaoMethod(project, nameWithoutExtension, daoFile)
59+
val sqlFileName = file.virtualFile?.nameWithoutExtension ?: return
60+
jumpToDaoMethod(project, sqlFileName, daoFile)
6161
PluginLoggerUtil.countLoggingByAction(
6262
this::class.java.simpleName,
6363
"JumpToDao",
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* Copyright Doma Tools Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.domaframework.doma.intellij.common
17+
18+
import com.intellij.openapi.module.Module
19+
import com.intellij.openapi.roots.ModuleRootManager
20+
import com.intellij.openapi.vfs.VirtualFile
21+
import org.jetbrains.jps.model.java.JavaResourceRootType
22+
import org.jetbrains.jps.model.java.JavaSourceRootType
23+
import java.util.concurrent.ConcurrentHashMap
24+
25+
val RESOURCES_META_INF_PATH: String
26+
get() = "META-INF"
27+
28+
/**
29+
* A utility for caching directory information on a per-module basis.
30+
*/
31+
object CommonPathParameterUtil {
32+
/**
33+
* Holds directory information for a module.
34+
*
35+
* @property moduleBasePath The base path of the module.
36+
* @property moduleSourceDirectories List of source directories.
37+
* @property moduleResourceDirectories List of resource directories.
38+
* @property moduleTestSourceDirectories List of test source directories.
39+
* @property moduleTestResourceDirectories List of test resource directories.
40+
*/
41+
data class ModulePaths(
42+
val moduleBasePath: VirtualFile?,
43+
val moduleSourceDirectories: List<VirtualFile>,
44+
val moduleResourceDirectories: List<VirtualFile>,
45+
val moduleTestSourceDirectories: List<VirtualFile>,
46+
val moduleTestResourceDirectories: List<VirtualFile>,
47+
)
48+
49+
// Cache for each module's directory information.
50+
private val modulePathCache = ConcurrentHashMap<Module, ModulePaths>()
51+
52+
/**
53+
* Returns the directory information for the specified module (uses cache if available).
54+
* If the module's directory structure has changed, call [refreshModulePaths] to update the cache.
55+
*
56+
* @param module The module to retrieve directory information for.
57+
* @return The cached or newly computed ModulePaths.
58+
*/
59+
fun getModulePaths(module: Module): ModulePaths = modulePathCache[module] ?: refreshModulePaths(module)
60+
61+
/**
62+
* Refreshes the directory information for the specified module and updates the cache.
63+
* Call this method when the module's directory structure changes.
64+
*
65+
* @param module The module to refresh.
66+
* @return The updated ModulePaths.
67+
*/
68+
fun refreshModulePaths(module: Module): ModulePaths {
69+
var basePath: VirtualFile? = null
70+
val sourceDirs = mutableListOf<VirtualFile>()
71+
val resourceDirs = mutableListOf<VirtualFile>()
72+
val testSourceDirs = mutableListOf<VirtualFile>()
73+
val testResourceDirs = mutableListOf<VirtualFile>()
74+
75+
val moduleManager = ModuleRootManager.getInstance(module)
76+
moduleManager.contentEntries.firstOrNull()?.let { entry ->
77+
basePath = entry.file
78+
entry.sourceFolders.forEach { folder ->
79+
val file = folder.file
80+
if (file != null) {
81+
when (folder.rootType) {
82+
JavaSourceRootType.SOURCE -> sourceDirs.add(file)
83+
JavaSourceRootType.TEST_SOURCE -> testSourceDirs.add(file)
84+
JavaResourceRootType.RESOURCE -> resourceDirs.add(file)
85+
JavaResourceRootType.TEST_RESOURCE -> testResourceDirs.add(file)
86+
}
87+
}
88+
}
89+
}
90+
val paths =
91+
ModulePaths(
92+
basePath,
93+
sourceDirs,
94+
resourceDirs,
95+
testSourceDirs,
96+
testResourceDirs,
97+
)
98+
modulePathCache[module] = paths
99+
return paths
100+
}
101+
102+
/**
103+
* Determines if the given file belongs to a test source or test resource directory.
104+
*
105+
* @param module The module to check.
106+
* @param file The file to check.
107+
* @return True if the file is in a test directory, false otherwise.
108+
*/
109+
fun isTest(
110+
module: Module,
111+
file: VirtualFile,
112+
): Boolean {
113+
val paths = getModulePaths(module)
114+
if (paths.moduleTestSourceDirectories.any { file.path.contains(it.path) }) return true
115+
if (paths.moduleTestResourceDirectories.any { file.path.contains(it.path) }) return true
116+
return false
117+
}
118+
119+
/**
120+
* Returns the resource directories for the given file in the specified module.
121+
* If the file is in a test directory, test resource directories are returned.
122+
*
123+
* @param module The module to check.
124+
* @param file The file to check.
125+
* @return List of resource directories.
126+
*/
127+
fun getResources(
128+
module: Module,
129+
file: VirtualFile,
130+
): List<VirtualFile> =
131+
if (isTest(module, file)) {
132+
getModulePaths(module).moduleTestResourceDirectories
133+
} else {
134+
getModulePaths(module).moduleResourceDirectories
135+
}
136+
137+
/**
138+
* Returns the source directories for the given file in the specified module.
139+
* If the file is in a test directory, test source directories are returned.
140+
*
141+
* @param module The module to check.
142+
* @param file The file to check.
143+
* @return List of source directories.
144+
*/
145+
fun getSources(
146+
module: Module,
147+
file: VirtualFile,
148+
): List<VirtualFile> =
149+
if (isTest(module, file)) {
150+
getModulePaths(module).moduleTestSourceDirectories
151+
} else {
152+
getModulePaths(module).moduleSourceDirectories
153+
}
154+
155+
/**
156+
* Clears the module directory cache. Call this if the module structure changes.
157+
*/
158+
fun clearCache() {
159+
modulePathCache.clear()
160+
}
161+
}

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

Lines changed: 0 additions & 29 deletions
This file was deleted.

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

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
package org.domaframework.doma.intellij.common
1717

1818
import com.intellij.openapi.fileTypes.FileTypeManager
19-
import com.intellij.openapi.vfs.VirtualFile
2019
import com.intellij.psi.PsiFile
21-
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.SRC_MAIN_PATH
20+
21+
val sourceExtensionNames: List<String> = listOf("JAVA", "Kotlin", "CLASS")
2222

2323
/**
2424
* Get extension by file type identifier
@@ -66,36 +66,3 @@ fun isInjectionSqlFile(file: PsiFile): Boolean {
6666
} &&
6767
!(filePath.endsWith(".sql") || filePath.endsWith(".script"))
6868
}
69-
70-
/**
71-
* Dao file search for SQL files
72-
*/
73-
fun searchDaoFile(
74-
contentRoot: VirtualFile?,
75-
originFilePath: String,
76-
relativeDaoFilePath: String,
77-
): VirtualFile? {
78-
val projectRootPath = contentRoot?.path ?: return null
79-
if (projectRootPath.endsWith(SRC_MAIN_PATH)) {
80-
return contentRoot.findFileByRelativePath(relativeDaoFilePath)
81-
}
82-
83-
if (projectRootPath.length > originFilePath.length) {
84-
return null
85-
}
86-
87-
// TODO Dynamically build the source directory path and retrieve subproject info
88-
// by inspecting file metadata instead of using string manipulation.
89-
val index = originFilePath.indexOf(SRC_MAIN_PATH)
90-
val projectRootPathBefore = projectRootPath.substringBefore(SRC_MAIN_PATH)
91-
if (index < 0 || projectRootPathBefore.length < index) return null
92-
val subProjectName =
93-
originFilePath.substring(projectRootPathBefore.length, index)
94-
95-
val daoFile =
96-
contentRoot
97-
.findFileByRelativePath(subProjectName)
98-
?.findFileByRelativePath(relativeDaoFilePath)
99-
100-
return daoFile
101-
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package org.domaframework.doma.intellij.common
1818
import com.intellij.openapi.vfs.StandardFileSystems
1919
import com.intellij.openapi.vfs.VirtualFile
2020
import com.intellij.psi.PsiFile
21-
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_META_INF_PATH
2221

2322
fun getJarRoot(
2423
virtualFile: VirtualFile,

0 commit comments

Comments
 (0)