Skip to content

Commit 06e51b2

Browse files
authored
Merge pull request #175 from domaframework/feature/support-custom-functions
Support custom functions
2 parents 3d3f1d6 + 1b6db0b commit 06e51b2

File tree

60 files changed

+977
-254
lines changed

Some content is hidden

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

60 files changed

+977
-254
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The plugin also provides quick fixes for Dao methods where the required SQL file
3939
- Check the class name and package name for static property calls
4040
![inspectionPackageName.png](images/inspectionPackageName.png)
4141
- Optional types are recognized as their element type (e.g. Optional<String> is treated as String).
42+
- Checks calls to custom functions and error-highlights any methods that aren’t defined in the classes registered via the settings.
4243

4344
## Completion
4445
Adds code completion functionality to support indexing of Doma directives and bind variables
@@ -54,6 +55,7 @@ Adds code completion functionality to support indexing of Doma directives and bi
5455
- Directives such as Condition, Loop, Population are suggested after “%”
5556
- Suggest built-in functions after “@”
5657
- Optional types are recognized as their element type (e.g. Optional<String> is treated as String).
58+
- Suggest functions during code completion from the ExpressionFunctions implementation classes registered in the settings.
5759

5860
## Refactoring
5961
Along with the Dao name change, we will refactor the SQL file directory and file name.
@@ -81,6 +83,7 @@ This feature works in source JARs as well, but in binary JARs, if the DAO method
8183
- The DAO method’s argument parameter definition
8284
- The field and method definitions on that parameter’s type
8385
- The class definition referenced by @ClassName@
86+
- Resolve references for custom functions using the ExpressionFunctions implementation class in which they are defined.
8487
- You can also jump using the **Go To > Declaration Usage** menu.
8588

8689
![reference.png](images/reference.png)
@@ -92,3 +95,6 @@ Some functions of "Doma Tools" can be customized from the settings screen.
9295
- Highlight color settings for SQL elements
9396
![setting_highlight.png](images/setting_highlight.png)
9497
- Customize action shortcut keys
98+
- Toggle the SQL formatting feature on or off
99+
- Specify the class names that define custom functions.
100+
![setting.png](images/setting.png)

images/setting.png

9.54 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
// TODO Dynamically build the source directory path and retrieve subproject info
19+
// by inspecting file metadata instead of using string manipulation.
20+
object CommonPathParameterHelper {
21+
val SRC_MAIN_PATH: String
22+
get() = "/src/main"
23+
24+
val RESOURCES_PATH: String
25+
get() = "resources"
26+
27+
val RESOURCES_META_INF_PATH: String
28+
get() = "META-INF"
29+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package org.domaframework.doma.intellij.common
1818
import com.intellij.openapi.fileTypes.FileTypeManager
1919
import com.intellij.openapi.vfs.VirtualFile
2020
import com.intellij.psi.PsiFile
21-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.SRC_MAIN_PATH
21+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.SRC_MAIN_PATH
2222

2323
/**
2424
* Get extension by file type identifier

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ 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.CommonPathParameter.Companion.RESOURCES_META_INF_PATH
21+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_META_INF_PATH
2222

2323
fun getJarRoot(
2424
virtualFile: VirtualFile,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import com.intellij.psi.PsiManager
2727
import com.intellij.psi.PsiMethod
2828
import com.intellij.psi.search.GlobalSearchScope
2929
import com.intellij.psi.util.PsiTreeUtil
30-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_META_INF_PATH
31-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_PATH
30+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_META_INF_PATH
31+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_PATH
3232
import org.domaframework.doma.intellij.common.getExtension
3333
import org.domaframework.doma.intellij.common.getJarRoot
3434
import org.domaframework.doma.intellij.common.getMethodDaoFilePath
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.helper
17+
18+
import com.intellij.openapi.project.Project
19+
import com.intellij.openapi.project.ProjectManager
20+
import com.intellij.openapi.wm.IdeFocusManager
21+
22+
object ActiveProjectHelper {
23+
private var activeProject: Project? = null
24+
25+
fun setCurrentActiveProject(value: Project?) {
26+
activeProject = value
27+
}
28+
29+
fun getCurrentActiveProject(): Project? {
30+
val initProject = activeProject
31+
val active = getActiveUIProject()
32+
return active ?: initProject
33+
}
34+
35+
private fun getActiveUIProject(): Project? {
36+
val openProjects: Array<out Project> = ProjectManager.getInstance().openProjects
37+
var active: Project? = null
38+
39+
for (project in openProjects) {
40+
if (IdeFocusManager.getInstance(project).focusOwner != null) {
41+
active = project
42+
break
43+
}
44+
}
45+
46+
return active
47+
}
48+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.helper
17+
18+
import com.intellij.openapi.project.Project
19+
import com.intellij.psi.PsiClass
20+
import org.domaframework.doma.intellij.extension.getJavaClazz
21+
import org.domaframework.doma.intellij.extension.psi.psiClassType
22+
23+
class ExpressionFunctionsHelper {
24+
companion object {
25+
var expressionFunction: PsiClass? = null
26+
27+
fun setExpressionFunctionsInterface(project: Project): PsiClass? {
28+
val expressionFunctionsClass =
29+
project.getJavaClazz("org.seasar.doma.expr.ExpressionFunctions")
30+
if (expressionFunctionsClass != null) {
31+
expressionFunction = expressionFunctionsClass
32+
}
33+
return expressionFunction
34+
}
35+
36+
fun isInheritor(expressionClazz: PsiClass?): Boolean {
37+
val project = expressionClazz?.project
38+
39+
expressionFunction?.let { functionInterface ->
40+
expressionClazz?.let {
41+
if (expressionClazz.isInheritor(functionInterface, true)) return true
42+
43+
val parentType =
44+
expressionClazz.superTypes.firstOrNull()?.canonicalText
45+
?: expressionClazz.psiClassType.canonicalText
46+
return project?.let {
47+
expressionClazz.psiClassType.canonicalText
48+
project
49+
.getJavaClazz(parentType)
50+
?.isInheritor(functionInterface, true) == true
51+
} == true
52+
}
53+
}
54+
return false
55+
}
56+
}
57+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import com.intellij.psi.PsiManager
3232
import com.intellij.psi.PsiMethod
3333
import com.intellij.psi.PsiNameValuePair
3434
import com.intellij.util.IncorrectOperationException
35-
import org.domaframework.doma.intellij.common.CommonPathParameter.Companion.RESOURCES_PATH
35+
import org.domaframework.doma.intellij.common.CommonPathParameterHelper.RESOURCES_PATH
3636
import org.domaframework.doma.intellij.common.dao.formatSqlPathFromDaoPath
3737
import org.domaframework.doma.intellij.common.getExtension
3838
import org.domaframework.doma.intellij.extension.findFile

src/main/kotlin/org/domaframework/doma/intellij/common/sql/directive/DirectiveCompletion.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616
package org.domaframework.doma.intellij.common.sql.directive
1717

1818
import com.intellij.codeInsight.completion.CompletionResultSet
19-
import com.intellij.openapi.project.Project
2019
import com.intellij.psi.PsiElement
2120
import com.intellij.psi.PsiFile
2221

2322
class DirectiveCompletion(
2423
private val originalFile: PsiFile,
2524
private val bindText: String,
2625
private val element: PsiElement,
27-
private val project: Project,
2826
private val result: CompletionResultSet,
2927
) {
3028
fun directiveHandle(symbol: String): Boolean {
@@ -56,7 +54,6 @@ class DirectiveCompletion(
5654
element = element,
5755
result = result,
5856
bindText = bindText,
59-
project = project,
6057
).directiveHandle()
6158

6259
else -> return false

0 commit comments

Comments
 (0)