Skip to content

Commit d2a5782

Browse files
committed
Refactor: Split inspection logic
1 parent 7728471 commit d2a5782

File tree

15 files changed

+293
-22
lines changed

15 files changed

+293
-22
lines changed

src/main/kotlin/org/domaframework/doma/intellij/inspection/dao/inspector/DaoMethodVariableInspector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class DaoMethodVariableInspector : AbstractBaseJavaLocalInspectionTool() {
5353
val deplicateForItemElements: List<PsiParameter>,
5454
)
5555

56-
override fun getDisplayName(): String = "Method argument usage check"
56+
override fun getDisplayName(): String = "Check usage of DAO method arguments in corresponding SQL file."
5757

5858
override fun getShortName(): String = "org.domaframework.doma.intellij.variablechecker"
5959

src/main/kotlin/org/domaframework/doma/intellij/inspection/dao/inspector/SqlFileExistInspector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import org.domaframework.doma.intellij.inspection.dao.quickfix.GenerateSQLFileQu
3232
* Check for existence of SQL file
3333
*/
3434
class SqlFileExistInspector : AbstractBaseJavaLocalInspectionTool() {
35-
override fun getDisplayName(): String = "Check for existence of SQL file"
35+
override fun getDisplayName(): String = "Ensure the existence of SQL files for DAO methods."
3636

3737
override fun getShortName(): String = "org.domaframework.doma.intellij.existsqlchecker"
3838

src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/inspector/SqlBindVariableValidInspector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import org.domaframework.doma.intellij.psi.SqlVisitor
2525
* Code inspection for SQL bind variables
2626
*/
2727
class SqlBindVariableValidInspector : LocalInspectionTool() {
28-
override fun getDisplayName(): String = "Match checking between SQL bind variables and Declaration"
28+
override fun getDisplayName(): String = "Check where SQL bind variables are defined."
2929

3030
override fun getShortName(): String = "org.domaframework.doma.intellij.validBindVariable"
3131

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.inspection.sql.inspector
17+
18+
import com.intellij.codeHighlighting.HighlightDisplayLevel
19+
import com.intellij.codeInspection.LocalInspectionTool
20+
import com.intellij.codeInspection.ProblemsHolder
21+
import org.domaframework.doma.intellij.inspection.sql.visitor.SqlFunctionCallVisitor
22+
import org.domaframework.doma.intellij.psi.SqlVisitor
23+
24+
class SqlFunctionCallInspector : LocalInspectionTool() {
25+
override fun getDisplayName(): String =
26+
"This inspection checks whether the function name called " +
27+
"in a function call is defined in the implementation class specified " +
28+
"by the `doma.expr.functions` property of doma.compile.config," +
29+
" or in org.seasar.doma.expr.ExpressionFunctions."
30+
31+
override fun getShortName(): String = "org.domaframework.doma.intellij.functionCall"
32+
33+
override fun getGroupDisplayName(): String = "DomaTools"
34+
35+
override fun isEnabledByDefault(): Boolean = true
36+
37+
override fun getDefaultLevel(): HighlightDisplayLevel = HighlightDisplayLevel.Companion.ERROR
38+
39+
override fun runForWholeFile(): Boolean = true
40+
41+
override fun buildVisitor(
42+
holder: ProblemsHolder,
43+
isOnTheFly: Boolean,
44+
): SqlVisitor = SqlFunctionCallVisitor(holder, this.shortName)
45+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.inspection.sql.inspector
17+
18+
import com.intellij.codeHighlighting.HighlightDisplayLevel
19+
import com.intellij.codeInspection.LocalInspectionTool
20+
import com.intellij.codeInspection.ProblemsHolder
21+
import org.domaframework.doma.intellij.inspection.sql.visitor.SqlLoopDirectiveVisitor
22+
import org.domaframework.doma.intellij.psi.SqlVisitor
23+
24+
class SqlLoopDirectiveTypeInspector : LocalInspectionTool() {
25+
override fun getDisplayName(): String =
26+
"This inspection checks whether the base type of the element defined in a loop directive is of an Iterable type."
27+
28+
override fun getShortName(): String = "org.domaframework.doma.intellij.loopDirectiveType"
29+
30+
override fun getGroupDisplayName(): String = "DomaTools"
31+
32+
override fun isEnabledByDefault(): Boolean = true
33+
34+
override fun getDefaultLevel(): HighlightDisplayLevel = HighlightDisplayLevel.Companion.ERROR
35+
36+
override fun runForWholeFile(): Boolean = true
37+
38+
override fun buildVisitor(
39+
holder: ProblemsHolder,
40+
isOnTheFly: Boolean,
41+
): SqlVisitor = SqlLoopDirectiveVisitor(holder, this.shortName)
42+
}

src/main/kotlin/org/domaframework/doma/intellij/inspection/sql/inspector/SqlTestDataAfterBlockCommentValidValidInspector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import org.domaframework.doma.intellij.psi.SqlVisitor
2525
* Code inspection for SQL bind variables
2626
*/
2727
class SqlTestDataAfterBlockCommentValidValidInspector : LocalInspectionTool() {
28-
override fun getDisplayName(): String = "Check whether test data exists after the bind variable"
28+
override fun getDisplayName(): String = "Verify the presence of test data after SQL bind variables"
2929

3030
override fun getShortName(): String = "org.domaframework.doma.intellij.existaftertestdata"
3131

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.inspection.sql.provider
17+
18+
import com.intellij.codeInspection.InspectionToolProvider
19+
import com.intellij.codeInspection.LocalInspectionTool
20+
import org.domaframework.doma.intellij.inspection.sql.inspector.SqlFunctionCallInspector
21+
22+
class SqlFunctionCallProvider : InspectionToolProvider {
23+
override fun getInspectionClasses(): Array<Class<out LocalInspectionTool>> =
24+
arrayOf(
25+
SqlFunctionCallInspector::class.java,
26+
)
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.inspection.sql.provider
17+
18+
import com.intellij.codeInspection.InspectionToolProvider
19+
import com.intellij.codeInspection.LocalInspectionTool
20+
import org.domaframework.doma.intellij.inspection.sql.inspector.SqlLoopDirectiveTypeInspector
21+
22+
class SqlLoopDirectiveTypeProvider : InspectionToolProvider {
23+
override fun getInspectionClasses(): Array<Class<out LocalInspectionTool>> =
24+
arrayOf(
25+
SqlLoopDirectiveTypeInspector::class.java,
26+
)
27+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.inspection.sql.visitor
17+
18+
import com.intellij.codeInspection.ProblemsHolder
19+
import com.intellij.psi.PsiElement
20+
import com.intellij.psi.PsiLiteralExpression
21+
import org.domaframework.doma.intellij.common.isInjectionSqlFile
22+
import org.domaframework.doma.intellij.common.isJavaOrKotlinFileType
23+
import org.domaframework.doma.intellij.inspection.sql.processor.InspectionFunctionCallVisitorProcessor
24+
import org.domaframework.doma.intellij.psi.SqlElFunctionCallExpr
25+
26+
class SqlFunctionCallVisitor(
27+
private val holder: ProblemsHolder,
28+
private val shortName: String,
29+
) : SqlVisitorBase() {
30+
override fun visitElement(element: PsiElement) {
31+
val file = element.containingFile ?: return
32+
if (isJavaOrKotlinFileType(file) && element is PsiLiteralExpression) {
33+
val injectionFile = initInjectionElement(file, element.project, element) ?: return
34+
injectionFile.accept(this)
35+
super.visitElement(element)
36+
}
37+
if (isInjectionSqlFile(file)) {
38+
element.acceptChildren(this)
39+
}
40+
}
41+
42+
override fun visitElFunctionCallExpr(element: SqlElFunctionCallExpr) {
43+
super.visitElFunctionCallExpr(element)
44+
val processor = InspectionFunctionCallVisitorProcessor(this.shortName, element)
45+
processor.check(holder)
46+
}
47+
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,9 @@ import org.domaframework.doma.intellij.common.isInjectionSqlFile
2323
import org.domaframework.doma.intellij.common.isJavaOrKotlinFileType
2424
import org.domaframework.doma.intellij.extension.psi.isFirstElement
2525
import org.domaframework.doma.intellij.inspection.sql.processor.InspectionFieldAccessVisitorProcessor
26-
import org.domaframework.doma.intellij.inspection.sql.processor.InspectionForDirectiveVisitorProcessor
27-
import org.domaframework.doma.intellij.inspection.sql.processor.InspectionFunctionCallVisitorProcessor
2826
import org.domaframework.doma.intellij.inspection.sql.processor.InspectionPrimaryVisitorProcessor
2927
import org.domaframework.doma.intellij.inspection.sql.processor.InspectionStaticFieldAccessVisitorProcessor
3028
import org.domaframework.doma.intellij.psi.SqlElFieldAccessExpr
31-
import org.domaframework.doma.intellij.psi.SqlElForDirective
32-
import org.domaframework.doma.intellij.psi.SqlElFunctionCallExpr
3329
import org.domaframework.doma.intellij.psi.SqlElPrimaryExpr
3430
import org.domaframework.doma.intellij.psi.SqlElStaticFieldAccessExpr
3531
import org.domaframework.doma.intellij.psi.SqlTypes
@@ -50,12 +46,6 @@ class SqlInspectionVisitor(
5046
}
5147
}
5248

53-
override fun visitElFunctionCallExpr(element: SqlElFunctionCallExpr) {
54-
super.visitElFunctionCallExpr(element)
55-
val processor = InspectionFunctionCallVisitorProcessor(this.shortName, element)
56-
processor.check(holder)
57-
}
58-
5949
override fun visitElStaticFieldAccessExpr(element: SqlElStaticFieldAccessExpr) {
6050
super.visitElStaticFieldAccessExpr(element)
6151
val processor = InspectionStaticFieldAccessVisitorProcessor(this.shortName)
@@ -69,12 +59,6 @@ class SqlInspectionVisitor(
6959
processor.check(holder, file)
7060
}
7161

72-
override fun visitElForDirective(element: SqlElForDirective) {
73-
super.visitElForDirective(element)
74-
val process = InspectionForDirectiveVisitorProcessor(shortName, element)
75-
process.check(holder)
76-
}
77-
7862
override fun visitElPrimaryExpr(element: SqlElPrimaryExpr) {
7963
val file = element.containingFile ?: return
8064
if (!element.isFirstElement() || element.prevSibling?.elementType == SqlTypes.AT_SIGN) return

0 commit comments

Comments
 (0)