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 @@ -21,9 +21,10 @@ import com.intellij.psi.PsiElement
import org.domaframework.doma.intellij.bundle.MessageBundle
import org.domaframework.doma.intellij.common.psi.PsiParentClass

class ValidationMethodParamEntityResult(
class ValidationMethodParamTypeResult(
override val identify: PsiElement?,
override val shortName: String = "",
private val typeName: String,
) : ValidationResult(identify, null, shortName) {
override fun setHighlight(
highlightRange: TextRange,
Expand All @@ -34,7 +35,7 @@ class ValidationMethodParamEntityResult(
val project = identify.project
holder.registerProblem(
identify,
MessageBundle.message("inspection.invalid.dao.params.entity"),
MessageBundle.message("inspection.invalid.dao.params.type", typeName),
problemHighlightType(project, shortName),
highlightRange,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ enum class DomaAnnotationType(
Insert("org.seasar.doma.Insert"),
Update("org.seasar.doma.Update"),
Delete("org.seasar.doma.Delete"),
ArrayFactory("org.seasar.doma.ArrayFactory"),
BlobFactory("org.seasar.doma.BlobFactory"),
ClobFactory("org.seasar.doma.ClobFactory"),
NClobFactory("org.seasar.doma.NClobFactory"),
SQLXMLFactory("org.seasar.doma.SQLXMLFactory"),
Sql("org.seasar.doma.Sql"),
Unknown("Unknown"),
;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Doma Tools Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.domaframework.doma.intellij.inspection.dao.processor

enum class FactoryAnnotationType(
val fqdn: String,
val returnType: String,
val paramCount: Int = 0,
) {
ArrayFactory("org.seasar.doma.ArrayFactory", "java.sql.Array", 1),
BlobFactory("org.seasar.doma.BlobFactory", "java.sql.Blob"),
ClobFactory("org.seasar.doma.ClobFactory", "java.sql.Clob"),
NClobFactory("org.seasar.doma.NClobFactory", "java.sql.NClob"),
SQLXMLFactory("org.seasar.doma.SQLXMLFactory", "java.sql.SQLXML"),
;

fun matchFactoryAnnotation(fqName: String): Boolean = this.fqdn == fqName
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright Doma Tools Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.domaframework.doma.intellij.inspection.dao.processor.paramtype

import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.PsiArrayType
import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodParamTypeResult
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodParamsCountResult
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodParamsEmptyResult
import org.domaframework.doma.intellij.inspection.dao.processor.FactoryAnnotationType

class FactoryParamTypeCheckProcessor(
private val psiDaoMethod: PsiDaoMethod,
private val shortName: String,
) : ParamTypeCheckProcessor(psiDaoMethod, shortName) {
override fun checkParams(holder: ProblemsHolder) {
val daoType = psiDaoMethod.daoType
val factoryAnnotationType =
FactoryAnnotationType.entries.find { annotation ->
annotation.matchFactoryAnnotation(daoType.fqdn)
} ?: return

val params = method.parameterList.parameters
if (factoryAnnotationType.paramCount != params.size) {
val paramCountResult =
when (factoryAnnotationType) {
FactoryAnnotationType.ArrayFactory ->
ValidationMethodParamsCountResult(
method.nameIdentifier,
shortName,
)

else ->
ValidationMethodParamsEmptyResult(
method.nameIdentifier,
shortName,
)
}
paramCountResult.highlightElement(holder)
return
}

if (factoryAnnotationType == FactoryAnnotationType.ArrayFactory) {
val arrayParam = params.firstOrNull() ?: return
if (arrayParam.type !is PsiArrayType) {
ValidationMethodParamTypeResult(
arrayParam.nameIdentifier ?: return,
shortName,
"an array type",
).highlightElement(holder)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package org.domaframework.doma.intellij.inspection.dao.processor.paramtype

import com.intellij.codeInspection.ProblemsHolder
import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodParamEntityResult
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodParamTypeResult
import org.domaframework.doma.intellij.extension.getJavaClazz
import org.domaframework.doma.intellij.extension.psi.isEntity

Expand Down Expand Up @@ -61,9 +61,10 @@ class UpdateParamTypeCheckProcessor(
val paramClass = project.getJavaClazz(param?.type?.canonicalText ?: "")
val identifier = param?.nameIdentifier ?: return
if (paramClass == null || !paramClass.isEntity()) {
ValidationMethodParamEntityResult(
ValidationMethodParamTypeResult(
identifier,
shortName,
"an entity",
).highlightElement(holder)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.domaframework.doma.intellij.extension.getJavaClazz
* @property psiDaoMethod The target DAO method info to be checked.
* @property shortName The short name of inspection to check.
*/
class BatchAnnotationReturnTypeCheckProcessor(
class BatchReturnTypeCheckProcessor(
private val psiDaoMethod: PsiDaoMethod,
private val shortName: String,
) : ReturnTypeCheckerProcessor(psiDaoMethod, shortName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Doma Tools Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.domaframework.doma.intellij.inspection.dao.processor.returntype

import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
import org.domaframework.doma.intellij.common.validation.result.ValidationResult
import org.domaframework.doma.intellij.common.validation.result.ValidationReturnTypeResult
import org.domaframework.doma.intellij.inspection.dao.processor.FactoryAnnotationType

/**
* Processor for checking the return type of SqlProcessor annotation.
*
* @param psiDaoMethod The target DAO method info to be checked.
* @param shortName The short name of the inspection to check.
*/
class FactoryReturnTypeCheckProcessor(
private val psiDaoMethod: PsiDaoMethod,
private val shortName: String,
) : ReturnTypeCheckerProcessor(psiDaoMethod, shortName) {
override fun checkReturnType(): ValidationResult? {
val daoType = psiDaoMethod.daoType
val factoryAnnotationType =
FactoryAnnotationType.entries.find { annotation ->
annotation.matchFactoryAnnotation(daoType.fqdn)
} ?: return null

val returnTypeResult =
ValidationReturnTypeResult(
method.nameIdentifier,
shortName,
factoryAnnotationType.returnType,
)

val returnType = method.returnType
return if (returnType?.canonicalText != factoryAnnotationType.returnType) {
returnTypeResult
} else {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.domaframework.doma.intellij.extension.getJavaClazz
import org.domaframework.doma.intellij.extension.psi.isDomain
import org.domaframework.doma.intellij.extension.psi.isEntity

class FunctionAnnotationReturnTypeCheckProcessor(
class FunctionReturnTypeCheckProcessor(
psiDaoMethod: PsiDaoMethod,
private val shortName: String,
) : ReturnTypeCheckerProcessor(psiDaoMethod, shortName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import org.domaframework.doma.intellij.extension.psi.DomaAnnotationType
* @property psiDaoMethod The target DAO method info to be checked.
* @property shortName The short name of the inspection to check.
*/
class MultiInsertAnnotationReturnTypeCheckProcessor(
class MultiInsertReturnTypeCheckProcessor(
private val psiDaoMethod: PsiDaoMethod,
private val shortName: String,
) : ReturnTypeCheckerProcessor(psiDaoMethod, shortName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.intellij.psi.PsiTypes
import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
import org.domaframework.doma.intellij.common.validation.result.ValidationResult

class ScriptAnnotationReturnTypeCheckProcessor(
class ProcedureReturnTypeCheckProcessor(
psiDaoMethod: PsiDaoMethod,
shortName: String,
) : ReturnTypeCheckerProcessor(psiDaoMethod, shortName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.intellij.psi.PsiTypes
import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
import org.domaframework.doma.intellij.common.validation.result.ValidationResult

class ProcedureAnnotationReturnTypeCheckProcessor(
class ScriptReturnTypeCheckProcessor(
psiDaoMethod: PsiDaoMethod,
shortName: String,
) : ReturnTypeCheckerProcessor(psiDaoMethod, shortName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.domaframework.doma.intellij.extension.psi.isDomain
import org.domaframework.doma.intellij.extension.psi.isEntity
import org.domaframework.doma.intellij.inspection.dao.processor.StrategyParam

class SelectAnnotationReturnTypeCheckProcessor(
class SelectReturnTypeCheckProcessor(
private val psiDaoMethod: PsiDaoMethod,
private val shortName: String,
) : ReturnTypeCheckerProcessor(psiDaoMethod, shortName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.domaframework.doma.intellij.common.validation.result.ValidationSqlPro
* @param psiDaoMethod The target DAO method info to be checked.
* @param shortName The short name of the inspection to check.
*/
class SqlProcessorAnnotationReturnTypeCheckProcessor(
class SqlProcessorReturnTypeCheckProcessor(
psiDaoMethod: PsiDaoMethod,
private val shortName: String,
) : ReturnTypeCheckerProcessor(psiDaoMethod, shortName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.domaframework.doma.intellij.extension.psi.psiClassType
* @property psiDaoMethod The target DAO method info to be checked.
* @property shortName The short name of inspection.
*/
class UpdateAnnotationReturnTypeCheckProcessor(
class UpdateReturnTypeCheckProcessor(
private val psiDaoMethod: PsiDaoMethod,
private val shortName: String,
) : ReturnTypeCheckerProcessor(psiDaoMethod, shortName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.domaframework.doma.intellij.common.isJavaOrKotlinFileType
import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
import org.domaframework.doma.intellij.extension.psi.DomaAnnotationType
import org.domaframework.doma.intellij.inspection.dao.processor.paramtype.BatchParamTypeCheckProcessor
import org.domaframework.doma.intellij.inspection.dao.processor.paramtype.FactoryParamTypeCheckProcessor
import org.domaframework.doma.intellij.inspection.dao.processor.paramtype.MultiInsertParamTypeCheckProcessor
import org.domaframework.doma.intellij.inspection.dao.processor.paramtype.ParamTypeCheckProcessor
import org.domaframework.doma.intellij.inspection.dao.processor.paramtype.ProcedureParamTypeCheckProcessor
Expand All @@ -47,6 +48,13 @@ class DaoMethodParamTypeInspectionVisitor(

private fun getParamTypeCheckProcessor(psiDaoMethod: PsiDaoMethod): ParamTypeCheckProcessor? =
when (psiDaoMethod.daoType) {
DomaAnnotationType.Select -> {
SelectParamTypeCheckProcessor(
psiDaoMethod,
this.shortName,
)
}

DomaAnnotationType.Insert, DomaAnnotationType.Update, DomaAnnotationType.Delete -> {
UpdateParamTypeCheckProcessor(psiDaoMethod, this.shortName)
}
Expand Down Expand Up @@ -76,12 +84,15 @@ class DaoMethodParamTypeInspectionVisitor(
)
}

DomaAnnotationType.Select -> {
SelectParamTypeCheckProcessor(
DomaAnnotationType.ArrayFactory, DomaAnnotationType.BlobFactory, DomaAnnotationType.ClobFactory,
DomaAnnotationType.NClobFactory, DomaAnnotationType.SQLXMLFactory,
-> {
FactoryParamTypeCheckProcessor(
psiDaoMethod,
this.shortName,
)
}

DomaAnnotationType.Sql, DomaAnnotationType.Unknown -> null
}
}
Loading
Loading