Skip to content

feat: extend type kinds in codegen model — stage 1 (#489) - #492

Open
igel-devin-ai wants to merge 30 commits into
java-helpers:mainfrom
igel-devin-ai:devin/489-type-kinds
Open

igel-devin-ai wants to merge 30 commits into
java-helpers:mainfrom
igel-devin-ai:devin/489-type-kinds

Conversation

@igel-devin-ai

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

Copy link
Copy Markdown
Contributor

Part of #489 — stage 1.

In this stage:

  • shared TypeKind enum (CLASS/INTERFACE/ENUM/RECORD/ANNOTATION_TYPE); GenerationTargetClassDto.kind defaults to CLASS — no behavioral change for existing consumers
  • NestedTypeKind extended with ENUM/RECORD/ANNOTATION_TYPE
  • model + builder support for enum constants (target + nested); record components are modeled as plain fields — a record's components are its fields (JLS 8.10), no separate list
  • kind-preset factory methods on GenerationTargetClassDtoBuilder: createInterface(), createEnum(), createRecord(), createAnnotationType()
  • Roaster renders nested enums (with constants), nested annotation types (methods become annotation elements) and nested records (fields become the components in the record header); rendering tests for all of them
  • per-kind validation rules in GenerationTargetValidator for target and nested types:
    • interfaces: no constructors, no fields, no super type
    • enums: no generic parameters, no super type
    • records: no super type; record component fields must not declare a literal initializer (values are assigned through the canonical constructor)
    • annotation types: no constructors, no fields, no generics, no super type, no interfaces
    • misplaced members: enum constants only valid on enums

Deliberately not in this stage (follow-up on the same issue):

  • Top-level kind rendering: the generation pipeline is typed to JavaClassSource end to end (fields/constructors/methods/metadata appenders) — generalizing it to JavaSource<?> with per-kind capability handling is a bigger refactor that deserves its own reviewable change

- new shared TypeKind enum (CLASS/INTERFACE/ENUM/RECORD/ANNOTATION_TYPE),
  kind property on GenerationTargetClassDto (defaults to CLASS)
- NestedTypeKind extended with ENUM/RECORD/ANNOTATION_TYPE
- enum constants on generation target + nested types, record components
  on generation target (model + builders incl. copy constructors)
- Roaster renders nested enums (with constants) and nested annotation
  types (methods as annotation elements)

Stage 1 scope: nested enum/annotation-type rendering. Top-level kinds
need generalizing the generation pipeline beyond JavaClassSource; record
RENDERING is blocked upstream — Roaster 2.31.1 has no JavaRecordSource.
- record components on NestedTypeDto + builder (incl. copy constructor)
- nested records render via JavaRecordSource: components in the record
  header, constructors as regular canonical constructors with a warning
  logged (compact constructors unsupported upstream, forge/roaster#275)
- fields on records throw with a link to forge/roaster#279 (static
  fields in records unsupported upstream; instance fields are illegal
  in records anyway)
- 3 new rendering tests
- GenerationTargetValidator validates per-kind restrictions for target
  and nested types: interfaces reject constructors/fields/super type,
  enums and annotation types reject generics and super type, records
  reject fields and super type; enum constants only valid on enums,
  record components only valid on records
- GenerationTargetClassDtoBuilder gains createInterface(), createEnum(),
  createRecord() and createAnnotationType() factory methods presetting
  the kind
A record's components ARE its fields (JLS 8.10) — the separate
recordComponents list duplicated what classFields already models.
Records now render their fields as components in the record header;
the validator rejects literal initializers on record fields instead
of rejecting fields altogether, since component values are assigned
through the canonical constructor.
Constructors declared on records now have compact-constructor
semantics: an empty parameter list is auto-completed from the record
components (fields) in order, rendered as a regular canonical
constructor since Roaster cannot emit the compact form. The
validator rejects declared parameter lists that do not match the
components in order and type.
Records may declare additional constructors with any parameter list
as long as they delegate to the canonical constructor — checking the
delegation is the compiler's job, not the validator's. Only the
compact constructor semantics remain: an empty parameter list is
auto-completed from the components at generation time.
Comment on lines +51 to +64
public class GenerationTargetClassDto implements GenerationTargetClassDtoBuilder.With {
/** Kind of the generated type, defaults to {@link TypeKind#CLASS}. */
private org.javahelpers.codegen.model.type.TypeKind kind =
org.javahelpers.codegen.model.type.TypeKind.CLASS;

/** Enum constant names, only rendered when kind is {@link TypeKind#ENUM}. */
private final java.util.List<String> enumConstants = new java.util.LinkedList<>();

/**
* Record components as parameters (name + type), only rendered when kind is {@link
* TypeKind#RECORD}.
*/
private final java.util.List<org.javahelpers.codegen.model.method.MethodParameterDto>
recordComponents = new java.util.LinkedList<>();

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.

Could you do that with simple names instead of fullpackages? Please check other places of this PR too

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 — simple names with imports everywhere in the DTOs; swept the whole PR for fully-qualified usages (the {@code} javadoc references intentionally keep the FQN since that's generated documentation text).

Comment on lines +1418 to +1421
private org.javahelpers.codegen.model.type.TypeKind kind;
private final java.util.List<String> enumConstants = new java.util.LinkedList<>();
private final java.util.List<org.javahelpers.codegen.model.method.MethodParameterDto>
recordComponents = new java.util.LinkedList<>();

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.

Member variables to the top of the class and not below methods.

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.

Still full package here and on other places

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 — kind and enumConstants now sit with the other member variables at the top of the class.

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 — caught the remaining ones in the sweep (enumConstants/kind declarations in both DTOs and builders, plus a java.util.Arrays usage).

this.superType.ifSet(result::setSuperType);
this.typeName.ifSet(result::setTypeName);
if (kind != null) {
result.setKind(kind);

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.

Is kind default on dto set to class?

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.

Yes — GenerationTargetClassDto.kind is initialized to TypeKind.CLASS and the setter is null-guarded, so existing consumers that never set a kind behave exactly as before.

Comment on lines +847 to +850
private final java.util.List<String> enumConstants = new java.util.LinkedList<>();
private final java.util.List<org.javahelpers.codegen.model.method.MethodParameterDto>
recordComponents = new java.util.LinkedList<>();

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.

Here the same, it needs to be move in class up

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 — same move in NestedTypeDtoBuilder, the field is up with the other members now.

Comment on lines +386 to +415
if (nestedSource instanceof JavaEnumSource enumSource) {
for (String constant : nestedType.getEnumConstants()) {
enumSource.addEnumConstant(constant);
}
}
if (nestedSource instanceof JavaRecordSource recordSource) {
for (var component : nestedType.getRecordComponents()) {
recordSource.addRecordComponent(
RoasterMapper.mapType(component.getParameterType(), collidingSimpleNames),
component.getParameterName());
}
if (!nestedType.getClassFields().isEmpty()) {
// instance fields are illegal in records, so any declared field would have to be static —
// but Roaster cannot render static fields in records yet
throw new UnsupportedOperationException(
("Nested record '%s' declares fields, but Roaster does not support static fields in"
+ " records yet — see https://github.com/forge/roaster/issues/279")
.formatted(nestedType.getTypeName()));
}
if (!nestedType.getConstructors().isEmpty()) {
// Roaster does not support compact constructors
// (https://github.com/forge/roaster/issues/275);
// they are rendered as regular canonical constructors instead — the workaround is source-
// compatible since a compact constructor is just syntactic sugar for the canonical one
logger.debug(
"Nested record '%s' declares constructors: rendered as regular canonical constructors"
+ " because Roaster does not support compact constructors"
+ " (https://github.com/forge/roaster/issues/275)",
nestedType.getTypeName());
}

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.

Move that in helper functions one for each type

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 — extracted into per-kind helpers: appendEnumConstants / appendRecordComponents / appendRecordConstructors (the compact-constructor auto-completion lives there now, documented in its javadoc with the forge/roaster#275 link).

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.

But why not directly call that in the switch case instead of doing it afterwards in an instance of check?

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 kind-specific rendering now happens directly in the switch arms: enum constants in the ENUM case, record components and the compact-constructor warning in the RECORD case. The redundant instanceof checks afterwards are gone.

Comment on lines +112 to +117
if (target.getSuperType() != null) {
addViolation(
"Interface '%s' declares a super type, but interfaces can only extend interfaces"
+ " via the interfaces list",
target.getTypeName().getClassName());
}

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
if (target.getSuperType() != null) {
addViolation(
"Interface '%s' declares a super type, but interfaces can only extend interfaces"
+ " via the interfaces list",
target.getTypeName().getClassName());
}
rejectIfNotEmpty(target.getSuperType(),
"Interface '%s' declares a super type, but interfaces can only extend interfaces"
+ " via the interfaces list",
target.getTypeName().getClassName());

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.

Almost — rejectIfNotEmpty takes a collection, but superType is a single object. Introduced rejectIfNotNull as the single-value counterpart and applied it to all super type checks; generics/interfaces checks now use rejectIfNotEmpty as suggested.

Comment on lines +150 to +151
if (!target.getGenerics().isEmpty()) {
addViolation(

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.

Use rejectIfNotEmpty

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 — generics and interfaces checks on enums/annotation types use rejectIfNotEmpty now.

.nestedType(
n ->
n.typeName("Marker")
.kind(NestedTypeDto.NestedTypeKind.ANNOTATION_TYPE)

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.

Adding static import for NestedTypeDto.NestedTypeKind.* for increasing readability?

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 — static imports for ENUM/RECORD/ANNOTATION_TYPE, much easier to read.

- Specialized builders per target kind: GenerationTargetEnumDtoBuilder
  (enumConstant), GenerationTargetRecordDtoBuilder (recordComponent),
  GenerationTargetInterfaceDtoBuilder, GenerationTargetAnnotationTypeDtoBuilder;
  the kind-preset factories return them and enumConstant leaves the
  general builder — misplaced members are now impossible through the
  builder API, the validator remains as safety net for direct DTO use
- Roaster nested-type rendering extracted into per-kind helpers
  (appendEnumConstants/appendRecordComponents/appendRecordConstructors/
  appendAnnotationElements)
- Member variables moved to the top of both builders; simple names
  instead of fully qualified ones across the PR
- Validator: unified rejection pattern, rejectIfNotNull for single
  values next to rejectIfNotEmpty for collections
- Test readability: static imports for NestedTypeKind constants
…arget

- EnumConstantDto models a constant name plus optional constructor
  argument expressions — enumConstant(name, args...) on the enum and
  nested builders renders FAST(100), as required when the enum
  constructor has parameters
- validator prohibits enum constants on the generation target
  regardless of kind: top-level enum rendering is not implemented
  yet, so constants would be silently dropped
Constructor arguments of enum constants reuse the AnnotationMember
model: raw source expressions plus typed references (class/enum
constants) whose imports are collected and which are qualified on
simple-name collisions — the same semantics as annotation members.
RoasterMapper.mapAnnotationMemberValue gained an overload for bare
value expressions shared by both rendering paths.
Comment on lines +102 to +146
switch (target.getKind()) {
case INTERFACE -> {
rejectIfNotEmpty(
target.getConstructors(),
"Interface '%s' declares constructors, but interfaces cannot have constructors");
rejectIfNotEmpty(
target.getClassFields(),
"Interface '%s' declares fields, but fields on interfaces are implicit constants"
+ " and cannot be generated as declared");
rejectIfNotNull(
target.getSuperType(),
"Interface '%s' declares a super type, but interfaces can only extend interfaces"
+ " via the interfaces list");
}
case ENUM -> {
rejectIfNotEmpty(
target.getGenerics(),
"Enum '%s' declares generic parameters, but enums cannot be generic");
rejectIfNotNull(
target.getSuperType(),
"Enum '%s' declares a super type, but enums implicitly extend java.lang.Enum");
}
case RECORD -> {
validateRecordComponents(target.getClassFields(), target.getTypeName().getClassName());
rejectIfNotNull(
target.getSuperType(),
"Record '%s' declares a super type, but records implicitly extend java.lang.Record");
}
case ANNOTATION_TYPE -> {
rejectIfNotEmpty(
target.getConstructors(),
"Annotation type '%s' declares constructors, but annotation types cannot have constructors");
rejectIfNotEmpty(
target.getClassFields(),
"Annotation type '%s' declares fields, but fields are not supported on annotation types");
rejectIfNotEmpty(
target.getGenerics(),
"Annotation type '%s' declares generic parameters, but annotation types cannot be generic");
rejectIfNotNull(
target.getSuperType(),
"Annotation type '%s' declares a super type, but annotation types cannot extend types");
rejectIfNotEmpty(
target.getInterfaces(),
"Annotation type '%s' declares interfaces, but annotation types cannot implement interfaces");
}

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.

Looking at this, the correct implementation with inheritance of builder is wrong. On builder for interfaces for example there should be no field helper function.

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.

Agreed — inheritance is replaced by composition: the four kind builders no longer extend GenerationTargetClassDtoBuilder. They compose it and expose only the delegate methods legal for their kind — the interface builder has no field/constructor/superType helpers at all, the enum builder no generics/superType, the record builder no superType, the annotation builder none of these and no interfaces. As a bonus, chaining now keeps the specialized type everywhere. The illegal-state validation tests construct their fixtures through the mutable DTO directly, since the builders rightly can't express them anymore.

Comment on lines +182 to +183
if (field.getLiteralInitializer() != null) {
addViolation(

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.

RejectIfNoNull?

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.

Yes — aligned: null checks now use rejectIfNotNull, collection checks rejectIfNotEmpty (and the nested variants).

}

private void validateMisplacedKindMembers() {
if (!target.getEnumConstants().isEmpty()) {

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.

RejectIfNotEmpty?

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 nested generics check uses rejectNestedIfNotEmpty now.

nestedName);
}
case ENUM -> {
if (!nestedType.getGenericParameters().isEmpty()) {

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.

RejectIfNotEmpty

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 — aligned on the reject helpers.

"Nested annotation type '%s' in %s declares fields, but fields are not supported on"
+ " annotation types",
nestedName);
if (!nestedType.getGenericParameters().isEmpty()) {

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.

RejectIfNotEmpty

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 — aligned on the reject helpers here as well.

Comment on lines +699 to +702
CodeGenerationException exception =
assertThrows(
CodeGenerationException.class,
() ->

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.

Having a helper function so that it could be assertFailsValidationWithMessage("message", GenerationTargetBuilder.build())

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.

Added — assertFailsValidationWithMessage(expectedMessage, target) and all single-message tests use it. One exception: allViolationsCollectedInOneException keeps the manual form since it asserts two fragments (documented in the test).

Comment on lines +789 to +804
var enumTarget =
GenerationTargetClassDtoBuilder.createEnum().typeName("com.example", "E").build();
org.junit.jupiter.api.Assertions.assertEquals(
org.javahelpers.codegen.model.type.TypeKind.ENUM, enumTarget.getKind());
var interfaceTarget =
GenerationTargetClassDtoBuilder.createInterface().typeName("com.example", "I").build();
org.junit.jupiter.api.Assertions.assertEquals(
org.javahelpers.codegen.model.type.TypeKind.INTERFACE, interfaceTarget.getKind());
var recordTarget =
GenerationTargetClassDtoBuilder.createRecord().typeName("com.example", "R").build();
org.junit.jupiter.api.Assertions.assertEquals(
org.javahelpers.codegen.model.type.TypeKind.RECORD, recordTarget.getKind());
var annotationTarget =
GenerationTargetClassDtoBuilder.createAnnotationType().typeName("com.example", "A").build();
org.junit.jupiter.api.Assertions.assertEquals(
org.javahelpers.codegen.model.type.TypeKind.ANNOTATION_TYPE, annotationTarget.getKind());

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.

Remove full package names

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.

Removed — simple names with imports throughout the test.

Comment on lines +386 to +415
if (nestedSource instanceof JavaEnumSource enumSource) {
for (String constant : nestedType.getEnumConstants()) {
enumSource.addEnumConstant(constant);
}
}
if (nestedSource instanceof JavaRecordSource recordSource) {
for (var component : nestedType.getRecordComponents()) {
recordSource.addRecordComponent(
RoasterMapper.mapType(component.getParameterType(), collidingSimpleNames),
component.getParameterName());
}
if (!nestedType.getClassFields().isEmpty()) {
// instance fields are illegal in records, so any declared field would have to be static —
// but Roaster cannot render static fields in records yet
throw new UnsupportedOperationException(
("Nested record '%s' declares fields, but Roaster does not support static fields in"
+ " records yet — see https://github.com/forge/roaster/issues/279")
.formatted(nestedType.getTypeName()));
}
if (!nestedType.getConstructors().isEmpty()) {
// Roaster does not support compact constructors
// (https://github.com/forge/roaster/issues/275);
// they are rendered as regular canonical constructors instead — the workaround is source-
// compatible since a compact constructor is just syntactic sugar for the canonical one
logger.debug(
"Nested record '%s' declares constructors: rendered as regular canonical constructors"
+ " because Roaster does not support compact constructors"
+ " (https://github.com/forge/roaster/issues/275)",
nestedType.getTypeName());
}

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.

But why not directly call that in the switch case instead of doing it afterwards in an instance of check?

Comment on lines +501 to +511
constructor.getParameters().isEmpty()
? nestedType.getClassFields().stream()
.map(
field -> {
MethodParameterDto param = new MethodParameterDto();
param.setParameterName(field.getFieldName());
param.setParameterTypeName(field.getFieldType());
return param;
})
.toList()
: constructor.getParameters();

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.

I thought we decided not to have a constructor with all fields generated!

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.

Nothing is generated unless declared: the auto-completion only fills the parameters of a constructor that IS in the constructors list — that's the compact-constructor semantics you asked for ('could that not be done for the constructor with all fields?'). A record with no constructors gets no constructor output at all. If you'd rather drop the auto-completion and render declared constructors exactly as declared, say so and I'll simplify.

Set<String> collidingSimpleNames) {
for (MethodDto methodDto : nestedType.getMethods()) {
appendNestedMethod(nestedSource, methodDto, isInterface, collidingSimpleNames);
org.jboss.forge.roaster.model.source.AnnotationElementSource element =

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.

Again here and on other places full package names

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.

Removed — all roaster source types use simple names with imports now.

… names

- nested kind validation aligned on rejectNestedIfNotEmpty
- DtoBuilderCopyTest: enum constant added through the mutable DTO
  (superType on an enum is not a legal combination)
- validator tests: assertFailsValidationWithMessage helper, simple
  names instead of full packages
- RoasterCodeGenerator: simple names for roaster source types
The specialized builders no longer extend GenerationTargetClassDtoBuilder:
they compose it and expose only the delegate methods that are legal for
their kind. Interfaces have no field/constructor/superType helpers, enums
no generics/superType, records no superType, annotation types none of
these and no interfaces. enumConstant/recordComponent remain on their
kind builders. Negative validation tests construct illegal state through
the mutable DTO.
@codecov

codecov Bot commented Dec 5, 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!

Getters return an unmodifiable view; builder application uses the
addEnumConstant mutator instead of mutating through the getter
@igel-devin-ai

igel-devin-ai commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Strict review

blocking

Reviewed head 04ad58a69f4699130268a6fd832b4d3b19c8acea against upstream/main 4b696141058c97b8130c3ce3920a7faeafbb3bbd, including issue #489, the stage-1 scope statement, issue comments, and inline reviews. I am not repeating the already-addressed specialized-builder composition or unmodifiable enum-constant-list comments. Deferring top-level kind rendering can be a legitimate staged decision, but the implemented nested kinds still need to generate valid Java, and unsupported top-level rendering should not silently change the requested kind.

  1. major — verified — codegen-roaster/src/main/java/org/javahelpers/codegen/roaster/RoasterCodeGenerator.java:434–445: nested enum fields and constructors are silently discarded. Enums are JavaEnumSource, not JavaClassSource, so they miss the branch that appends ordinary fields and constructors; the only alternative branch handles records. A nested enum model with FAST(100), an int field, and a compatible private constructor passes GenerationTargetValidator, but output contains only enum Mode { FAST(100) }. Javac fails with constructor Mode in enum test.Target.Mode cannot be applied to given types; required: no arguments; found: int. A simple enum without constructor arguments compiles, ruling out a general enum-parser failure. Render enum fields/constructors through the appropriate Roaster capabilities, and compile the constructor-argument regression. The existing rendersEnumConstantsWithArguments test checks only FAST(100)/SLOW(10) substrings and therefore passes despite omitting the members that make those constants legal.

  2. major — verified — codegen-roaster/src/main/java/org/javahelpers/codegen/roaster/RoasterCodeGenerator.java:505–519: compact-constructor emulation loses implicit component assignments. For a record with component int x and the parameterless constructor body used by the new test, the renderer synthesizes Point(int x) but emits only the validation body. Unlike a compact constructor, an ordinary canonical constructor must assign this.x = x;. The generated source fails javac with variable x might not have been initialized. A control with an explicitly declared canonical constructor containing that assignment compiles with zero warnings. Preserve compact-constructor semantics, including assignment after the user body, or reject this unsupported representation instead of claiming the workaround is source-compatible. Make rendersRecordConstructorAsCanonicalConstructor compile its generated source; its current two substring assertions accept the broken output.

  3. major — verified — codegen-roaster/src/main/java/org/javahelpers/codegen/roaster/RoasterCodeGenerator.java:391–395: generic nested records crash at runtime. A legal record Box<T>(T value) model passes validation, reaches appendNestedType's RECORD case, then appendNestedGenerics casts its JavaRecordImpl to JavaClassSource. Generation throws CodeGenerationException caused by ClassCastException. Project frames are appendNestedGenerics:395, appendNestedType:427, appendNestedTypes:381, and buildClassSource:173. Use JavaRecordSource's generic support or a shared generic-capable abstraction rather than assuming every non-interface is a class. Add bounded and unbounded generic-record compile tests; ordinary non-generic records are not sufficient coverage.

  4. major — verified — codegen-roaster/src/main/java/org/javahelpers/codegen/roaster/RoasterCodeGenerator.java:530–541; codegen-core/src/main/java/org/javahelpers/codegen/validation/GenerationTargetValidator.java:285–302: annotation elements silently lose method state and invalid element signatures are accepted. appendAnnotationElements copies only the name and return type. A method model with a String arg parameter and @Deprecated passes kind validation, but becomes an unannotated String value();: its parameter and annotation disappear without a diagnostic. The annotation-kind validator checks constructors, fields and type-level generics, not element method shapes. Reject parameters and other unsupported element shapes, and preserve the legal annotation/Javadoc metadata that the model supplies. Add tests for annotated elements and invalid parameterized/void/generic elements. Do not make an invalid model appear valid by silently deleting its requested signature.

  5. major — verified — codegen-roaster/src/main/java/org/javahelpers/codegen/roaster/RoasterCodeGenerator.java:190–199; codegen-core/src/main/java/org/javahelpers/codegen/validation/GenerationTargetValidator.java:166–172: deferred top-level kinds are silently rendered as classes. Both createInterface().typeName("test", "Target").build() and the equivalent createRecord() pass validation, yet generation emits class Target { }. The renderer unconditionally creates JavaClassSource; the new unsupported-feature guard rejects top-level enum constants only, so empty enums/interfaces/records/annotation types can still reach a renderer that ignores their kind. This is not a request to implement stage 2 in this PR: fail fast at the rendering boundary for unsupported top-level kinds and document the factories as metadata-only until dispatch exists. A staged API must not successfully return Java of a different kind. Issue Support further type kinds in code generation: interfaces, records, enums, annotation types #489's full top-level acceptance criteria remain deferred, not completed by stage 1.

  6. nit — verified — codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/NestedTypeKindGenerationTest.java:107–108: the new multiline constructor-source fixture is an escaped ordinary string. Replace the \n-encoded method body with a text block. The numerous new expected-Java fragments should likewise follow the required text-block convention; preferably assert precise full generated sources and compile them, which would expose findings 1 and 2. No added + string concatenation was found in this PR's changed tests.

Verification

  • Java 17 / Maven 3.9.11: mvn -q install -pl codegen-core,codegen-roaster,processor -am -Dfmt.skip=true exited 0. Surefire XML totals: 1,394 tests, 0 failures, 0 errors, 0 skipped. Formatting was skipped to preserve the read-only worktree.
  • External probes explicitly call GenerationTargetValidator.validate before Roaster generation, then compile emitted Java with -Xlint:rawtypes -Xlint:unchecked. Enum-with-constructor and compact-record models validated but generated uncompilable source; the generic record validated but generation threw. Explicit canonical-record and simple-enum controls both compiled with 0 warnings, 0 errors. Top-level interface/record probes validated and compiled, but as classes; the annotation-element probe validated and compiled only after its modeled parameter/annotation were silently dropped.
  • git_pr_checks: 6 passed, 0 failed, 0 pending, 0 skipped, including JDK 17 and JDK 25. Retrieved JDK 25 job 146010693663 using git_ci_job_logs; Maven reports BUILD SUCCESS. Green CI does not cover the compiler failures above.
  • Checked specialized conditional callbacks: they receive the specialized builder, so the earlier illegal-callback-exposure concern is already resolved. The enum-constant collections now use unmodifiable views. EnumConstantDto.getArguments() remains explicitly documented as mutable; I am not assuming deep DTO immutability or counting that documented contract as a new defect.
  • No existing processor-generator behavior changes in this PR require example-builder regeneration; the additional public builder APIs are hand-maintained. No repository files were edited.

Other-PR integration review

Written by Devin


Recheck at 4a65d7d2 (2026-12-06)

Verdict: changes needed

# Original finding (short) Status Remaining action
1 Enum fields/constructors dropped fixed —
2 Compact-record assignments lost fixed; regression missing — minor Compile a compact-emulation constructor, including component reassignment (NestedTypeKindGenerationTest.java:92–121,283–298).
3 Generic-record crash Roaster backend gap — should be emulated in RoasterCodeGenerator like compact constructors Track/emulate generic headers in the backend (RoasterCodeGenerator.java:430–435); do not restrict the general model/validator.
4 Invalid/lost annotation-element state partially fixed — major Validator must reject void returns and generic element methods: invalid Java for every backend (GenerationTargetValidator.java:288–300).
5 Top-level kinds silently become classes fixed —
6 Test-source string convention partially fixed — nit Replace diagnostic concatenation with a formatted text block (NestedTypeKindGenerationTest.java:325–329).
N1 Literal %s in diagnostics open — minor Format the complete message and assert its values (RoasterCodeGenerator.java:166–169,432–435).
N2 Annotation-fix regressions missing open — minor Test parameter rejection and preserved annotation/Javadoc metadata (RoasterCodeGenerator.java:574–582).
N3 Wrong generic-record issue link open — minor Correct the link at RoasterCodeGenerator.java:432–435: forge/roaster#275 concerns compact constructors, not generics.

Build: Java 17 module install — BUILD SUCCESS; 1,397 tests, 0 failures/errors; void annotation probe still fails javac, generic element state is still dropped, generic records are rejected by Roaster.


Recheck at 0160611c (2026-12-06)

Verdict: changes needed

Severity What is missing Where (file:line)
major (backend) N1: Scope generic-record injection to declarations: valid return "record Box"; becomes return "record Box<T>"; (compiled probe). RoasterCodeGenerator.java:599–605

…roaster gap), compact-constructor component assignments
…lement metadata, validate element shapes and record generics
The validator stays generator-agnostic: other future generators may support
generic records. RoasterCodeGenerator now raises a generation error for
nested records with generic parameters (roaster limitation, forge/roaster#275).
Also drops the isFinal usage in the enum test (modifier modeling belongs to java-helpers#498).
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Strict-review follow-up plus review feedback in 8774484:

Verified: 358 core + 94 roaster tests green.

…record sources

Both probes compile the generated source with the system compiler and fail with
full diagnostics: the enum with constructor-binding constants (fields and
constructor assignments present) and the record component generation.
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Strict-review leftovers done: the nit (compact-constructor body fixture as text block) and the compile-probe regression tests — both the constructor-binding enum and the record generation now compile the generated source with the system compiler and fail with full diagnostics on regression. 10/10 green.

… validator

- Generic nested records: instead of a generation error, the generic header is now
  emulated — injected into the rendered record declaration, since Roaster's
  JavaRecordSource cannot model type variables. Emulated records compile.
- Compact-constructor emulation: the canonical rendering inherits the record's
  access modifier (compact constructors do implicitly), fixing javac's
  'invalid canonical constructor' rejection; regression test compiles the
  emulated constructor including component reassignment
- Validator rejects void/missing-return and generic annotation elements at top
  level and nested — illegal Java shapes for every backend
- Annotation element metadata: regression test proves javadoc and annotations
  survive rendering; nested element parameter rejection test added
- Literal-%s diagnostic fixed (formatted bound only the second concatenated
  literal); diagnostic concatenation converted to a text block
@igel-devin-ai

Copy link
Copy Markdown
Contributor Author

Recheck items addressed:

  • Generic records — Roaster workaround instead of error: the generation error is gone. The generic header is now emulated: Roaster renders the record plain and the type-parameter header (with bounds) is injected into the record declaration after rendering. Regression test verifies record Box<T>(T value) is emitted and the result compiles end-to-end. The wrong Compiler options should be possible to be set with -D without pom.xml -A mapping #275 link is gone with the error (275 correctly stays only on the compact-constructor warning, which is what it actually concerns — N3 moot)
  • Compact-emulation compile regression: the existing test now compiles the emulated constructor and asserts this.x = x; reassignment. This exposed a real emulation bug — the canonical rendering missed the record's access modifier (compact constructors inherit it implicitly), so javac rejected it as an invalid canonical constructor. Fixed: the emulation applies the record's visibility
  • Annotation elements: validator now rejects void/missing-return and generic element methods — top-level and nested — since these shapes are illegal Java for every backend. Parameter rejection was already there and now has a test. Element javadoc/annotation metadata preservation has a compile-verified regression test (N2)
  • N1 literal %s: real bug — .formatted bound only to the second concatenated literal, leaving the first %s unformatted in the top-level-kind error. Fixed
  • Nit: diagnostic concatenation in the compile probe converted to a text block

All green: validator 44/44, roaster incl. 11/11 kind tests.

…omplexity (S3776)

- appendAnnotationElements javadoc was orphaned by the header-injection insertion
- appendNestedType no longer declares CodeGenerationException (nothing throws it)
- kind-specific source creation and member appending extracted into helpers
- appendNestedTypes no longer declares CodeGenerationException (S1130)
- appendNestedMembers split further: shared fields/constructors loop extracted
  with generic holder bounds, annotation-element/method split separated (S3776)
@sonarqubecloud

sonarqubecloud Bot commented Dec 6, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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