Skip to content

Commit 7ee2a6c

Browse files
committed
Refactor error messages for SQL validation and enhance expression function handling
1 parent ac272dc commit 7ee2a6c

File tree

17 files changed

+44
-22
lines changed

17 files changed

+44
-22
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,12 @@ Along with the Dao name change, we will refactor the SQL file directory and file
6666

6767
## Formatter(Preview)
6868
Provides code formatting for SQL syntax.
69-
7069
This feature is in preview. You cannot customize the indentation or keywords to be broken down!
7170

72-
You can reformat entire directories and files with "Code > Reformat Code".
73-
74-
If you want to enable the plugin's formatting function, check "Enable SQL Format" in "Settings > Other Settings > Doma Tools". (The default is OFF.)
75-
76-
![enableFormat.png](images/enableFormat.png)
71+
Automatic indentation on newlines provided by the SQL formatting feature is disabled by default.
72+
To enable auto-indentation, toggle the corresponding flag in the settings screen below.
7773

74+
`Settings > Other Settings > Doma Tools > Enable auto-indent for SQL`
7875
## Reference resolution
7976
Ctrl+Click on a bind variable in an SQL file to jump to its source symbol:
8077

images/enableFormat.png

8.07 KB
Loading

src/main/kotlin/org/domaframework/doma/intellij/common/config/DomaCompileConfigUtil.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import org.domaframework.doma.intellij.common.CommonPathParameterUtil
2121
import java.util.concurrent.ConcurrentHashMap
2222

2323
object DomaCompileConfigUtil {
24+
const val EXPRESSION_FUNCTIONS_NAME = "org.seasar.doma.expr.ExpressionFunctions"
25+
2426
/**
2527
* Cache: key=file path, value=Pair<Properties, last update time>
2628
*/

src/main/kotlin/org/domaframework/doma/intellij/common/helper/ExpressionFunctionsHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package org.domaframework.doma.intellij.common.helper
1717

1818
import com.intellij.openapi.project.Project
1919
import com.intellij.psi.PsiClass
20+
import org.domaframework.doma.intellij.common.config.DomaCompileConfigUtil.EXPRESSION_FUNCTIONS_NAME
2021
import org.domaframework.doma.intellij.extension.getJavaClazz
2122
import org.domaframework.doma.intellij.extension.psi.psiClassType
2223

@@ -26,7 +27,7 @@ class ExpressionFunctionsHelper {
2627

2728
fun setExpressionFunctionsInterface(project: Project): PsiClass? {
2829
val expressionFunctionsClass =
29-
project.getJavaClazz("org.seasar.doma.expr.ExpressionFunctions")
30+
project.getJavaClazz(EXPRESSION_FUNCTIONS_NAME)
3031
if (expressionFunctionsClass != null) {
3132
expressionFunction = expressionFunctionsClass
3233
}

src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/processor/InspectionFunctionCallVisitorProcessor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemsHolder
1919
import com.intellij.psi.PsiMethod
2020
import org.domaframework.doma.intellij.common.CommonPathParameterUtil
2121
import org.domaframework.doma.intellij.common.config.DomaCompileConfigUtil
22+
import org.domaframework.doma.intellij.common.config.DomaCompileConfigUtil.EXPRESSION_FUNCTIONS_NAME
2223
import org.domaframework.doma.intellij.common.helper.ExpressionFunctionsHelper
2324
import org.domaframework.doma.intellij.common.sql.validator.result.ValidationInvalidExpressionFunctionsResult
2425
import org.domaframework.doma.intellij.common.sql.validator.result.ValidationInvalidFunctionCallResult
@@ -46,7 +47,7 @@ class InspectionFunctionCallVisitorProcessor(
4647
var result: ValidationResult =
4748
ValidationInvalidFunctionCallResult(
4849
functionName,
49-
customFunctionClassName ?: "",
50+
customFunctionClassName ?: EXPRESSION_FUNCTIONS_NAME,
5051
shortName,
5152
)
5253
var methods: Array<out PsiMethod?> = emptyArray()

src/main/resources/messages/DomaToolsBundle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ inspection.invalid.dao.paramUse=There are unused parameters in the SQL [{0}]
88
inspection.invalid.dao.parameter=The bind variable [{1}] does not exist in the Dao method [{0}]
99
inspection.invalid.sql.topType=Can't get type of first element
1010
inspection.invalid.sql.staticProperty=[{0}] is not a public or static property in the class [{1}]
11-
inspection.invalid.sql.testdata=Bind variables must be followed by test data
11+
inspection.invalid.sql.testdata=Test data is required after a bind variable directive or a literal variable directive
1212
inspection.invalid.sql.classpath=A non-existent package or class name was specified [{0}]
1313
inspection.invalid.sql.iterable=The type that can be used in the loop directive is an Iterable type
1414
inspection.invalid.dao.duplicate=An element name that is a duplicate of an element name defined in SQL is used
15-
inspection.invalid.sql.notFound.customFunction=An undefined built-in or custom function [{0}] is being called in class [{1}]
15+
inspection.invalid.sql.notFound.customFunction=Custom function [{0}] not found in class [{1}]
1616
inspection.invalid.sql.notFound.expressionClass=An invalid ExpressionFunctions implementation class is configured in doma.compile.config

src/main/resources/messages/DomaToolsBundle_ja.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ inspection.invalid.dao.paramUse=SQL\u3067\u4F7F\u7528\u3055\u308C\u3066\u3044\u3
88
inspection.invalid.dao.parameter=Dao\u30E1\u30BD\u30C3\u30C9[{0}]\u306B\u5B58\u5728\u3057\u306A\u3044\u30D0\u30A4\u30F3\u30C9\u5909\u6570\u304C\u4F7F\u7528\u3055\u308C\u3066\u3044\u307E\u3059:[{1}]
99
inspection.invalid.sql.topType=\u6700\u521D\u306E\u8981\u7D20\u306E\u578B\u304C\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093
1010
inspection.invalid.sql.staticProperty=[{0}]\u0020\u306F\u30AF\u30E9\u30B9\u0020[{1}]\u0020\u306E\u0020\u0070\u0075\u0062\u006C\u0069\u0063\u0020\u307E\u305F\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u30D7\u30ED\u30D1\u30C6\u30A3\u3067\u306F\u3042\u308A\u307E\u305B\u3093
11-
inspection.invalid.sql.testdata=\u30D0\u30A4\u30F3\u30C9\u5909\u6570\u306E\u5F8C\u308D\u306B\u306F\u30C6\u30B9\u30C8\u30C7\u30FC\u30BF\u304C\u5FC5\u8981\u3067\u3059
11+
inspection.invalid.sql.testdata=\u30D0\u30A4\u30F3\u30C9\u5909\u6570\u30C7\u30A3\u30EC\u30AF\u30C6\u30A3\u30D6\u3001\u30EA\u30C6\u30E9\u30EB\u5909\u6570\u30C7\u30A3\u30EC\u30AF\u30C6\u30A3\u30D6\u306E\u5F8C\u308D\u306B\u306F\u30C6\u30B9\u30C8\u30C7\u30FC\u30BF\u304C\u5FC5\u8981\u3067\u3059
1212
inspection.invalid.sql.classpath=\u5B58\u5728\u3057\u306A\u3044\u30D1\u30C3\u30B1\u30FC\u30B8\u307E\u305F\u306F\u30AF\u30E9\u30B9\u540D\u304C\u6307\u5B9A\u3055\u308C\u307E\u3057\u305F\u3002:[{0}]
1313
inspection.invalid.sql.iterable=\u30EB\u30FC\u30D7\u30C7\u30A3\u30EC\u30AF\u30C6\u30A3\u30D6\u306B\u4F7F\u7528\u3067\u304D\u308B\u578B\u306F\u0049\u0074\u0065\u0072\u0061\u0062\u006C\u0065\u578B\u3067\u3059
1414
inspection.invalid.dao.duplicate=\u0053\u0051\u004C\u5185\u3067\u5B9A\u7FA9\u3055\u308C\u305F\u8981\u7D20\u540D\u3068\u91CD\u8907\u3057\u305F\u8981\u7D20\u540D\u304C\u4F7F\u7528\u3055\u308C\u3066\u3044\u307E\u3059
15-
inspection.invalid.sql.notFound.customFunction=\u5B9A\u7FA9\u3055\u308C\u3066\u3044\u306A\u3044\u7D44\u307F\u8FBC\u307F\u95A2\u6570\u307E\u305F\u306F\u30AB\u30B9\u30BF\u30E0\u95A2\u6570\u304C\u547C\u3073\u51FA\u3055\u308C\u3066\u3044\u307E\u3059:[{0}] in class [{1}]
15+
inspection.invalid.sql.notFound.customFunction=\u30AB\u30B9\u30BF\u30E0\u95A2\u6570[{0}]\u304C\u30AF\u30E9\u30B9[{1}]\u5185\u306B\u898B\u3064\u304B\u308A\u307E\u305B\u3093
1616
inspection.invalid.sql.notFound.expressionClass=\u0064\u006F\u006D\u0061\u002E\u0063\u006F\u006D\u0070\u0069\u006C\u0065\u002E\u0063\u006F\u006E\u0066\u0069\u0067\u0020\u306B\u7121\u52B9\u306A\u0020\u0045\u0078\u0070\u0072\u0065\u0073\u0073\u0069\u006F\u006E\u0046\u0075\u006E\u0063\u0074\u0069\u006F\u006E\u0073\u0020\u5B9F\u88C5\u30AF\u30E9\u30B9\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u307E\u3059

src/test/kotlin/org/domaframework/doma/intellij/inspection/sql/ParameterDefinedTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ParameterDefinedTest : DomaSqlTest() {
4141
"$testDaoName/optionalDaoParameterFieldAccess.sql",
4242
"$testDaoName/implementCustomFunctions.sql",
4343
"$testDaoName/invalidImplementCustomFunctions.sql",
44+
"$testDaoName/emptyImplementCustomFunctions.sql",
4445
)
4546
myFixture.enableInspections(SqlBindVariableValidInspector())
4647
}
@@ -144,4 +145,14 @@ class ParameterDefinedTest : DomaSqlTest() {
144145

145146
myFixture.testHighlighting(false, false, false, sqlFile)
146147
}
148+
149+
fun testEmptyImplementCustomFunctions() {
150+
addResourceCompileFile("empty.doma.compile.config")
151+
val sqlFile =
152+
findSqlFile("$testDaoName/emptyImplementCustomFunctions.sql")
153+
assertNotNull("Not Found SQL File", sqlFile)
154+
if (sqlFile == null) return
155+
156+
myFixture.testHighlighting(false, false, false, sqlFile)
157+
}
147158
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SELECT
2+
e.employee_id
3+
, u.user_id
4+
, u.user_name
5+
FROM user u
6+
WHERE p.employee_id = /* employee.employeeId */0
7+
AND p.user_id = /* employee.userId */0
8+
OR is_gest = /* @<error descr="Custom function [isGest] not found in class [org.seasar.doma.expr.ExpressionFunctions]">isGest</error>() */false
9+
OR flag = /* @<error descr="Custom function [authUser] not found in class [org.seasar.doma.expr.ExpressionFunctions]">authUser</error>() */false
10+
AND lang = /* @<error descr="Custom function [getLangCode] not found in class [org.seasar.doma.expr.ExpressionFunctions]">getLangCode</error>() */'en'

src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/implementCustomFunctions.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ SELECT
66
WHERE p.employee_id = /* employee.employeeId */0
77
AND p.user_id = /* employee.userId */0
88
OR is_gest = /* @isGest() */false
9-
OR flag = /* @<error descr="An undefined built-in or custom function [authUser] is being called in class [doma.example.expression.TestExpressionFunctions]">authUser</error>() */false
10-
AND lang = /* @<error descr="An undefined built-in or custom function [getLangCode] is being called in class [doma.example.expression.TestExpressionFunctions]">getLangCode</error>() */'en'
9+
OR flag = /* @<error descr="Custom function [authUser] not found in class [doma.example.expression.TestExpressionFunctions]">authUser</error>() */false
10+
AND lang = /* @<error descr="Custom function [getLangCode] not found in class [doma.example.expression.TestExpressionFunctions]">getLangCode</error>() */'en'

0 commit comments

Comments
 (0)