Skip to content

Conversation

@xterao
Copy link
Collaborator

@xterao xterao commented Jul 30, 2025

This update enables support for Java record types annotated with @DataType when used as return types or parameter types in DAO methods.


Issue

Previously, the code inspection mechanism would erroneously highlight @DataType records as errors when used as DAO method return types.


Fix Overview

The inspection logic has been updated to recognize @DataType-annotated records as valid in the following cases:

  • For @Select-annotated DAO methods:
    No error highlight for using @DataType records as either return type or parameter type.

  • For @Factory-annotated DAO methods:
    @DataType records are accepted as both return type and parameter type.

  • For @Procedure-annotated DAO methods:
    @DataType records are allowed as parameter types.

  • For @Update, @Insert, and @Delete DAO methods:
    If the annotation has the option sqlFile = true or is used in combination with @Sql, then @DataType records are allowed as parameter types.

  • For Batch annotations (e.g., @BatchInsert, @BatchUpdate, etc.):
    If sqlFile = true is specified or @Sql is present, then using a @DataType record as the element type of the parameter is accepted and not highlighted as an error.


This change improves support for domain-style value types and ensures compatibility with custom record-based models in Doma DAO method signatures.


Related Issue
N/A


Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Other (please specify)
  • Refactor
  • Test
  • Build system change
  • Chore
  • Performance improvement
  • Code style update
  • Security fix
  • Other (please specify)

@github-actions github-actions bot added the fix Bug fixes label Jul 30, 2025
@xterao xterao self-assigned this Jul 30, 2025
@xterao xterao requested a review from Copilot July 30, 2025 07:59
@xterao xterao linked an issue Jul 30, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the new @DataType annotation in the Doma framework plugin, enabling validation and type checking for Java record classes annotated with @DataType. The implementation extends existing Domain and Entity type checking to also recognize DataType annotations.

  • Added isDataType() method to identify record classes with @DataType annotation
  • Updated all type checking processors to validate DataType alongside Domain and Entity types
  • Enhanced parameter and return type validation for DAO methods to support DataType

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main/kotlin/org/domaframework/doma/intellij/common/util/DomaClassName.kt Added DATATYPE enum constant for annotation identification
src/main/kotlin/org/domaframework/doma/intellij/common/util/TypeUtil.kt Added isDataType utility method for type checking
src/main/kotlin/org/domaframework/doma/intellij/extension/psi/PsiClassExtension.kt Added isDataType extension method with record validation
Multiple processor files Updated type validation to include DataType support alongside Domain/Entity
Test files Added comprehensive test data and test cases for DataType validation
Comments suppressed due to low confidence (1)

src/test/testData/src/main/java/doma/example/dao/inspection/returntype/DataTypeReturnTypeTestDao.java:52

  • The test shows 'Cannot resolve symbol BatchResult' error, but BatchResult should be a valid Doma type. This suggests either a missing import or the test data is not properly set up to resolve Doma framework classes.
  <error descr="Cannot resolve symbol 'BatchResult'">BatchResult</error><Salary> <error descr="The return type must be \"int[]\"">batchUpdateSalaryWithSql2</error>(List<Salary> salary);

@xterao xterao changed the title Add support for DataType annotations in Doma framework Support for Using @DataType-Annotated Records in DAO Method Return and Parameter Types Jul 30, 2025
@xterao xterao force-pushed the fix/check-returntype-datatype branch from 1d5c115 to 62a61d8 Compare July 30, 2025 08:14
@xterao xterao merged commit fea91a5 into main Jul 30, 2025
5 checks passed
@xterao xterao deleted the fix/check-returntype-datatype branch July 30, 2025 08:30
@xterao xterao added this to the ver2.0.0 Release milestone Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Return Type with @DataType Is Incorrectly Marked as Invalid

2 participants