Cohesion and coupling measured, RFC 0002 step 1 (0.18.0) #36

Merged
mi merged 2 commits from mihoe/cohesion-coupling-measure into main 2026-10-04 11:04:01 +02:00
Owner

Related Links

The Problem

werkcrappit showed how complex and how well tested a method is, but not how well a class holds together or how strongly classes depend on each other.

Non-Goals

  • The code city and the gate: RFC 0002 steps 2 and 3.
  • Any change of Mutation-CRAP.

The Scenarios

  • @MC-CK-001 to @MC-CK-006 as agreed for RFC 0002, in the new feature file 08-cohesion-coupling.feature.
  • @MC-CK-007, added while implementing: the component accessors, equals, hashCode and toString of a record count no more than generated methods.
    The first measurement of werkcrappit itself showed every record with an LCOM4 equal to its number of components, from 10 to 15, at the top of the list: javac generates these methods without the mark Lombok puts on its own.
Verified by

The Solution

  • A new package design: Cohesion reads the class files of a top-level class and its nested classes with ASM and connects methods by calls and shared instance fields; DesignAnalysis folds the references the edges already use onto the top-level classes for Ce and Ca.
  • The listener measures every class of the directory code roots at the end of the run, werkcrappit's excluded classes left out; ClassFiles.classNames moved from the CodeCharta export, which enumerates the code roots the same way.
  • mutation-crap.json has schema version 2 with the section classes; the gate and the export read version 2.
    mutation-crap.md lists the ten classes with the highest LCOM4, with their method groups, and the ten with the highest Ce.
  • ADR 0004 notes the new schema version.
  • Version 0.18.0.

Open Questions

  • werkcrappit measures itself with the listener of the same commit but judges with the released Gradle plugin, whose gate reads schema version 1: the nightly mutationCrapCheck of werkcrappit-pit fails until the plugin there is raised to 0.18.0, in the next PR.
  • Methods that use no field and call nothing are a group each; MutationCrapListenerFactory has LCOM4 3 for name, description and getListener.
    Whether such stateless methods should count is a question for the limits of step 3, with the numbers of hsadmin-ng at hand.

Attachments

werkcrappit-pit measured by itself

58 top-level classes, 28 with methods to judge: 19 with LCOM4 1, 6 with 2, 3 with 3.
The highest Ce: MutationCrapListener 21, CodeChartaExport 17, JsonReport 12.

🤖 Generated with Claude Code

## Related Links - [RFC 0002](../rfcs/0002-cohesion-and-coupling.md), step 1 ## The Problem werkcrappit showed how complex and how well tested a method is, but not how well a class holds together or how strongly classes depend on each other. ## Non-Goals - The code city and the gate: RFC 0002 steps 2 and 3. - Any change of Mutation-CRAP. ## The Scenarios - `@MC-CK-001` to `@MC-CK-006` as agreed for RFC 0002, in the new feature file `08-cohesion-coupling.feature`. - `@MC-CK-007`, added while implementing: the component accessors, `equals`, `hashCode` and `toString` of a record count no more than generated methods. The first measurement of werkcrappit itself showed every record with an LCOM4 equal to its number of components, from 10 to 15, at the top of the list: javac generates these methods without the mark Lombok puts on its own. ##### Verified by - [DesignAnalysisTest](../../werkcrappit-pit/src/test/java/de/javagil/werkcrappit/pit/design/DesignAnalysisTest.java), one test per scenario `@MC-CK-001` to `@MC-CK-005` and `@MC-CK-007` - [MutationCrapListenerTest](../../werkcrappit-pit/src/test/java/de/javagil/werkcrappit/pit/listener/MutationCrapListenerTest.java) `theReportCarriesCohesionAndCouplingOfEveryClass` for `@MC-CK-006` ## The Solution - A new package `design`: `Cohesion` reads the class files of a top-level class and its nested classes with ASM and connects methods by calls and shared instance fields; `DesignAnalysis` folds the references the edges already use onto the top-level classes for Ce and Ca. - The listener measures every class of the directory code roots at the end of the run, werkcrappit's excluded classes left out; `ClassFiles.classNames` moved from the CodeCharta export, which enumerates the code roots the same way. - `mutation-crap.json` has schema version 2 with the section `classes`; the gate and the export read version 2. `mutation-crap.md` lists the ten classes with the highest LCOM4, with their method groups, and the ten with the highest Ce. - ADR 0004 notes the new schema version. - Version 0.18.0. ## Open Questions - werkcrappit measures itself with the listener of the same commit but judges with the released Gradle plugin, whose gate reads schema version 1: the nightly `mutationCrapCheck` of werkcrappit-pit fails until the plugin there is raised to 0.18.0, in the next PR. - Methods that use no field and call nothing are a group each; `MutationCrapListenerFactory` has LCOM4 3 for `name`, `description` and `getListener`. Whether such stateless methods should count is a question for the limits of step 3, with the numbers of hsadmin-ng at hand. ## Attachments ### werkcrappit-pit measured by itself 58 top-level classes, 28 with methods to judge: 19 with LCOM4 1, 6 with 2, 3 with 3. The highest Ce: `MutationCrapListener` 21, `CodeChartaExport` 17, `JsonReport` 12. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mi added 2 commits 2026-10-04 11:00:35 +02:00
mi merged commit b404166da3 into main 2026-10-04 11:04:01 +02:00
mi deleted branch mihoe/cohesion-coupling-measure 2026-10-04 11:04:01 +02:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mi/werkcrappit#36