Repository navigation
fix: avoid splitting cast types before breaking after assignment operator - #1150
Open
RainyMarks wants to merge 1 commit into
Open
RainyMarks wants to merge 1 commit into
RainyMarks wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed with this PR:
When an assignment's right-hand side is a cast expression with a complex generic or intersection type (for example
(Map<String, Map<String, Object>>) Helpers.deepCopyOf(map)),printAssignment's fluid layout previously checked whether the line after=could fit up to the first inner break point and stopped at thesoftlineinside the cast type's type arguments or intersection bounds. As a result, the cast type was broken across multiple lines before breaking after=.This change updates
printAssignmentandcast_expressionto keep cast types inline viaifBreak(castGroup, removeLines(castGroup), { groupId })while the assignment operator group is unbroken (unlesscastGroupitself contains a forced break such as a line comment), propagating the assignment group ID across chained casts. Once the line breaks after=, the cast type remains free to break if it still exceedsprintWidth.resourcein try-with-resources now delegates toprintAssignmentas well so it shares the same behavior.Existing cases where the right-hand side breaks cleanly without exceeding
printWidthbefore its break point (such as short left-hand sides with multi-line argument lists,switchexpressions, or method chains) stay on the same line after=without breaking the cast type.Example
Input
Output
Relative issues or prs:
Closes #766