Skip to content

Commit 44b293d

Browse files
committed
Add ValidationClassPathResult for handling non-existent package or class
1 parent 1bf5898 commit 44b293d

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.sql.validator.result
17+
18+
import com.intellij.codeInspection.ProblemsHolder
19+
import com.intellij.openapi.project.Project
20+
import com.intellij.openapi.util.TextRange
21+
import com.intellij.psi.PsiElement
22+
import org.domaframework.doma.intellij.bundle.MessageBundle
23+
import org.domaframework.doma.intellij.common.psi.PsiParentClass
24+
25+
/**
26+
* Non-existent package name or class
27+
*/
28+
open class ValidationClassPathResult(
29+
override val identify: PsiElement,
30+
override val shortName: String,
31+
) : ValidationResult(identify, null, shortName) {
32+
override fun setHighlight(
33+
highlightRange: TextRange,
34+
identify: PsiElement,
35+
holder: ProblemsHolder,
36+
parent: PsiParentClass?,
37+
project: Project,
38+
) {
39+
val project = identify.project
40+
holder.registerProblem(
41+
identify,
42+
MessageBundle.message(
43+
"inspection.invalid.sql.classpath",
44+
identify.text ?: "",
45+
),
46+
problemHighlightType(project, shortName),
47+
highlightRange,
48+
)
49+
}
50+
}

src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/visitor/SqlInspectionVisitor.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
2929
import org.domaframework.doma.intellij.common.psi.PsiParentClass
3030
import org.domaframework.doma.intellij.common.psi.PsiStaticElement
3131
import org.domaframework.doma.intellij.common.sql.cleanString
32+
import org.domaframework.doma.intellij.common.sql.validator.result.ValidationClassPathResult
3233
import org.domaframework.doma.intellij.common.sql.validator.result.ValidationDaoParamResult
3334
import org.domaframework.doma.intellij.common.sql.validator.result.ValidationPropertyResult
3435
import org.domaframework.doma.intellij.common.util.ForDirectiveUtil
@@ -178,7 +179,15 @@ class SqlInspectionVisitor(
178179
) {
179180
val blockElements = staticAccuser.accessElements
180181
val psiStaticClass = PsiStaticElement(staticAccuser.elClass.elIdExprList, staticAccuser.containingFile)
181-
val referenceClass = psiStaticClass.getRefClazz() ?: return
182+
val referenceClass = psiStaticClass.getRefClazz()
183+
if (referenceClass == null) {
184+
ValidationClassPathResult(
185+
staticAccuser.elClass,
186+
this.shortName,
187+
).highlightElement(holder)
188+
return
189+
}
190+
182191
val topParentClass = ForDirectiveUtil.getStaticFieldAccessTopElementClassType(staticAccuser, referenceClass)
183192
if (topParentClass == null) {
184193
blockElements.firstOrNull()?.let {

src/main/resources/messages/DomaToolsBundle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ inspector.invalid.class.property=The field or method [{1}] does not exist in the
66
inspection.dao.method.variable.error=There are unused parameters in the SQL [{0}]
77
inspector.invalid.dao.parameter=The bind variable [{1}] does not exist in the Dao method [{0}]
88
config.enable.sql.format=Enable SQL Format
9-
inspection.invalid.sql.testdata=Bind variables must be followed by test data
9+
inspection.invalid.sql.testdata=Bind variables must be followed by test data
10+
inspection.invalid.sql.classpath=A non-existent package or class name was specified. [{0}]

src/main/resources/messages/DomaToolsBundle_ja.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ inspector.invalid.class.property=\u30AF\u30E9\u30B9[{0}]\u306B\u5B58\u5728\u3057
66
inspection.dao.method.variable.error=SQL\u3067\u4F7F\u7528\u3055\u308C\u3066\u3044\u306A\u3044\u5F15\u6570\u304C\u3042\u308A\u307E\u3059[{0}]
77
inspector.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}]
88
config.enable.sql.format=SQL\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8\u3092\u6709\u52B9\u5316
9-
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
9+
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
10+
inspection.invalid.sql.classpath=\u0041\u0020\u006E\u006F\u006E\u002D\u0065\u0078\u0069\u0073\u0074\u0065\u006E\u0074\u0020\u0070\u0061\u0063\u006B\u0061\u0067\u0065\u0020\u006F\u0072\u0020\u0063\u006C\u0061\u0073\u0073\u0020\u006E\u0061\u006D\u0065\u0020\u0077\u0061\u0073\u0020\u0073\u0070\u0065\u0063\u0069\u0066\u0069\u0065\u0064\u002E [{0}]

0 commit comments

Comments
 (0)