File tree Expand file tree Collapse file tree 5 files changed +79
-4
lines changed
main/kotlin/org/domaframework/doma/intellij
inspection/dao/processor/returntype
test/testData/src/main/java/doma/example/dao/inspection/returntype Expand file tree Collapse file tree 5 files changed +79
-4
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "permissions" : {
3+ "allow" : [
4+ " Bash(./gradlew test:*)" ,
5+ " Bash(gh issue view:*)" ,
6+ " Bash(gh repo view:*)" ,
7+ " Bash(gh issue list:*)" ,
8+ " Bash(gh auth:*)" ,
9+ " Bash(gh api:*)" ,
10+ " WebFetch(domain:github.com)" ,
11+ " Bash(git checkout:*)" ,
12+ " Bash(git pull:*)" ,
13+ " Bash(./gradlew:*)" ,
14+ " Bash(git add:*)"
15+ ],
16+ "deny" : []
17+ }
18+ }
Original file line number Diff line number Diff line change @@ -60,8 +60,9 @@ object PsiTypeChecker {
6060 fun isBaseClassType (psiType : PsiType ? ): Boolean {
6161 if (psiType == null ) return false
6262 // Check if the type is a primitive type
63- if (psiType is PsiPrimitiveType && psiType.canonicalText == " char" ) {
64- return false
63+ if (psiType is PsiPrimitiveType ) {
64+ // char is not supported, but other primitive types are
65+ return psiType.canonicalText != " char"
6566 }
6667
6768 // Check if the type is a wrapper class
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package org.domaframework.doma.intellij.inspection.dao.processor.returntype
1717
1818import com.intellij.psi.PsiClassType
1919import com.intellij.psi.PsiType
20+ import com.intellij.psi.PsiTypes
2021import org.domaframework.doma.intellij.common.psi.PsiDaoMethod
2122import org.domaframework.doma.intellij.common.util.DomaClassName
2223import org.domaframework.doma.intellij.common.util.TypeUtil
@@ -77,7 +78,7 @@ class SelectReturnTypeCheckProcessor(
7778 shortName,
7879 checkTypeCanonicalText,
7980 )
80- if (checkType == null ) return result
81+ if (checkType == null || checkType == PsiTypes .voidType() ) return result
8182
8283 if (TypeUtil .isBaseOrOptionalWrapper(checkType)) {
8384 return null
Original file line number Diff line number Diff line change 1616public interface FunctionReturnTypeTestDao {
1717
1818 @ Function
19- int < error descr = "The return type int is invalid" > primitiveFunction </ error > (@ In int id );
19+ int primitiveFunction (@ In int id );
2020
2121 @ Function
2222 void voidFunction (@ In int id );
2323
24+ @ Function
25+ long primitiveLongFunction (@ In long id );
26+
27+ @ Function
28+ boolean primitiveBooleanFunction (@ In boolean flag );
29+
30+ @ Function
31+ double primitiveDoubleFunction (@ In double value );
32+
33+ @ Function
34+ float primitiveFloatFunction (@ In float value );
35+
36+ @ Function
37+ byte primitiveByteFunction (@ In byte value );
38+
39+ @ Function
40+ short primitiveShortFunction (@ In short value );
41+
42+ @ Function
43+ char <error descr ="The return type char is invalid" >primitiveCharFunction </error >(@ In char value );
44+
2445 @ Function
2546 String executeFunction (
2647 @ In Integer arg1 , @ InOut Reference <Integer > arg2 , @ Out Reference <Integer > arg3 );
Original file line number Diff line number Diff line change @@ -139,4 +139,38 @@ public interface SelectReturnTypeTestDao {
139139 @ Sql ("select * from emp where salary > /* salary */0" )
140140 String selectHogeFunction (BigDecimal salary , HogeFunction function );
141141
142+ // Test cases for primitive return types - these should be valid (except char)
143+ @ Select
144+ @ Sql ("select count(*) from EMPLOYEE" )
145+ int selectCountAsInt ();
146+
147+ @ Select
148+ @ Sql ("select count(*) from EMPLOYEE" )
149+ long selectCountAsLong ();
150+
151+ @ Select
152+ @ Sql ("select exists(select 1 from EMPLOYEE where EMPLOYEE_ID = /* id */1)" )
153+ boolean selectExistsAsBoolean (Integer id );
154+
155+ @ Select
156+ @ Sql ("select avg(SALARY) from EMPLOYEE" )
157+ double selectAverageAsDouble ();
158+
159+ @ Select
160+ @ Sql ("select avg(SALARY) from EMPLOYEE" )
161+ float selectAverageAsFloat ();
162+
163+ @ Select
164+ @ Sql ("select age from EMPLOYEE where EMPLOYEE_ID = /* id */1" )
165+ byte selectAgeAsByte (Integer id );
166+
167+ @ Select
168+ @ Sql ("select department_id from EMPLOYEE where EMPLOYEE_ID = /* id */1" )
169+ short selectDepartmentIdAsShort (Integer id );
170+
171+ // This should show an error - char is not supported
172+ @ Select
173+ @ Sql ("select initial from EMPLOYEE where EMPLOYEE_ID = /* id */1" )
174+ char <error descr ="The return type char is invalid" >selectInitialAsChar </error >(Integer id );
175+
142176}
You can’t perform that action at this time.
0 commit comments