Skip to content

Conversation

@Lauriichan
Copy link
Contributor

@Lauriichan Lauriichan commented Jan 4, 2026

This adds an api to Roaster which allows to add/remove/get static initializers of enums, classes and records.

This should close #237

@Lauriichan Lauriichan changed the title Add api for static initializers (#237) Add api for static initializers (closes #237) Jan 4, 2026
@Lauriichan Lauriichan changed the title Add api for static initializers (closes #237) Add api for static initializers Jan 4, 2026
@gastaldi
Copy link
Member

gastaldi commented Jan 4, 2026

Looks good, but we need some tests also

@Lauriichan Lauriichan marked this pull request as draft January 4, 2026 20:02
@Lauriichan Lauriichan marked this pull request as ready for review January 4, 2026 20:36
@Lauriichan
Copy link
Contributor Author

Okay I have implemented some tests now, please tell me if anything is missing not up to standards :)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds API support for static initializers to Roaster, enabling users to add, retrieve, and remove initializer blocks for Java classes, enums, and records. This addresses issue #237 by introducing a comprehensive initializer management API.

Key changes:

  • Introduced new API interfaces (Initializer, InitializerHolder, InitializerSource, InitializerHolderSource) to represent and manage initializer blocks
  • Implemented initializer support in JavaClassImpl, JavaEnumImpl, and JavaRecordImpl with methods to add, get, and remove initializers
  • Added comprehensive test coverage for initializer functionality across all three Java type implementations

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
api/src/main/java/org/jboss/forge/roaster/model/Initializer.java New interface defining the base contract for initializer blocks with body retrieval
api/src/main/java/org/jboss/forge/roaster/model/InitializerHolder.java New interface for types that can contain initializers, providing getInitializers()
api/src/main/java/org/jboss/forge/roaster/model/source/InitializerSource.java Source-level initializer interface extending Initializer with setBody() capability
api/src/main/java/org/jboss/forge/roaster/model/source/InitializerHolderSource.java Source-level interface for adding and removing initializers
api/src/main/java/org/jboss/forge/roaster/model/JavaClass.java Updated to extend InitializerHolder interface
api/src/main/java/org/jboss/forge/roaster/model/JavaEnum.java Updated to extend InitializerHolder interface
api/src/main/java/org/jboss/forge/roaster/model/JavaRecord.java Updated to extend InitializerHolder interface
api/src/main/java/org/jboss/forge/roaster/model/source/JavaClassSource.java Updated to extend InitializerHolderSource interface
api/src/main/java/org/jboss/forge/roaster/model/source/JavaEnumSource.java Updated to extend InitializerHolderSource interface
api/src/main/java/org/jboss/forge/roaster/model/source/JavaRecordSource.java Updated to extend InitializerHolderSource interface
impl/src/main/java/org/jboss/forge/roaster/model/impl/InitializerImpl.java New implementation class handling initializer body parsing, static modifier management, and JavaDoc support
impl/src/main/java/org/jboss/forge/roaster/model/impl/JavaClassImpl.java Implements initializer management methods for classes
impl/src/main/java/org/jboss/forge/roaster/model/impl/JavaEnumImpl.java Implements initializer management methods for enums, includes formatting fix
impl/src/main/java/org/jboss/forge/roaster/model/impl/JavaRecordImpl.java Implements initializer management methods for records
tests/src/test/java/org/jboss/forge/test/roaster/model/JavaClassInitializerTest.java Tests for class initializer static flag operations
tests/src/test/java/org/jboss/forge/test/roaster/model/JavaEnumInitializerTest.java Tests for enum initializer static flag operations
tests/src/test/java/org/jboss/forge/test/roaster/model/JavaRecordInitializerTest.java Tests for record initializer static flag operations
tests/src/test/java/org/jboss/forge/test/roaster/model/InitializerBodyTest.java Tests for initializer body manipulation including lambdas and complex statements
tests/src/test/java/org/jboss/forge/test/roaster/model/InitializerImplementationTest.java Tests for initializer validation and error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gastaldi gastaldi merged commit 76fab90 into forge:master Jan 5, 2026
4 checks passed
@gastaldi
Copy link
Member

gastaldi commented Jan 5, 2026

Thanks! I'll cut a release later today

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.

Support static blocks in a type declaration

2 participants