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
@@ -0,0 +1,43 @@
/*
* 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.common.validation.result

import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import org.domaframework.doma.intellij.bundle.MessageBundle
import org.domaframework.doma.intellij.common.psi.PsiParentClass

class ValidationMethodInvalidReturnTypeResult(
override val identify: PsiElement?,
override val shortName: String = "",
private val returnTypeName: String,
) : ValidationResult(identify, null, shortName) {
override fun setHighlight(
highlightRange: TextRange,
identify: PsiElement,
holder: ProblemsHolder,
parent: PsiParentClass?,
) {
val project = identify.project
holder.registerProblem(
identify,
MessageBundle.message("inspection.invalid.dao.returnType.invalid", returnTypeName),
problemHighlightType(project, shortName),
highlightRange,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.intellij.psi.PsiElement
import org.domaframework.doma.intellij.bundle.MessageBundle
import org.domaframework.doma.intellij.common.psi.PsiParentClass

class ValidationMethodProcedureParamsSupportGenericParamResult(
class ValidationMethodParamsSupportGenericParamResult(
override val identify: PsiElement?,
override val shortName: String = "",
private val paramTypeName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import org.domaframework.doma.intellij.common.psi.PsiParentClass
class ValidationMethodSelectStrategyParamResult(
override val identify: PsiElement?,
override val shortName: String = "",
private val selectTypeName: String,
private val requireClassName: String,
private val genericTypeName: String,
private val parentParamTypeName: String,
) : ValidationResult(identify, null, shortName) {
override fun setHighlight(
highlightRange: TextRange,
Expand All @@ -36,7 +36,11 @@ class ValidationMethodSelectStrategyParamResult(
val project = identify.project
holder.registerProblem(
identify,
MessageBundle.message("inspection.invalid.dao.select.param.strategy.require.type", selectTypeName, requireClassName),
MessageBundle.message(
"inspection.invalid.dao.select.param.strategy.require.type",
genericTypeName,
parentParamTypeName,
),
problemHighlightType(project, shortName),
highlightRange,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.common.validation.result

import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import org.domaframework.doma.intellij.bundle.MessageBundle
import org.domaframework.doma.intellij.common.psi.PsiParentClass

class ValidationMethodSelectStrategyReturnTypeResult(
override val identify: PsiElement?,
override val shortName: String = "",
private val resultType: String,
) : ValidationResult(identify, null, shortName) {
override fun setHighlight(
highlightRange: TextRange,
identify: PsiElement,
holder: ProblemsHolder,
parent: PsiParentClass?,
) {
val project = identify.project
holder.registerProblem(
identify,
MessageBundle.message(
"inspection.invalid.dao.select.returnType.strategy",
resultType,
),
problemHighlightType(project, shortName),
highlightRange,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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

import org.domaframework.doma.intellij.common.util.DomaClassName

class StrategyParam(
val fieldName: String = "",
parentClassName: String?,
) {
private val isSelectType: Boolean = parentClassName == DomaClassName.SELECT_TYPE.className

fun isStream(): Boolean = fieldName == "STREAM" && isSelectType

fun isCollect(): Boolean = fieldName == "COLLECT" && isSelectType
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ package org.domaframework.doma.intellij.inspection.dao.processor
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiField
import com.intellij.psi.PsiParameter
import com.intellij.psi.PsiReferenceExpression
import com.intellij.psi.PsiType
import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
import org.domaframework.doma.intellij.common.psi.PsiTypeChecker
import org.domaframework.doma.intellij.common.util.DomaClassName
import org.domaframework.doma.intellij.extension.getJavaClazz
import org.domaframework.doma.intellij.extension.psi.getSuperType
import org.domaframework.doma.intellij.extension.psi.isDomain

abstract class TypeCheckerProcessor(
Expand All @@ -34,6 +36,11 @@ abstract class TypeCheckerProcessor(

protected fun getAnnotation(fqName: String): PsiAnnotation? = method.annotations.find { it.qualifiedName == fqName }

protected fun getMethodParamTargetType(typeName: String): PsiParameter? =
method.parameterList.parameters.find { param ->
(param.type as? PsiClassType)?.getSuperType(typeName) != null
}

protected fun getDaoAnnotationOption(
psiAnnotation: PsiAnnotation,
findOptionName: String,
Expand Down Expand Up @@ -90,6 +97,6 @@ abstract class TypeCheckerProcessor(
DomaClassName.STRING.className,
DomaClassName.OBJECT.className,
).replace(" ", "")
return mapClassName != mapExpectedType
return mapClassName == mapExpectedType
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiType
import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
import org.domaframework.doma.intellij.common.util.DomaClassName
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodParamsSupportGenericParamResult
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodProcedureParamTypeResult
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodProcedureParamsSupportGenericParamResult

class ProcedureFunctionInOutParamAnnotationTypeChecker(
private val annotationType: ProcedureFunctionParamAnnotationType,
Expand All @@ -49,7 +49,7 @@ class ProcedureFunctionInOutParamAnnotationTypeChecker(
// Check if the parameter type is a valid reference type with generic parameters
val referenceParamType = (paramType as? PsiClassType)?.parameters?.firstOrNull()
if (referenceParamType == null) {
ValidationMethodProcedureParamsSupportGenericParamResult(
ValidationMethodParamsSupportGenericParamResult(
identifier,
shortName,
"Unknown",
Expand All @@ -59,7 +59,7 @@ class ProcedureFunctionInOutParamAnnotationTypeChecker(
}

if (checkParamType(referenceParamType)) return
ValidationMethodProcedureParamsSupportGenericParamResult(
ValidationMethodParamsSupportGenericParamResult(
identifier,
shortName,
referenceParamType.canonicalText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import com.intellij.psi.PsiType
import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
import org.domaframework.doma.intellij.common.psi.PsiTypeChecker
import org.domaframework.doma.intellij.common.util.DomaClassName
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodParamsSupportGenericParamResult
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodProcedureParamTypeResult
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodProcedureParamsSupportGenericParamResult
import org.domaframework.doma.intellij.extension.getJavaClazz
import org.domaframework.doma.intellij.extension.psi.isDomain
import org.domaframework.doma.intellij.extension.psi.isEntity
Expand Down Expand Up @@ -77,7 +77,7 @@ class ProcedureFunctionResultSetParamAnnotationTypeChecker(
// Check if the parameter type is a valid List type with generic parameters
val listParamType = (paramType as? PsiClassType)?.parameters?.firstOrNull()
if (listParamType == null) {
ValidationMethodProcedureParamsSupportGenericParamResult(
ValidationMethodParamsSupportGenericParamResult(
identifier,
shortName,
"Unknown",
Expand All @@ -88,14 +88,14 @@ class ProcedureFunctionResultSetParamAnnotationTypeChecker(

val listCanonicalText = listParamType.canonicalText
val result =
ValidationMethodProcedureParamsSupportGenericParamResult(
ValidationMethodParamsSupportGenericParamResult(
identifier,
shortName,
listCanonicalText,
annotationType.requireType,
)
if (DomaClassName.MAP.isTargetClassNameStartsWith(listCanonicalText)) {
if (checkMapType(listCanonicalText)) result.highlightElement(holder)
if (!checkMapType(listCanonicalText)) result.highlightElement(holder)
return
}

Expand Down
Loading
Loading