Skip to content

feat: validate generation targets before rendering (#465) - #479

Merged
AndreasIgel merged 6 commits into
java-helpers:mainfrom
igel-devin-ai:issue-465-generation-target-validation
Dec 5, 2026
Merged

AndreasIgel merged 6 commits into
java-helpers:mainfrom
igel-devin-ai:issue-465-generation-target-validation

Conversation

@igel-devin-ai

@igel-devin-ai igel-devin-ai commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends the existing GenerationTargetValidator (introduced in #470) and moves it into codegen-core (org.javahelpers.codegen.validation), implementing the full rule set of #465 before rendering:

  • duplicate parameter names within a method/constructor
  • duplicate method signatures and constructor signatures (erasure-aware via JavaSignatures from refactor: centralize erasure-aware Java signature calculation #486)
  • duplicate field names
  • nested-type name collisions (with each other and the target class)
  • nested-type member validation: methods, fields and constructors validated recursively; nested interfaces declaring constructors or fields are rejected (interfaces cannot have constructors, and interface fields are implicit constants that cannot be generated as declared)
  • simple-name collisions of referenced types (e.g. java.util.Date vs java.sql.Date)
  • static-import member collisions across different owners
  • reserved words and illegal identifiers for all name-bearing properties

All violations are collected and reported in one CodeGenerationException instead of failing on the first.

Rebased onto main after #486 and #488 merged — the diff is now the validator alone.

@AndreasIgel

This comment has been minimized.

@igel-devin-ai

This comment has been minimized.

@AndreasIgel

This comment has been minimized.

@igel-devin-ai

This comment has been minimized.

@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Comment on lines +94 to +96
GenerationTargetClassDto target, String targetName, List<String> violations) {
Set<String> seen = new HashSet<>();
for (ClassFieldDto field : target.getClassFields()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Passing list of fields instead of target would be better, follow other calls and it would provide the possibility to reuse this function for validating fields of nested types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — validateFields now takes List<ClassFieldDto> and the call site passes target.getClassFields(), so the function can be reused for validating fields of nested types.

Extends and moves GenerationTargetValidator into codegen-core
(org.javahelpers.codegen.validation): duplicate parameter names,
duplicate method/constructor signatures (erasure-aware via
JavaSignatures), duplicate field names, nested-type collisions,
simple-name collisions of referenced types, reserved words and
illegal identifiers. Collects all violations into one exception.

Stacked on java-signature-erasure: the signature calculation is
split into its own PR.
- validateFields takes the field list so it can be reused for nested
  type validation
- static imports are checked for member-name collisions across
  different owners
- nested-type validation now recurses into fields and constructors,
  not just methods (model support added in java-helpers#487/java-helpers#488)
- nested interfaces declaring constructors or fields are rejected:
  constructors are impossible in interfaces, fields are implicit
  constants and cannot be generated as declared
@devin-ai-integration
devin-ai-integration Bot force-pushed the issue-465-generation-target-validation branch from 0479a9c to 3b48790 Compare December 5, 2026 08:40
The static entry point now creates a validator instance holding the
collected violations, the validation context and the type-variable
bounds, so the private validation methods no longer repeat targetName
and violations in every signature. Nested-type recursion scopes context
and type-variable bounds with save/restore.
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

@AndreasIgel
AndreasIgel merged commit d23d992 into java-helpers:main Dec 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants