Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Binary file modified images/enableFormat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Properties, last update time>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,7 +47,7 @@ class InspectionFunctionCallVisitorProcessor(
var result: ValidationResult =
ValidationInvalidFunctionCallResult(
functionName,
customFunctionClassName ?: "",
customFunctionClassName ?: EXPRESSION_FUNCTIONS_NAME,
shortName,
)
var methods: Array<out PsiMethod?> = emptyArray()
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/messages/DomaToolsBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/main/resources/messages/DomaToolsBundle_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ParameterDefinedTest : DomaSqlTest() {
"$testDaoName/optionalDaoParameterFieldAccess.sql",
"$testDaoName/implementCustomFunctions.sql",
"$testDaoName/invalidImplementCustomFunctions.sql",
"$testDaoName/emptyImplementCustomFunctions.sql",
)
myFixture.enableInspections(SqlBindVariableValidInspector())
}
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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 = /* @<error descr="Custom function [isGest] not found in class [org.seasar.doma.expr.ExpressionFunctions]">isGest</error>() */false
OR flag = /* @<error descr="Custom function [authUser] not found in class [org.seasar.doma.expr.ExpressionFunctions]">authUser</error>() */false
AND lang = /* @<error descr="Custom function [getLangCode] not found in class [org.seasar.doma.expr.ExpressionFunctions]">getLangCode</error>() */'en'
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /* @<error descr="An undefined built-in or custom function [authUser] is being called in class [doma.example.expression.TestExpressionFunctions]">authUser</error>() */false
AND lang = /* @<error descr="An undefined built-in or custom function [getLangCode] is being called in class [doma.example.expression.TestExpressionFunctions]">getLangCode</error>() */'en'
OR flag = /* @<error descr="Custom function [authUser] not found in class [doma.example.expression.TestExpressionFunctions]">authUser</error>() */false
AND lang = /* @<error descr="Custom function [getLangCode] not found in class [doma.example.expression.TestExpressionFunctions]">getLangCode</error>() */'en'
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ INSERT INTO employee
, employee_name
, department_name)
VALUES ( /* employee.employeeId */0
, <error descr="Bind variables must be followed by test data">/* employee.employeeName */</error>
, <error descr="Bind variables must be followed by test data">/* employee.department */</error>)
, <error descr="Test data is required after a bind variable directive or a literal variable directive">/* employee.employeeName */</error>
, <error descr="Test data is required after a bind variable directive or a literal variable directive">/* employee.department */</error>)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SELECT e.employee_id AS employeeId
*/
FROM employee e
/*%! This comment will be removed */
WHERE e.employee_id = <error descr="Bind variables must be followed by test data">/*^ id */</error>
WHERE e.employee_id = <error descr="Test data is required after a bind variable directive or a literal variable directive">/*^ id */</error>
AND e.age >= /*^ literalAge */99
AND e.sub_id IN /* subIds */(1, 2, 3)
AND e.sub_id IN /* subIds */(true, False, NULL)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
SELECT *
FROM employee
WHERE join_at <= <error descr="Bind variables must be followed by test data">/* referenceDate */</error>
WHERE join_at <= <error descr="Test data is required after a bind variable directive or a literal variable directive">/* referenceDate */</error>
/*%for project : projects */
employee_name LIKE /* project.projectName */'hoge'
/*%if project_has_next */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ INSERT INTO employee
, department_name)
VALUES ( /* employee.employeeId */0
, /* employee.employeeName */'name'
, <error descr="Bind variables must be followed by test data">/* employee.department */</error>department)
, <error descr="Test data is required after a bind variable directive or a literal variable directive">/* employee.department */</error>department)
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <error descr="Bind variables must be followed by test data">/*^ literalId */</error>
AND e.employee_name = <error descr="Bind variables must be followed by test data">/*^ literalName */</error>
WHERE e.employee_id = <error descr="Test data is required after a bind variable directive or a literal variable directive">/*^ literalId */</error>
AND e.employee_name = <error descr="Test data is required after a bind variable directive or a literal variable directive">/*^ literalName */</error>
AND e.age >= /*^ literalAge */99
AND e.use = /* literalTrue */TRUE
AND e.use = /* literalFalse */false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
UPDATE employee
SET /*%populate*/id = id
WHERE rank < <error descr="Bind variables must be followed by test data">/* emplotee.rank */</error>
WHERE rank < <error descr="Test data is required after a bind variable directive or a literal variable directive">/* emplotee.rank */</error>
Empty file.