Skip to content

refactor: centralize erasure-aware Java signature calculation - #486

Merged
AndreasIgel merged 3 commits into
java-helpers:mainfrom
igel-devin-ai:java-signature-erasure
Dec 4, 2026
Merged

AndreasIgel merged 3 commits into
java-helpers:mainfrom
igel-devin-ai:java-signature-erasure

Conversation

@igel-devin-ai

Copy link
Copy Markdown
Contributor

Summary

Extracts method/constructor signature calculation into a shared JavaSignatures utility in codegen-core:

  • type variables are erased to their first upper bound, following Java type erasure — previously a type variable T was keyed as "T" instead of its erasure, so e.g. void m(T) and void m(String) with <T extends String> did not collide the way javac sees them
  • owner type variables are resolved through caller-provided context (typeVariableUpperBounds)
  • array dimensions are preserved (builds on Keep array dimensions in method signature keys #481)

Adopted in:

  • MethodDto.getSignatureKey() / BuilderMethodDto.getSignatureKey() — now delegate instead of duplicating the concatenation logic
  • RoasterCodeGenerator.resolveMethodConflicts — owner-generics-aware duplicate detection
  • BuilderDefinitionCreator.collectMethodsBySignature — same for builder methods

Preparation for #465: the generation-target validation in #479 needs correct erasure-aware signatures to detect duplicate methods/constructors; this PR is the signature-calculation part split out of #479 so it can be reviewed and merged independently. #479 will be rebased once this lands.

Extracts method/constructor signature calculation into JavaSignatures
in codegen-core: type variables are erased to their first upper bound
(Java type erasure), array dimensions are preserved, and owner type
variables are resolved through caller-provided context.

Adopted in MethodDto/BuilderMethodDto getSignatureKey, Roaster conflict
resolution and BuilderDefinitionCreator method grouping, replacing the
duplicated raw-qualified-name concatenations that treated type variables
as their own names instead of their erasures.

Preparation for generation-target validation (java-helpers#465), which needs correct
signatures to detect duplicate methods and constructors.
Comment on lines +304 to +306
List<MethodDto> resolvedMethods =
resolveMethodConflicts(
classDef.getMethods(), JavaSignatures.typeVariableUpperBounds(classDef.getGenerics()));

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.

Suggested change
List<MethodDto> resolvedMethods =
resolveMethodConflicts(
classDef.getMethods(), JavaSignatures.typeVariableUpperBounds(classDef.getGenerics()));
classGenerics = JavaSignatures.typeVariableUpperBounds(classDef);
List<MethodDto> resolvedMethods =
resolveMethodConflicts(
classDef.getMethods(), classGenerics);

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.

Applied — added a typeVariableUpperBounds(GenerationTargetClassDto) overload to JavaSignatures and used it here.

Comment on lines +417 to +421
return JavaSignatures.methodSignature(
method.getMethodName(),
method.getParameters(),
method.getGenericParameters(),
typeVariableUpperBounds);

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.

This should be then provided by ruhe builder specific signature helper

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 — the private helper is gone; BuilderDefinitionCreator now uses BuilderSignatures.methodSignature(method, typeVariableUpperBounds) from the new builder-specific signature helper.

- BuilderSignatures in the processor project provides erasure-aware
  signatures for BuilderMethodDto, used by getSignatureKey and
  BuilderDefinitionCreator instead of a local helper
- JavaSignatures.typeVariableUpperBounds overload taking the generation
  target directly
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@AndreasIgel
AndreasIgel merged commit 514c6de into java-helpers:main Dec 4, 2026
5 checks passed
@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!

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.

2 participants