Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package org.domaframework.doma.intellij.inspection.sql.visitor

import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiLiteralExpression
import com.intellij.psi.util.elementType
import org.domaframework.doma.intellij.common.isInjectionSqlFile
Expand All @@ -38,14 +37,13 @@ class SqlInspectionVisitor(
private val shortName: String,
) : SqlVisitorBase() {
override fun visitElement(element: PsiElement) {
if (setFile(element)) return
val visitFile: PsiFile = file ?: return
if (isJavaOrKotlinFileType(visitFile) && element is PsiLiteralExpression) {
val injectionFile = initInjectionElement(visitFile, element.project, element) ?: return
val file = element.containingFile ?: return
if (isJavaOrKotlinFileType(file) && element is PsiLiteralExpression) {
val injectionFile = initInjectionElement(file, element.project, element) ?: return
injectionFile.accept(this)
super.visitElement(element)
}
if (isInjectionSqlFile(visitFile)) {
if (isInjectionSqlFile(file)) {
element.acceptChildren(this)
}
}
Expand All @@ -58,11 +56,9 @@ class SqlInspectionVisitor(

override fun visitElFieldAccessExpr(element: SqlElFieldAccessExpr) {
super.visitElFieldAccessExpr(element)
if (setFile(element)) return
val visitFile: PsiFile = file ?: return

val file = element.containingFile ?: return
val processor = InspectionFieldAccessVisitorProcessor(shortName, element)
processor.check(holder, visitFile)
processor.check(holder, file)
}

override fun visitElForDirective(element: SqlElForDirective) {
Expand All @@ -72,12 +68,10 @@ class SqlInspectionVisitor(
}

override fun visitElPrimaryExpr(element: SqlElPrimaryExpr) {
super.visitElPrimaryExpr(element)
val file = element.containingFile ?: return
if (!element.isFirstElement() || element.prevSibling?.elementType == SqlTypes.AT_SIGN) return
if (setFile(element)) return
val visitFile: PsiFile = file ?: return

val processor = InspectionPrimaryVisitorProcessor(this.shortName, element)
processor.check(holder, visitFile)
processor.check(holder, file)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package org.domaframework.doma.intellij.inspection.sql.visitor
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiLiteralExpression
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.util.nextLeafs
Expand All @@ -37,14 +36,13 @@ class SqlTestDataAfterBlockCommentVisitor(
private val shortName: String,
) : SqlVisitorBase() {
override fun visitElement(element: PsiElement) {
if (setFile(element)) return
val visitFile: PsiFile = file ?: return
if (isJavaOrKotlinFileType(visitFile) && element is PsiLiteralExpression) {
val injectionFile = initInjectionElement(visitFile, element.project, element) ?: return
val file = element.containingFile ?: return
if (isJavaOrKotlinFileType(file) && element is PsiLiteralExpression) {
val injectionFile = initInjectionElement(file, element.project, element) ?: return
injectionFile.accept(this)
super.visitElement(element)
}
if (isInjectionSqlFile(visitFile)) {
if (isInjectionSqlFile(file)) {
element.acceptChildren(this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,12 @@ package org.domaframework.doma.intellij.inspection.sql.visitor

import com.intellij.lang.injection.InjectedLanguageManager
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiLiteralExpression
import org.domaframework.doma.intellij.common.isJavaOrKotlinFileType
import org.domaframework.doma.intellij.psi.SqlVisitor

open class SqlVisitorBase : SqlVisitor() {
var file: PsiFile? = null

protected fun setFile(element: PsiElement): Boolean {
if (file == null) {
file = element.containingFile
}
return false
}

/**
* For processing inside Sql annotations, get it as an injected custom language
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package doma.example.dao.inspection;

import doma.example.entity.*:
import doma.example.entity.*;
import org.seasar.doma.*;
import org.seasar.doma.jdbc.Config;
import org.seasar.doma.jdbc.PreparedSql;
Expand Down