Skip to content

feat(codegen-core): Class-based import constructors + AnnotationDto type validation (#445) - #444

Merged
AndreasIgel merged 4 commits into
java-helpers:mainfrom
igel-devin-ai:feat/regular-import-class-ctor
Nov 24, 2026
Merged

AndreasIgel merged 4 commits into
java-helpers:mainfrom
igel-devin-ai:feat/regular-import-class-ctor

Conversation

@igel-devin-ai

@igel-devin-ai igel-devin-ai commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Class-based convenience constructors for both ImportStatement implementations plus the AnnotationDto validation fix:

  • new RegularImport(Instant.class) / new StaticImport(System.class, "out") instead of wrapping TypeName.of(...) first — delegates to the TypeName constructors, so array/generic unwrapping semantics are unchanged.
  • Fixes AnnotationDto.setAnnotationType accepts invalid type kinds (generic/array/map/set/wildcard) #445: AnnotationDto.setAnnotationType now 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.

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.
@igel-devin-ai igel-devin-ai changed the title feat(codegen-core): add RegularImport(Class) convenience constructor feat(codegen-core): add Class-based convenience constructors for RegularImport/StaticImport Nov 24, 2026
…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.
@igel-devin-ai igel-devin-ai changed the title feat(codegen-core): add Class-based convenience constructors for RegularImport/StaticImport feat(codegen-core): Class-based import constructors + AnnotationDto type validation (#445) Nov 24, 2026
public void setAnnotationType(TypeName annotationType) {
if (annotationType instanceof TypeNameGeneric
|| annotationType instanceof TypeNameArray
|| annotationType instanceof TypeNameMap

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.

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

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.

Fixed — same: TypeNameSet (via TypeNameCollection) extends TypeNameGeneric; the dead check is removed.

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;

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.

Using wildcard import?

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 — 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.
@AndreasIgel
AndreasIgel merged commit b1e998e into java-helpers:main Nov 24, 2026
5 checks passed
@codecov

codecov Bot commented Nov 24, 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!

@sonarqubecloud

Copy link
Copy Markdown

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.

AnnotationDto.setAnnotationType accepts invalid type kinds (generic/array/map/set/wildcard)

3 participants