Skip to content

Commit 0d8cdc7

Browse files
committed
Add support for DataType in Doma framework with related utility functions
1 parent 5b4480e commit 0d8cdc7

File tree

11 files changed

+76
-8
lines changed

11 files changed

+76
-8
lines changed

src/main/kotlin/org/domaframework/doma/intellij/common/util/DomaClassName.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum class DomaClassName(
6767
SELECT_TYPE("org.seasar.doma.SelectType"),
6868

6969
ENTITY("org.seasar.doma.Entity"),
70+
DATATYPE("org.seasar.doma.DataType"),
7071
;
7172

7273
fun isTargetClassNameStartsWith(paramTypeCanonicalNames: String): Boolean = paramTypeCanonicalNames.startsWith(this.className)

src/main/kotlin/org/domaframework/doma/intellij/common/util/TypeUtil.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiType
2222
import org.domaframework.doma.intellij.common.psi.PsiTypeChecker
2323
import org.domaframework.doma.intellij.extension.getJavaClazz
2424
import org.domaframework.doma.intellij.extension.psi.getClassAnnotation
25+
import org.domaframework.doma.intellij.extension.psi.isDataType
2526
import org.domaframework.doma.intellij.extension.psi.isDomain
2627
import org.domaframework.doma.intellij.extension.psi.isEntity
2728

@@ -73,6 +74,17 @@ object TypeUtil {
7374
return clazz?.isDomain() == true
7475
}
7576

77+
/**
78+
* Checks if the given type is a data type.
79+
*/
80+
fun isDataType(
81+
type: PsiType?,
82+
project: Project,
83+
): Boolean {
84+
val clazz = type?.canonicalText?.let { project.getJavaClazz(it) }
85+
return clazz?.isDataType() == true
86+
}
87+
7688
/**
7789
* Checks if the given type is a valid Map<String, Object>.
7890
*/

src/main/kotlin/org/domaframework/doma/intellij/extension/psi/PsiClassExtension.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ fun PsiClass.isEntity(): Boolean = this.getClassAnnotation(DomaClassName.ENTITY.
5050

5151
fun PsiClass.isDomain(): Boolean = this.getClassAnnotation(DomaClassName.DOMAIN.className) != null
5252

53+
fun PsiClass.isDataType(): Boolean = this.getClassAnnotation(DomaClassName.DATATYPE.className) != null
54+
5355
fun PsiClassType.getSuperType(superClassName: String): PsiClassType? {
5456
var parent: PsiClassType? = this
5557
while (parent != null && !parent.canonicalText.startsWith(superClassName)) {

src/main/kotlin/org/domaframework/doma/intellij/inspection/dao/processor/TypeCheckerProcessor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.domaframework.doma.intellij.common.psi.PsiTypeChecker
2626
import org.domaframework.doma.intellij.common.util.DomaClassName
2727
import org.domaframework.doma.intellij.extension.getJavaClazz
2828
import org.domaframework.doma.intellij.extension.psi.getSuperType
29+
import org.domaframework.doma.intellij.extension.psi.isDataType
2930
import org.domaframework.doma.intellij.extension.psi.isDomain
3031

3132
/**
@@ -90,12 +91,12 @@ abstract class TypeCheckerProcessor(
9091
val optionalParam = paramClassType.parameters.firstOrNull()
9192
return optionalParam?.let {
9293
val optionalParamClass = project.getJavaClazz(it.canonicalText)
93-
optionalParamClass?.isDomain() == true || PsiTypeChecker.isBaseClassType(it)
94+
optionalParamClass?.isDomain() == true || optionalParamClass?.isDataType() == true || PsiTypeChecker.isBaseClassType(it)
9495
} == true
9596
}
9697

9798
val paramClass = project.getJavaClazz(paramType.canonicalText)
98-
return paramClass?.isDomain() == true
99+
return paramClass?.isDomain() == true || paramClass?.isDataType() == true
99100
}
100101

101102
protected fun checkMapType(paramTypeCanonicalText: String): Boolean {

src/main/kotlin/org/domaframework/doma/intellij/inspection/dao/processor/cheker/ProcedureFunctionResultSetParamAnnotationTypeChecker.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.domaframework.doma.intellij.common.util.DomaClassName
2626
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodParamsSupportGenericParamResult
2727
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodProcedureParamTypeResult
2828
import org.domaframework.doma.intellij.extension.getJavaClazz
29+
import org.domaframework.doma.intellij.extension.psi.isDataType
2930
import org.domaframework.doma.intellij.extension.psi.isDomain
3031
import org.domaframework.doma.intellij.extension.psi.isEntity
3132

@@ -46,14 +47,15 @@ class ProcedureFunctionResultSetParamAnnotationTypeChecker(
4647
val optionalParamClass = project.getJavaClazz(it.canonicalText)
4748
optionalParamClass?.isDomain() == true ||
4849
optionalParamClass?.isEntity() == true ||
50+
optionalParamClass?.isDataType() == true ||
4951
PsiTypeChecker.isBaseClassType(
5052
it,
5153
)
5254
} == true
5355
}
5456

5557
val paramClass = project.getJavaClazz(paramType.canonicalText)
56-
return paramClass?.isDomain() == true
58+
return paramClass?.isDomain() == true || paramClass?.isDataType() == true
5759
}
5860

5961
override fun checkParam(
@@ -101,7 +103,7 @@ class ProcedureFunctionResultSetParamAnnotationTypeChecker(
101103

102104
val paramClass = project.getJavaClazz(listParamType.canonicalText)
103105

104-
if (checkParamType(listParamType) || paramClass?.isEntity() == true) return
106+
if (checkParamType(listParamType) || paramClass?.isEntity() == true || paramClass?.isDataType() == true) return
105107
result.highlightElement(holder)
106108
}
107109
}

src/main/kotlin/org/domaframework/doma/intellij/inspection/dao/processor/paramtype/SelectParamTypeCheckProcessor.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.domaframework.doma.intellij.common.validation.result.ValidationMethod
2727
import org.domaframework.doma.intellij.common.validation.result.ValidationMethodSelectStrategyParamResult
2828
import org.domaframework.doma.intellij.extension.getJavaClazz
2929
import org.domaframework.doma.intellij.extension.psi.getSuperClassType
30+
import org.domaframework.doma.intellij.extension.psi.isDataType
3031
import org.domaframework.doma.intellij.extension.psi.isDomain
3132
import org.domaframework.doma.intellij.extension.psi.isEntity
3233
import org.domaframework.doma.intellij.inspection.dao.processor.StrategyParam
@@ -49,12 +50,13 @@ class SelectParamTypeCheckProcessor(
4950
val optionalParamClass = project.getJavaClazz(it.canonicalText)
5051
optionalParamClass?.isDomain() == true ||
5152
PsiTypeChecker.isBaseClassType(it) ||
52-
optionalParamClass?.isEntity() == true
53+
optionalParamClass?.isEntity() == true ||
54+
optionalParamClass?.isDataType() == true
5355
} == true
5456
}
5557

5658
val paramClass = project.getJavaClazz(paramType.canonicalText)
57-
return paramClass?.isDomain() == true || paramClass?.isEntity() == true
59+
return paramClass?.isDomain() == true || paramClass?.isEntity() == true || paramClass?.isDataType() == true
5860
}
5961

6062
override fun checkParams(holder: ProblemsHolder) {

src/main/kotlin/org/domaframework/doma/intellij/inspection/dao/processor/returntype/FunctionReturnTypeCheckProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class FunctionReturnTypeCheckProcessor(
6767
}
6868
}
6969

70-
if (TypeUtil.isDomain(checkType, project) || TypeUtil.isEntity(checkType, project)) {
70+
if (TypeUtil.isDomain(checkType, project) || TypeUtil.isEntity(checkType, project) || TypeUtil.isDataType(checkType, project)) {
7171
return null
7272
}
7373

src/main/kotlin/org/domaframework/doma/intellij/inspection/dao/processor/returntype/SelectReturnTypeCheckProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class SelectReturnTypeCheckProcessor(
9191
}
9292
}
9393

94-
if (TypeUtil.isDomain(checkType, project) || TypeUtil.isEntity(checkType, project)) {
94+
if (TypeUtil.isDomain(checkType, project) || TypeUtil.isEntity(checkType, project) || TypeUtil.isDataType(checkType, project)) {
9595
return null
9696
}
9797

src/test/kotlin/org/domaframework/doma/intellij/inspection/dao/AnnotationReturnTypeCheckInspectionTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class AnnotationReturnTypeCheckInspectionTest : DomaSqlTest() {
3232
"ProcedureReturnTypeTestDao",
3333
"FunctionReturnTypeTestDao",
3434
"FactoryReturnTypeTestDao",
35+
"DataTypeReturnTypeTestDao",
3536
)
3637
private val daoPackage = "inspection/returntype"
3738

@@ -43,6 +44,7 @@ class AnnotationReturnTypeCheckInspectionTest : DomaSqlTest() {
4344
addEntityJavaFile("Packet.java")
4445
addEntityJavaFile("Pckt.java")
4546
addOtherJavaFile("domain", "Hiredate.java")
47+
addOtherJavaFile("domain", "Salary.java")
4648
addOtherJavaFile("collector", "HogeCollector.java")
4749
addOtherJavaFile("function", "HogeFunction.java")
4850
addOtherJavaFile("function", "HogeBiFunction.java")
@@ -88,4 +90,9 @@ class AnnotationReturnTypeCheckInspectionTest : DomaSqlTest() {
8890
val dao = findDaoClass("$daoPackage.FactoryReturnTypeTestDao")
8991
myFixture.testHighlighting(false, false, false, dao.containingFile.virtualFile)
9092
}
93+
94+
fun testDataTypeReturnTypeCheckProcessor() {
95+
val dao = findDaoClass("$daoPackage.DataTypeReturnTypeTestDao")
96+
myFixture.testHighlighting(false, false, false, dao.containingFile.virtualFile)
97+
}
9198
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package doma.example.dao.inspection.returntype;
2+
3+
import org.seasar.doma.*;
4+
import doma.example.domain.Salary;
5+
import org.seasar.doma.jdbc.Reference;
6+
7+
import java.util.List;
8+
import java.util.Optional;
9+
10+
@Dao
11+
public interface DataTypeReturnTypeTestDao {
12+
13+
@Select
14+
@Sql("select * from salary where id = /*salary.value*/0")
15+
Salary selectSalary(Salary salary);
16+
17+
@Select
18+
@Sql("select * from salary where id = /*salary.value*/0")
19+
Optional<Salary> selectOptSalary(Salary salary) ;
20+
21+
@Function
22+
Salary calculateAverageSalary();
23+
24+
@Function
25+
Optional<Salary> getMaxSalary(@InOut Reference<Salary> percentage, @ResultSet List<Salary> resultSet);
26+
27+
@Procedure
28+
void computeBonus(@In Salary employeeId);
29+
30+
@Procedure
31+
void adjustSalaries(@InOut Reference<Salary> percentage, @ResultSet List<Salary> resultSet);
32+
33+
}

0 commit comments

Comments
 (0)