Skip to content

processor: decouple codegen layer from builder internals (phase 0) - #299

Open
igel-devin-ai wants to merge 1 commit into
java-helpers:mainfrom
igel-devin-ai:devin/1790369750-codegen-decoupling
Open

igel-devin-ai wants to merge 1 commit into
java-helpers:mainfrom
igel-devin-ai:devin/1790369750-codegen-decoupling

Conversation

@igel-devin-ai

@igel-devin-ai igel-devin-ai commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #347. Part of #233.

Pure refactor, zero behavior change — decouples the code-generation layer inside processor so it no longer depends on builder-specific internals. This is Phase 0 of extracting a reusable simple-codegen library (~40 files) into its own module/artifact: do the decoupling before any git mv so the move commits stay rename-safe.

  • ClassCodeGenerator SPI (new): BuilderProcessor now talks to the generator through the interface. RoasterCodeGenerator implements it and receives a GenerationEnvironment (processing environment, logger, performance tracker, GenerationIssueReporter) plus a RoasterSourceFormatterFactory instead of the whole ProcessingContext. Strict-mode reporting keeps its semantics via context::reportBasedOnStrictMode wired as the issue reporter.
  • MapperOptions record (new): carries the mapper's needs (copyTypeAnnotations flag + a generated-type resolver function), replacing mapper reads of the builder scope resolver and the builder configuration. BuilderDefinitionCreator supplies them in one place.
  • findConstructorForBuilder takes the constructor marker annotation as a parameter instead of hardcoding SimpleBuilderConstructor (the builder caller passes it in).
  • ProcessingLogger no longer reads compiler options itself: a private Verbosity enum plus a verbose(ProcessingEnvironment) named factory replace the implicit flag — callers decide the verbosity; the -Averbose option is read once in BuilderProcessor.
  • CompilerOption interface (new) decouples CompilerArgumentsReader from the builder option enum; readBuilderConfiguration moved to BuilderConfigurationReader next to the other configuration sources.
  • Phase constants moved out of PerformanceTracker (now a pure protocol) into ProcessingPhases (pipeline phases + hierarchy) and GenerationPhases (codegen sub-phases); ActivePerformanceTracker takes them as constructor arguments.

Out of scope (next PRs)

  • Splitting ProcessingContext into a generic AnnotationProcessingContext + builder-specific context (separate PR — it touches many files on its own).
  • History-preserving git mv of the decoupled classes into simple-codegen / simple-codegen-roaster modules (Phase 1).

Test plan

  • mvn test -pl processor — all 528 tests pass
  • mvn -pl example clean compile — regenerated generated-example-builder/ tree is byte-identical (confirms zero behavior change)
  • license:check — all new files carry the license header

@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1790369750-codegen-decoupling branch from 353c73d to 4dde491 Compare September 25, 2026 21:23
Introduce a small SPI seam inside the processor so the Roaster-based code
generator and the analysis helpers no longer depend on builder internals:

- ClassCodeGenerator SPI: BuilderProcessor now talks to the generator through
  the interface; RoasterCodeGenerator implements it and receives a
  GenerationEnvironment (processing environment, logger, performance tracker,
  issue reporter) plus a RoasterSourceFormatterFactory instead of the whole
  ProcessingContext.
- GenerationIssueReporter abstracts strict-mode reporting out of the context.
- MapperOptions record carries the mapper's needs (copyTypeAnnotations flag +
  generated-type resolver function), replacing mapper reads of the builder
  scope resolver and configuration; BuilderDefinitionCreator supplies them.
- findConstructorForBuilder takes the constructor marker annotation as a
  parameter instead of hardcoding SimpleBuilderConstructor.
- ProcessingLogger no longer reads compiler options itself: a private
  Verbosity enum plus a verbose(ProcessingEnvironment) factory replace the
  implicit flag (callers decide the verbosity; the -Averbose option is read
  once in BuilderProcessor).
- CompilerOption interface decouples CompilerArgumentsReader from the builder
  option enum; readBuilderConfiguration moved to BuilderConfigurationReader.
- Phase constants moved out of the PerformanceTracker protocol into
  ProcessingPhases (pipeline phases + hierarchy) and GenerationPhases (codegen
  sub-phases); ActivePerformanceTracker takes them as constructor arguments.

No behavior change: generated example builders are unchanged.

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.

Decouple codegen layer from builder internals in processor (phase 0)

1 participant