diff --git a/README.md b/README.md index 5b799ef8..93e186d7 100644 --- a/README.md +++ b/README.md @@ -66,15 +66,12 @@ Along with the Dao name change, we will refactor the SQL file directory and file ## Formatter(Preview) Provides code formatting for SQL syntax. - This feature is in preview. You cannot customize the indentation or keywords to be broken down! -You can reformat entire directories and files with "Code > Reformat Code". - -If you want to enable the plugin's formatting function, check "Enable SQL Format" in "Settings > Other Settings > Doma Tools". (The default is OFF.) - -![enableFormat.png](images/enableFormat.png) +Automatic indentation on newlines provided by the SQL formatting feature is disabled by default. +To enable auto-indentation, toggle the corresponding flag in the settings screen below. +`Settings > Other Settings > Doma Tools > Enable auto-indent for SQL` ## Reference resolution Ctrl+Click on a bind variable in an SQL file to jump to its source symbol: diff --git a/images/enableFormat.png b/images/enableFormat.png index f66c32a5..efbea28b 100644 Binary files a/images/enableFormat.png and b/images/enableFormat.png differ 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 816f79ee..f9a84d84 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 @@ -21,6 +21,8 @@ import org.domaframework.doma.intellij.common.CommonPathParameterUtil import java.util.concurrent.ConcurrentHashMap object DomaCompileConfigUtil { + const val EXPRESSION_FUNCTIONS_NAME = "org.seasar.doma.expr.ExpressionFunctions" + /** * Cache: key=file path, value=Pair */ diff --git a/src/main/kotlin/org/domaframework/doma/intellij/common/helper/ExpressionFunctionsHelper.kt b/src/main/kotlin/org/domaframework/doma/intellij/common/helper/ExpressionFunctionsHelper.kt index e6e58bb5..a86d23cf 100644 --- a/src/main/kotlin/org/domaframework/doma/intellij/common/helper/ExpressionFunctionsHelper.kt +++ b/src/main/kotlin/org/domaframework/doma/intellij/common/helper/ExpressionFunctionsHelper.kt @@ -17,6 +17,7 @@ package org.domaframework.doma.intellij.common.helper import com.intellij.openapi.project.Project import com.intellij.psi.PsiClass +import org.domaframework.doma.intellij.common.config.DomaCompileConfigUtil.EXPRESSION_FUNCTIONS_NAME import org.domaframework.doma.intellij.extension.getJavaClazz import org.domaframework.doma.intellij.extension.psi.psiClassType @@ -26,7 +27,7 @@ class ExpressionFunctionsHelper { fun setExpressionFunctionsInterface(project: Project): PsiClass? { val expressionFunctionsClass = - project.getJavaClazz("org.seasar.doma.expr.ExpressionFunctions") + project.getJavaClazz(EXPRESSION_FUNCTIONS_NAME) if (expressionFunctionsClass != null) { expressionFunction = expressionFunctionsClass } 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 e288487e..173f1f97 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 @@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemsHolder import com.intellij.psi.PsiMethod import org.domaframework.doma.intellij.common.CommonPathParameterUtil import org.domaframework.doma.intellij.common.config.DomaCompileConfigUtil +import org.domaframework.doma.intellij.common.config.DomaCompileConfigUtil.EXPRESSION_FUNCTIONS_NAME import org.domaframework.doma.intellij.common.helper.ExpressionFunctionsHelper import org.domaframework.doma.intellij.common.sql.validator.result.ValidationInvalidExpressionFunctionsResult import org.domaframework.doma.intellij.common.sql.validator.result.ValidationInvalidFunctionCallResult @@ -46,7 +47,7 @@ class InspectionFunctionCallVisitorProcessor( var result: ValidationResult = ValidationInvalidFunctionCallResult( functionName, - customFunctionClassName ?: "", + customFunctionClassName ?: EXPRESSION_FUNCTIONS_NAME, shortName, ) var methods: Array = emptyArray() diff --git a/src/main/resources/messages/DomaToolsBundle.properties b/src/main/resources/messages/DomaToolsBundle.properties index 15c9df2d..675a6dcf 100644 --- a/src/main/resources/messages/DomaToolsBundle.properties +++ b/src/main/resources/messages/DomaToolsBundle.properties @@ -8,9 +8,9 @@ inspection.invalid.dao.paramUse=There are unused parameters in the SQL [{0}] inspection.invalid.dao.parameter=The bind variable [{1}] does not exist in the Dao method [{0}] inspection.invalid.sql.topType=Can't get type of first element inspection.invalid.sql.staticProperty=[{0}] is not a public or static property in the class [{1}] -inspection.invalid.sql.testdata=Bind variables must be followed by test data +inspection.invalid.sql.testdata=Test data is required after a bind variable directive or a literal variable directive inspection.invalid.sql.classpath=A non-existent package or class name was specified [{0}] inspection.invalid.sql.iterable=The type that can be used in the loop directive is an Iterable type inspection.invalid.dao.duplicate=An element name that is a duplicate of an element name defined in SQL is used -inspection.invalid.sql.notFound.customFunction=An undefined built-in or custom function [{0}] is being called in class [{1}] +inspection.invalid.sql.notFound.customFunction=Custom function [{0}] not found in class [{1}] inspection.invalid.sql.notFound.expressionClass=An invalid ExpressionFunctions implementation class is configured in doma.compile.config diff --git a/src/main/resources/messages/DomaToolsBundle_ja.properties b/src/main/resources/messages/DomaToolsBundle_ja.properties index 61014db1..01f24936 100644 --- a/src/main/resources/messages/DomaToolsBundle_ja.properties +++ b/src/main/resources/messages/DomaToolsBundle_ja.properties @@ -8,9 +8,9 @@ inspection.invalid.dao.paramUse=SQL\u3067\u4F7F\u7528\u3055\u308C\u3066\u3044\u3 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}] inspection.invalid.sql.topType=\u6700\u521D\u306E\u8981\u7D20\u306E\u578B\u304C\u53D6\u5F97\u3067\u304D\u307E\u305B\u3093 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 -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 +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 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}] 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 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 -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}] +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 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 diff --git a/src/test/kotlin/org/domaframework/doma/intellij/inspection/sql/ParameterDefinedTest.kt b/src/test/kotlin/org/domaframework/doma/intellij/inspection/sql/ParameterDefinedTest.kt index 70d1eff5..0ab6bfff 100644 --- a/src/test/kotlin/org/domaframework/doma/intellij/inspection/sql/ParameterDefinedTest.kt +++ b/src/test/kotlin/org/domaframework/doma/intellij/inspection/sql/ParameterDefinedTest.kt @@ -41,6 +41,7 @@ class ParameterDefinedTest : DomaSqlTest() { "$testDaoName/optionalDaoParameterFieldAccess.sql", "$testDaoName/implementCustomFunctions.sql", "$testDaoName/invalidImplementCustomFunctions.sql", + "$testDaoName/emptyImplementCustomFunctions.sql", ) myFixture.enableInspections(SqlBindVariableValidInspector()) } @@ -144,4 +145,14 @@ class ParameterDefinedTest : DomaSqlTest() { myFixture.testHighlighting(false, false, false, sqlFile) } + + fun testEmptyImplementCustomFunctions() { + addResourceCompileFile("empty.doma.compile.config") + val sqlFile = + findSqlFile("$testDaoName/emptyImplementCustomFunctions.sql") + assertNotNull("Not Found SQL File", sqlFile) + if (sqlFile == null) return + + myFixture.testHighlighting(false, false, false, sqlFile) + } } diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/emptyImplementCustomFunctions.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/emptyImplementCustomFunctions.sql new file mode 100644 index 00000000..d88a810d --- /dev/null +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/emptyImplementCustomFunctions.sql @@ -0,0 +1,10 @@ +SELECT + e.employee_id + , u.user_id + , u.user_name + FROM user u + WHERE p.employee_id = /* employee.employeeId */0 + AND p.user_id = /* employee.userId */0 + OR is_gest = /* @isGest() */false + OR flag = /* @authUser() */false + AND lang = /* @getLangCode() */'en' \ No newline at end of file diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/implementCustomFunctions.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/implementCustomFunctions.sql index 5188b9c6..ae736083 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/implementCustomFunctions.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/EmployeeSummaryDao/implementCustomFunctions.sql @@ -6,5 +6,5 @@ SELECT WHERE p.employee_id = /* employee.employeeId */0 AND p.user_id = /* employee.userId */0 OR is_gest = /* @isGest() */false - OR flag = /* @authUser() */false - AND lang = /* @getLangCode() */'en' \ No newline at end of file + OR flag = /* @authUser() */false + AND lang = /* @getLangCode() */'en' \ No newline at end of file diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/bindVariableDirective.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/bindVariableDirective.sql index c78405b6..572184db 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/bindVariableDirective.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/bindVariableDirective.sql @@ -3,5 +3,5 @@ INSERT INTO employee , employee_name , department_name) VALUES ( /* employee.employeeId */0 - , /* employee.employeeName */ - , /* employee.department */) + , /* employee.employeeName */ + , /* employee.department */) diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/commentBlock.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/commentBlock.sql index 2e33988e..d1b9fa98 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/commentBlock.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/commentBlock.sql @@ -7,7 +7,7 @@ SELECT e.employee_id AS employeeId */ FROM employee e /*%! This comment will be removed */ - WHERE e.employee_id = /*^ id */ + WHERE e.employee_id = /*^ id */ AND e.age >= /*^ literalAge */99 AND e.sub_id IN /* subIds */(1, 2, 3) AND e.sub_id IN /* subIds */(true, False, NULL) diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/conditionAndLoopDirective.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/conditionAndLoopDirective.sql index f0f75aff..962de317 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/conditionAndLoopDirective.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/conditionAndLoopDirective.sql @@ -1,6 +1,6 @@ SELECT * FROM employee - WHERE join_at <= /* referenceDate */ + WHERE join_at <= /* referenceDate */ /*%for project : projects */ employee_name LIKE /* project.projectName */'hoge' /*%if project_has_next */ diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/invalidTestData.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/invalidTestData.sql index b256a6d6..d16c6f97 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/invalidTestData.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/invalidTestData.sql @@ -4,4 +4,4 @@ INSERT INTO employee , department_name) VALUES ( /* employee.employeeId */0 , /* employee.employeeName */'name' - , /* employee.department */department) + , /* employee.department */department) diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/literalDirective.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/literalDirective.sql index 4300e1c1..31984536 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/literalDirective.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/literalDirective.sql @@ -2,8 +2,8 @@ SELECT e.employee_id AS employeeId , e.employee_name AS employeeName , e.department_name AS departmentName FROM employee e - WHERE e.employee_id = /*^ literalId */ - AND e.employee_name = /*^ literalName */ + WHERE e.employee_id = /*^ literalId */ + AND e.employee_name = /*^ literalName */ AND e.age >= /*^ literalAge */99 AND e.use = /* literalTrue */TRUE AND e.use = /* literalFalse */false diff --git a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/populateDirective.sql b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/populateDirective.sql index 8c0d8118..04fecd70 100644 --- a/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/populateDirective.sql +++ b/src/test/testData/src/main/resources/META-INF/doma/example/dao/inspection/TestDataCheckDao/populateDirective.sql @@ -1,3 +1,3 @@ UPDATE employee SET /*%populate*/id = id - WHERE rank < /* emplotee.rank */ + WHERE rank < /* emplotee.rank */ diff --git a/src/test/testData/src/main/resources/empty.doma.compile.config b/src/test/testData/src/main/resources/empty.doma.compile.config new file mode 100644 index 00000000..e69de29b