There was a problem hiding this comment.
This PR refactors core java-diff-utils classes to reduce coupling and cognitive complexity by extracting patching, inline diff annotation, delta normalization, and unified-diff parsing phases into focused helpers while keeping existing behavior intact.
Changes:
Copilot reviewed 18 out of 19 changed files in this pull request and generated 4 comments.
Show a summary per file| pom.xml | Formatting/lifecycle mapping adjustments (Spotless/m2e related) |
| java-diff-utils/src/main/java/com/github/difflib/DiffUtils.java | Slimmed diff façade; default algorithm now via DiffAlgorithmDefaults |
| java-diff-utils/src/main/java/com/github/difflib/PatchUtils.java | New patch/unpatch utility wrapper around Patch |
| java-diff-utils/src/main/java/com/github/difflib/InlineDiffUtils.java | New inline character-level diff utility |
| java-diff-utils/src/main/java/com/github/difflib/DiffAlgorithmDefaults.java | New default diff algorithm factory provider |
| java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffReader.java | Refactored parsing into header/file/chunk/tail phases |
| java-diff-utils/src/main/java/com/github/difflib/text/DiffRowGenerator.java | Reduced to orchestrator; delegates inline annotation and delta decompression |
| java-diff-utils/src/main/java/com/github/difflib/text/InlineTagRenderer.java | Extracted tag injection logic used by inline annotation |
| java-diff-utils/src/main/java/com/github/difflib/text/DeltaDecompressor.java | Extracted asymmetric ChangeDelta normalization logic |
| java-diff-utils/src/main/java/com/github/difflib/text/InlineDiffAnnotator.java | New dedicated inline token diff + tag application engine |
| java-diff-utils/src/main/java/com/github/difflib/text/InlineDiffAnnotatorConfig.java | New config carrier for inline annotator execution |
| java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffRoundTripTest.java | Updated patch application calls to PatchUtils |
| java-diff-utils/src/test/java/com/github/difflib/patch/PatchWithMyerDiffWithLinearSpaceTest.java | Updated patch application calls to PatchUtils |
| java-diff-utils/src/test/java/com/github/difflib/patch/PatchWithMyerDiffTest.java | Updated patch application calls to PatchUtils |
| java-diff-utils/src/test/java/com/github/difflib/patch/PatchWithAllDiffAlgorithmsTest.java | Updated patch application calls to PatchUtils |
| java-diff-utils/src/test/java/com/github/difflib/GenerateUnifiedDiffTest.java | Updated patch application calls to PatchUtils |
| java-diff-utils/src/test/java/com/github/difflib/examples/ApplyPatch.java | Updated example to use PatchUtils |
| java-diff-utils/src/test/java/com/github/difflib/DiffUtilsTest.java | Updated inline diff tests to use InlineDiffUtils |
| java-diff-utils/src/test/java/com/github/difflib/algorithm/myers/WithMyersDiffWithLinearSpacePatchTest.java | Updated patch application calls to PatchUtils |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
Refactor: Resolve High Coupling, God Class, and High Cognitive Complexity
This PR addresses three critical architectural code smells identified via PMD static analysis.
All changes are purely structural refactorings — zero changes to public APIs, method
signatures, or observable behavior.
Issues Addressed
1. High Object Coupling in DiffUtils.java (CBO Score: 29)
Problem: DiffUtils was directly coupled to 29 internal classes simultaneously, acting
as a monolithic control panel for algorithm engines, patch containers, and formatting
utilities. This made future algorithm changes risky and violated separation of concerns.
Fix — Delegation Pattern:
2. God Class in DiffRowGenerator.java (~780 lines, SRP Violation)
Problem: A single 780-line class simultaneously managed diff orchestration, HTML tag
rendering, and asymmetric delta normalization — three unrelated concerns that violated the
Single Responsibility Principle.
Fix — Single-Responsibility Decomposition:
lines vs 1 inserted) into uniform 1-to-1 row pairs for table rendering
configuration flags, eliminating parameter bloat
3. High Cognitive Complexity in UnifiedDiffReader.java (Score: 45 reduced to ~5)
Problem: The parse() method had a Cognitive Complexity score of 45 — three times the
allowed limit of 15 — caused by 4 levels of deeply nested while/if blocks and 16-parameter
vararg rule lists repeated across methods.
Fix — Phase-Driven Assembly Line Pattern:
and line-by-line additions/deletions
Files Changed
Design Principles Applied
Functional Validation
All existing tests pass with zero regressions. The 3 skipped tests are pre-existing
upstream skips entirely unrelated to this refactoring.