Skip to content

Commit 74320e9

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

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
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 {

0 commit comments

Comments
 (0)