Repository navigation
fix: support wildcard type arguments in the processor (#435) #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AndreasIgel
merged 6 commits into
java-helpers:main
from
igel-devin-ai:fix/processor-wildcard-type-arguments
Nov 22, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f9a8d39
fix: preserve wildcard type arguments in generated builders
devin-ai-integration[bot] 1bf18b5
refactor: use EqualsBuilder/HashCodeBuilder in TypeNameWildcard and c…
devin-ai-integration[bot] 40cd198
docs: explain why field helpers skip wildcard type arguments
devin-ai-integration[bot] 7858d92
docs: give per-generator reasons for skipping wildcard type arguments
devin-ai-integration[bot] a4652ec
refactor: drop redundant TypeNameVariable branch from mapType
devin-ai-integration[bot] e4b889d
Use polymorphic wildcard argument checks in generators
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
codegen-core/src/main/java/org/javahelpers/codegen/model/type/TypeNameWildcard.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * MIT License | ||
| * | ||
| * Copyright (c) 2025-2026 Andreas Igel | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package org.javahelpers.codegen.model.type; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import org.apache.commons.lang3.builder.EqualsBuilder; | ||
| import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
|
|
||
| /** A wildcard type argument, optionally bounded above or below by another type. */ | ||
| public final class TypeNameWildcard extends TypeName { | ||
| public enum BoundKind { | ||
| UNBOUNDED, | ||
| EXTENDS, | ||
| SUPER | ||
| } | ||
|
|
||
| private final BoundKind boundKind; | ||
| private final TypeName bound; | ||
|
|
||
| /** Creates an unbounded wildcard. */ | ||
| public TypeNameWildcard() { | ||
| super("", "?"); | ||
| boundKind = BoundKind.UNBOUNDED; | ||
| bound = null; | ||
| } | ||
|
|
||
| private TypeNameWildcard(BoundKind boundKind, TypeName bound) { | ||
| super("", "?"); | ||
| this.boundKind = boundKind; | ||
| this.bound = Objects.requireNonNull(bound, "bound"); | ||
| } | ||
|
|
||
| /** | ||
| * Creates an upper-bounded wildcard. | ||
| * | ||
| * @param bound the non-null upper bound | ||
| * @return the wildcard | ||
| */ | ||
| public static TypeNameWildcard extendsBound(TypeName bound) { | ||
| return new TypeNameWildcard(BoundKind.EXTENDS, bound); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a lower-bounded wildcard. | ||
| * | ||
| * @param bound the non-null lower bound | ||
| * @return the wildcard | ||
| */ | ||
| public static TypeNameWildcard superBound(TypeName bound) { | ||
| return new TypeNameWildcard(BoundKind.SUPER, bound); | ||
| } | ||
|
|
||
| public BoundKind getBoundKind() { | ||
| return boundKind; | ||
| } | ||
|
|
||
| public Optional<TypeName> getBound() { | ||
| return Optional.ofNullable(bound); | ||
| } | ||
|
|
||
| @Override | ||
| public String getFullQualifiedName() { | ||
| return switch (boundKind) { | ||
| case UNBOUNDED -> "?"; | ||
| case EXTENDS -> "? extends " + bound.getFullQualifiedName(); | ||
| case SUPER -> "? super " + bound.getFullQualifiedName(); | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
|
|
||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
|
|
||
| TypeNameWildcard that = (TypeNameWildcard) o; | ||
|
|
||
| return new EqualsBuilder() | ||
| .appendSuper(super.equals(o)) | ||
| .append(boundKind, that.boundKind) | ||
| .append(bound, that.bound) | ||
| .isEquals(); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return new HashCodeBuilder(17, 37) | ||
| .appendSuper(super.hashCode()) | ||
| .append(boundKind) | ||
| .append(bound) | ||
| .toHashCode(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
codegen-core/src/test/java/org/javahelpers/codegen/model/type/TypeNameWildcardTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * MIT License | ||
| * | ||
| * Copyright (c) 2025-2026 Andreas Igel | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
|
|
||
| package org.javahelpers.codegen.model.type; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.List; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class TypeNameWildcardTest { | ||
| @Test | ||
| void modelsBoundsAndQualifiedNames() { | ||
| TypeNameWildcard unbounded = new TypeNameWildcard(); | ||
| assertEquals("?", unbounded.getFullQualifiedName()); | ||
| assertEquals(TypeNameWildcard.BoundKind.UNBOUNDED, unbounded.getBoundKind()); | ||
| assertTrue(unbounded.getBound().isEmpty()); | ||
| TypeNameWildcard upper = TypeNameWildcard.extendsBound(TypeName.of(Number.class)); | ||
| assertEquals("? extends java.lang.Number", upper.getFullQualifiedName()); | ||
| assertEquals(TypeName.of(Number.class), upper.getBound().orElseThrow()); | ||
| TypeNameWildcard lower = | ||
| TypeNameWildcard.superBound(new TypeNameGeneric(List.class, String.class)); | ||
| assertEquals("? super java.util.List<java.lang.String>", lower.getFullQualifiedName()); | ||
| assertEquals(TypeNameWildcard.BoundKind.SUPER, lower.getBoundKind()); | ||
| } | ||
|
|
||
| @Test | ||
| void equalityIncludesDirectionAndBound() { | ||
| TypeNameWildcard upper = TypeNameWildcard.extendsBound(TypeName.of(Number.class)); | ||
| TypeNameWildcard same = TypeNameWildcard.extendsBound(TypeName.of(Number.class)); | ||
| assertEquals(upper, same); | ||
| assertEquals(upper.hashCode(), same.hashCode()); | ||
| assertEquals(new TypeNameWildcard(), new TypeNameWildcard()); | ||
| assertNotEquals(upper, new TypeNameWildcard()); | ||
| assertNotEquals(upper, TypeNameWildcard.superBound(TypeName.of(Number.class))); | ||
| assertNotEquals(upper, TypeNameWildcard.extendsBound(TypeName.of(Integer.class))); | ||
| assertNotEquals(upper, TypeName.of(Number.class)); | ||
| assertNotEquals(upper, null); | ||
| } | ||
|
|
||
| @Test | ||
| void rejectsMissingBound() { | ||
| assertThrows(NullPointerException.class, () -> TypeNameWildcard.extendsBound(null)); | ||
| assertThrows(NullPointerException.class, () -> TypeNameWildcard.superBound(null)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.