Repository navigation
feat(codegen-core): Class-based import constructors + AnnotationDto type validation (#445) - #444
Merged
AndreasIgel merged 4 commits intoNov 24, 2026
Conversation
Allows new RegularImport(Instant.class) instead of new RegularImport(TypeName.of(Instant.class)), matching the TypeName.of(Class) shortcuts elsewhere. Related to java-helpers#415.
…notationType (java-helpers#445) Annotations can never be generic, array, map, set, wildcard, primitive or type-variable typed; previously such invalid models were silently accepted and only surfaced as broken generated source.
| public void setAnnotationType(TypeName annotationType) { | ||
| if (annotationType instanceof TypeNameGeneric | ||
| || annotationType instanceof TypeNameArray | ||
| || annotationType instanceof TypeNameMap |
Contributor
Author
There was a problem hiding this comment.
Fixed — TypeNameMap extends TypeNameGeneric, so the check was unreachable; dropped. TypeNameGeneric covers Map/Set/List now.
| if (annotationType instanceof TypeNameGeneric | ||
| || annotationType instanceof TypeNameArray | ||
| || annotationType instanceof TypeNameMap | ||
| || annotationType instanceof TypeNameSet |
Contributor
Author
There was a problem hiding this comment.
Fixed — same: TypeNameSet (via TypeNameCollection) extends TypeNameGeneric; the dead check is removed.
AndreasIgel
reviewed
Nov 24, 2026
Comment on lines
+32
to
+38
| import org.javahelpers.codegen.model.type.TypeNameArray; | ||
| import org.javahelpers.codegen.model.type.TypeNameGeneric; | ||
| import org.javahelpers.codegen.model.type.TypeNameMap; | ||
| import org.javahelpers.codegen.model.type.TypeNamePrimitive; | ||
| import org.javahelpers.codegen.model.type.TypeNameSet; | ||
| import org.javahelpers.codegen.model.type.TypeNameVariable; | ||
| import org.javahelpers.codegen.model.type.TypeNameWildcard; |
Collaborator
There was a problem hiding this comment.
Using wildcard import?
Contributor
Author
There was a problem hiding this comment.
Done — import org.javahelpers.codegen.model.type.* now.
TypeNameMap/TypeNameSet/TypeNameList all extend TypeNameGeneric, so the explicit checks were dead code (CodeQL 'contradictory type checks'). TypeNameGeneric alone covers them.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Class-based convenience constructors for both
ImportStatementimplementations plus theAnnotationDtovalidation fix:new RegularImport(Instant.class)/new StaticImport(System.class, "out")instead of wrappingTypeName.of(...)first — delegates to theTypeNameconstructors, so array/generic unwrapping semantics are unchanged.AnnotationDto.setAnnotationTypenow rejects non-plain type kinds (TypeNameGeneric/Array/Map/Set/Wildcard/Primitive/Variable) — annotations can never have those shapes; invalid models now fail fast instead of producing broken generated source.Split out of #429 per review — changes on codegen model/DTO classes land separately from the builder work.