Skip to content

Refactor ProjectGraphGenerator to expose read-only graph results #459

Description

@cdsap

Problem

ProjectGraphGenerator.generate() returns MutableList at project-generator/src/main/kotlin/io/github/cdsap/projectgenerator/ProjectGraphGenerator.kt:16, although callers only read the generated graph and ProjectGraph itself is immutable.

Why This Matters

The mutable return type leaks construction details across the domain boundary and permits callers to alter generated graph state after creation, increasing coupling and making behavior harder to reason about.

Proposed Change

Change generate() to return List while retaining a private mutable accumulator during construction. Add or update a focused test documenting that the generated graph is consumed as a read-only result.

Files

  • project-generator/src/main/kotlin/io/github/cdsap/projectgenerator/ProjectGraphGenerator.kt
  • project-generator/src/test/kotlin/io/github/cdsap/projectgenerator/ProjectGraphGeneratorTest.kt

Constraints

  • Preserve behavior.
  • Preserve graph contents, ordering, and generation behavior.
  • Preserve existing Kotlin style and public usage patterns where possible.
  • Do not redesign graph generation or introduce new frameworks.
  • Keep this as a small refactor; do not perform a broad architecture migration.
  • Do not change public APIs unless the issue explicitly requires it.

Acceptance Criteria

  • ProjectGraphGenerator exposes List rather than MutableList.
  • Existing graph-generation tests continue to pass unchanged or with only type-focused adjustments.
  • ./gradlew :project-generator:unitTest passes.
  • ./gradlew :cli:test passes.
  • ./gradlew ktlintCheck passes.
  • Existing behavior is preserved.

Validation

  • ./gradlew :project-generator:unitTest
  • ./gradlew :cli:test
  • ./gradlew ktlintCheck

Notes

This clarifies the domain boundary: graph construction remains internally mutable, while the generated graph is returned as an immutable domain result. Because the library is published, review downstream source compatibility before applying the signature change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureArchitecture, module boundaries, or dependency directionquality-codeGenerated by Hermes Quality Code for small architecture refactorsrefactorCode change that preserves behavior while improving structure

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions