Skip to content

Commit a48cc76

Browse files
committed
Implement separately the logic for retrieving static method errors and the logic for fetching the most recently analyzed item.
1 parent 9ee1fb7 commit a48cc76

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/processor/InspectionFieldAccessVisitorProcessor.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class InspectionFieldAccessVisitorProcessor(
6666
when (val topElementClass = resolveTopElementType(targetFile)) {
6767
is DummyPsiParentClass, null -> null
6868

69-
else -> getFieldAccess(topElementClass)?.parentClass?.type
69+
else -> getLastFieldAccess(topElementClass).type
7070
}
7171

7272
private fun resolveTopElementType(file: PsiFile): PsiParentClass? {
@@ -156,6 +156,22 @@ class InspectionFieldAccessVisitorProcessor(
156156
isBatchAnnotation = isBatchAnnotation,
157157
)
158158

159+
private fun getLastFieldAccess(topElementClass: PsiParentClass): PsiParentClass {
160+
var findLastTypeParent = topElementClass
161+
ForDirectiveUtil.getFieldAccessLastPropertyClassType(
162+
blockElements,
163+
project,
164+
topElementClass,
165+
shortName = this.shortName,
166+
isBatchAnnotation = isBatchAnnotation,
167+
findFieldMethod = { type ->
168+
findLastTypeParent = PsiParentClass(type)
169+
findLastTypeParent
170+
},
171+
)
172+
return findLastTypeParent
173+
}
174+
159175
private fun extractFieldAccessBlocks(element: SqlElFieldAccessExpr): List<SqlElIdExpr> {
160176
val accessElements = element.accessElements
161177
val primaryElement = accessElements.firstOrNull() as? SqlElPrimaryExpr ?: return emptyList()

src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/processor/InspectionStaticFieldAccessVisitorProcessor.kt

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.domaframework.doma.intellij.common.psi.PsiStaticElement
2424
import org.domaframework.doma.intellij.common.util.ForDirectiveUtil
2525
import org.domaframework.doma.intellij.common.validation.result.ValidationClassPathResult
2626
import org.domaframework.doma.intellij.common.validation.result.ValidationNotFoundStaticPropertyResult
27+
import org.domaframework.doma.intellij.common.validation.result.ValidationPropertyResult
2728
import org.domaframework.doma.intellij.common.validation.result.ValidationResult
2829
import org.domaframework.doma.intellij.extension.expr.accessElements
2930
import org.domaframework.doma.intellij.psi.SqlElStaticFieldAccessExpr
@@ -49,7 +50,11 @@ class InspectionStaticFieldAccessVisitorProcessor(
4950
resolveTopParentClass(staticAccessor, referenceClass, shortName)
5051
when (topParentClass.first) {
5152
is DummyPsiParentClass -> {
52-
topParentClass.second?.highlightElement(holder)
53+
if (topParentClass.second is ValidationPropertyResult) {
54+
highlightPropertyNotFoundError(staticAccessor, holder)
55+
} else {
56+
topParentClass.second?.highlightElement(holder)
57+
}
5358
return
5459
}
5560
null -> {
@@ -115,7 +120,7 @@ class InspectionStaticFieldAccessVisitorProcessor(
115120
blockElements.firstOrNull()?.let { firstElement ->
116121
ValidationNotFoundStaticPropertyResult(
117122
firstElement,
118-
staticAccessor.elClass,
123+
staticAccessor.elClass.text,
119124
shortName,
120125
).highlightElement(holder)
121126
}
@@ -136,20 +141,41 @@ class InspectionStaticFieldAccessVisitorProcessor(
136141
}
137142
val parent: PsiParentClass = topParentClass.first ?: return null
138143

139-
val result = checkFieldAccessValidity(staticAccessor, parent)
140-
return result?.parentClass?.type
144+
val result = getStaticFieldAccessLastProperty(staticAccessor, parent)
145+
return result.type
141146
}
142147

143148
private fun checkFieldAccessValidity(
144149
staticAccessor: SqlElStaticFieldAccessExpr,
145150
topParentClass: PsiParentClass,
146151
): ValidationResult? {
147152
val blockElements = staticAccessor.accessElements
148-
return ForDirectiveUtil.getFieldAccessLastPropertyClassType(
153+
val result =
154+
ForDirectiveUtil.getFieldAccessLastPropertyClassType(
155+
blockElements,
156+
staticAccessor.project,
157+
topParentClass,
158+
shortName = shortName,
159+
)
160+
return result
161+
}
162+
163+
private fun getStaticFieldAccessLastProperty(
164+
staticAccessor: SqlElStaticFieldAccessExpr,
165+
topParentClass: PsiParentClass,
166+
): PsiParentClass {
167+
val blockElements = staticAccessor.accessElements
168+
var findLastTypeParent = topParentClass
169+
ForDirectiveUtil.getFieldAccessLastPropertyClassType(
149170
blockElements,
150171
staticAccessor.project,
151172
topParentClass,
152173
shortName = shortName,
174+
findFieldMethod = { type ->
175+
findLastTypeParent = PsiParentClass(type)
176+
findLastTypeParent
177+
},
153178
)
179+
return findLastTypeParent
154180
}
155181
}

0 commit comments

Comments
 (0)