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
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@ import org.domaframework.doma.intellij.common.psi.PsiParentClass
class ValidationTestDataResult(
override val identify: PsiElement?,
override val shortName: String = "",
private val expand: Boolean,
) : ValidationResult(identify, null, shortName) {
override fun setHighlight(
highlightRange: TextRange,
identify: PsiElement,
holder: ProblemsHolder,
parent: PsiParentClass?,
) {
val message =
if (expand) {
MessageBundle.message("inspection.invalid.sql.expand")
} else {
MessageBundle.message("inspection.invalid.sql.testdata")
}
val project = identify.project
holder.registerProblem(
identify,
MessageBundle.message("inspection.invalid.sql.testdata"),
message,
problemHighlightType(project, shortName),
highlightRange,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ class SqlTestDataInspectionVisitor(
super.visitBlockComment(element)
if (hasOtherBindVariable(element)) return

val result = ValidationTestDataResult(element, shortName)
val nextElement = element.nextSibling
val expand = isExpand(element)
val result = ValidationTestDataResult(element, shortName, expand)

if (expand) {
if (!checkExpandDirective(nextElement)) result.highlightElement(holder)
return
}

if (nextElement == null) {
result.highlightElement(holder)
return
}

if (isSqlLiteral(nextElement)) return
if (isMatchListTestData(element)) return

Expand Down Expand Up @@ -91,6 +99,11 @@ class SqlTestDataInspectionVisitor(
listOf("true", "false", "null").contains(element.text.lowercase()) ||
element.text.matches(Regex("^\\d+$"))

private fun isExpand(element: PsiElement): Boolean =
PsiTreeUtil.getChildOfType(element, PsiElement::class.java)?.nextSibling?.elementType == SqlTypes.EL_EXPAND

private fun checkExpandDirective(element: PsiElement): Boolean = element.elementType == SqlTypes.ASTERISK

/**
* Determines if the given element matches the pattern for "List type test data."
*
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/DomaToolsBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ inspection.invalid.dao.parameter=The bind variable [{1}] does not exist in the D
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=Test data is required after a bind variable directive or a literal variable directive
inspection.invalid.sql.expand=Asterisk is required after expand variable
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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/DomaToolsBundle_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ inspection.invalid.dao.parameter=DAO\u30E1\u30BD\u30C3\u30C9[{0}]\u306B\u5B58\u5
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\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.expand=\u0045\u0078\u0070\u0061\u006E\u0064\u30C7\u30A3\u30EC\u30AF\u30C6\u30A3\u30D6\u306E\u5F8C\u308D\u306B\u306F\u30A2\u30B9\u30BF\u30EA\u30B9\u30AF\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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class TestDataCheckTest : DomaSqlTest() {
"$packageName/$testDaoName/commentBlock.sql",
"$packageName/$testDaoName/populateDirective.sql",
"$packageName/$testDaoName/invalidTestData.sql",
"$packageName/$testDaoName/expandDirective.sql",
"$packageName/$testDaoName/invalidExpandDirective.sql",
)
myFixture.enableInspections(SqlTestDataInspection())
}
Expand Down Expand Up @@ -88,4 +90,22 @@ class TestDataCheckTest : DomaSqlTest() {

myFixture.testHighlighting(false, false, false, sqlFile)
}

fun testExpandDirective() {
val sqlFile =
findSqlFile("$packageName/$testDaoName/expandDirective.sql")
assertNotNull("Not Found SQL File", sqlFile)
if (sqlFile == null) return

myFixture.testHighlighting(false, false, false, sqlFile)
}

fun testInvalidExpandDirective() {
val sqlFile =
findSqlFile("$packageName/$testDaoName/invalidExpandDirective.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
Expand Up @@ -30,5 +30,11 @@ interface TestDataCheckDao {
@Insert(sqlFile=true)
int invalidTestData(Employee employee);

@Select
int expandDirective(Employee employee);

@Select
int invalidExpandDirective(Employee employee);

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT /*%expand*/* FROM employee
WHERE rank < <error descr="Test data is required after a bind variable directive or a literal variable directive">/* employee.rank */</error>*
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT <error descr="Asterisk is required after expand variable">/*%expand*/</error>0 FROM employee
WHERE rank < /* employee.rank */0
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
UPDATE employee
SET /*%populate*/id = id
WHERE rank < <error descr="Test data is required after a bind variable directive or a literal variable directive">/* emplotee.rank */</error>
WHERE rank < <error descr="Test data is required after a bind variable directive or a literal variable directive">/* employee.rank */</error>
Loading