@@ -18,8 +18,10 @@ package org.domaframework.doma.intellij.inspection.dao.processor.option
1818import com.intellij.codeInspection.ProblemsHolder
1919import com.intellij.openapi.project.Project
2020import com.intellij.psi.PsiAnnotation
21+ import com.intellij.psi.PsiAnnotationMemberValue
2122import com.intellij.psi.PsiClass
2223import com.intellij.psi.PsiClassType
24+ import com.intellij.psi.PsiElement
2325import com.intellij.psi.PsiField
2426import com.intellij.psi.PsiLiteralExpression
2527import com.intellij.psi.PsiPrimitiveType
@@ -98,15 +100,9 @@ class DaoAnnotationOptionParameterCheckProcessor(
98100 annotation.parameterList.attributes
99101 .find { it.name == optionName }
100102 ?.value
103+ ? : return
101104
102- val arrayValues =
103- if (expression is PsiLiteralExpression ) {
104- listOf (expression)
105- } else {
106- expression
107- ?.children
108- ?.filter { it is PsiLiteralExpression } ? : return
109- }
105+ val arrayValues = extractArrayValues(expression)
110106 if (arrayValues.isEmpty()) return
111107
112108 val project = method.project
@@ -121,6 +117,8 @@ class DaoAnnotationOptionParameterCheckProcessor(
121117 searchParamClass
122118 ?.fields
123119 ?.find { property -> isOptionTargetProperty(property, field, project) }
120+ // Given that the first `searchParamType` is assumed to contain the type of Entity class,
121+ // checking the index for a primitive type is unnecessary.
124122 if (searchParamType is PsiPrimitiveType ) {
125123 // This is a primitive/basic type but there are more fields after it
126124 ValidationAnnotationOptionPrimitiveFieldResult (
@@ -164,6 +162,15 @@ class DaoAnnotationOptionParameterCheckProcessor(
164162 }
165163 }
166164
165+ private fun extractArrayValues (expression : PsiAnnotationMemberValue ): List <PsiElement > =
166+ if (expression is PsiLiteralExpression ) {
167+ listOf (expression)
168+ } else {
169+ expression
170+ .children
171+ .filter { it is PsiLiteralExpression }
172+ }
173+
167174 private fun getTargetOptionProperties (paramClass : PsiClass ? ) =
168175 paramClass?.fields?.filter { isOptionTargetProperty(it, it.name, project) }?.joinToString(" , " ) { it.name.substringAfter(" :" ) }
169176 ? : " No fields found"
0 commit comments