Skip to content

refactor: Extract and centralize indentation logic in lexical preservation#4952

Merged
jlerbsc merged 4 commits into
javaparser:masterfrom
jlerbsc:indentationHandler
Jan 18, 2026
Merged

refactor: Extract and centralize indentation logic in lexical preservation#4952
jlerbsc merged 4 commits into
javaparser:masterfrom
jlerbsc:indentationHandler

Conversation

@jlerbsc

@jlerbsc jlerbsc commented Jan 18, 2026

Copy link
Copy Markdown
Collaborator

Overview
This PR extracts and centralizes indentation-related logic from the lexical preservation system into dedicated, well-tested utility classes. This is the first step in a larger effort to improve the maintainability and readability of the LexicalPreservingPrinter codebase.

Detail
Extract indentation-related logic from LexicalPreservingPrinter and Difference
into dedicated utility classes (IndentationCalculator, IndentationContext,
IndentationConstants) to improve maintainability and testability.

Key changes:

  • Create IndentationCalculator with stateless utility methods for indentation
    analysis, computation, and enforcement
  • Create IndentationContext for stateful indentation management
  • Create IndentationConstants to eliminate constant duplication
  • Refactor Observer.concretePropertyChange() to properly preserve indentation
    when inserting block comments
  • Update Difference to use centralized indentation utilities
  • Add comprehensive test coverage (69 new unit tests)

Bug fixes:

  • Fix indentation loss on line following block comment insertion
    (testFixIndentOfMovedNode now passes)

This is the first step in a larger refactoring effort to improve the
LexicalPreservingPrinter codebase maintainability.

@codecov

codecov Bot commented Jan 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.14286% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.459%. Comparing base (d014fe5) to head (b785eee).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
.../lexicalpreservation/LexicalPreservingPrinter.java 46.666% 15 Missing and 1 partial ⚠️
...ter/lexicalpreservation/IndentationCalculator.java 91.780% 2 Missing and 4 partials ⚠️
...nter/lexicalpreservation/IndentationConstants.java 0.000% 2 Missing ⚠️
...parser/printer/lexicalpreservation/Difference.java 90.000% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##              master     #4952       +/-   ##
===============================================
+ Coverage     58.394%   58.459%   +0.064%     
  Complexity      2564      2564               
===============================================
  Files            689       692        +3     
  Lines          39798     39891       +93     
  Branches        7244      7261       +17     
===============================================
+ Hits           23240     23320       +80     
- Misses         13605     13619       +14     
+ Partials        2953      2952        -1     
Flag Coverage Δ
AlsoSlowTests 58.459% <82.142%> (+0.064%) ⬆️
javaparser-core 58.459% <82.142%> (+0.064%) ⬆️
javaparser-symbol-solver 58.459% <82.142%> (+0.064%) ⬆️
jdk-10 58.028% <82.014%> (+0.064%) ⬆️
jdk-11 58.027% <82.014%> (+0.066%) ⬆️
jdk-12 58.027% <82.014%> (+0.064%) ⬆️
jdk-13 58.027% <82.014%> (+0.064%) ⬆️
jdk-14 58.260% <82.014%> (+0.083%) ⬆️
jdk-15 58.260% <82.014%> (+0.063%) ⬆️
jdk-16 58.235% <82.014%> (+0.063%) ⬆️
jdk-17 58.385% <82.014%> (+0.063%) ⬆️
jdk-18 58.385% <82.014%> (+0.063%) ⬆️
jdk-8 57.863% <82.142%> (+0.065%) ⬆️
jdk-9 58.023% <82.014%> (+0.061%) ⬆️
macos-latest 58.451% <82.142%> (+0.064%) ⬆️
ubuntu-latest 58.446% <82.142%> (+0.064%) ⬆️
windows-latest 58.441% <82.142%> (+0.064%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rinter/lexicalpreservation/IndentationContext.java 100.000% <100.000%> (ø)
...parser/printer/lexicalpreservation/Difference.java 77.737% <90.000%> (-0.532%) ⬇️
...nter/lexicalpreservation/IndentationConstants.java 0.000% <0.000%> (ø)
...ter/lexicalpreservation/IndentationCalculator.java 91.780% <91.780%> (ø)
.../lexicalpreservation/LexicalPreservingPrinter.java 74.514% <46.666%> (-3.363%) ⬇️

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e49ff3...b785eee. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jlerbsc jlerbsc merged commit 61d0928 into javaparser:master Jan 18, 2026
34 of 35 checks passed
@jlerbsc jlerbsc added this to the next release milestone Jan 18, 2026
@jlerbsc jlerbsc added the PR: Changed A PR that changes implementation without changing behaviour (e.g. performance) label Jan 18, 2026
@jlerbsc jlerbsc deleted the indentationHandler branch January 21, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Changed A PR that changes implementation without changing behaviour (e.g. performance)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant