Skip to content

fix: avoid splitting cast types before breaking after assignment operator - #1150

Open
RainyMarks wants to merge 1 commit into
jhipster:mainfrom
RainyMarks:fix/cast-generic-split-766
Open

RainyMarks wants to merge 1 commit into
jhipster:mainfrom
RainyMarks:fix/cast-generic-split-766

Conversation

@RainyMarks

Copy link
Copy Markdown

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 the softline inside 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 printAssignment and cast_expression to keep cast types inline via ifBreak(castGroup, removeLines(castGroup), { groupId }) while the assignment operator group is unbroken (unless castGroup itself 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 exceeds printWidth. resource in try-with-resources now delegates to printAssignment as well so it shares the same behavior.

Existing cases where the right-hand side breaks cleanly without exceeding printWidth before its break point (such as short left-hand sides with multi-line argument lists, switch expressions, or method chains) stay on the same line after = without breaking the cast type.

Example

Input

public abstract class Foo implements MyInterface {
	@Override
	public String foo() {
		Map<String, Map<String, Object>> deepCopy =
			(Map<String, Map<String, Object>>) Helpers.deepCopyOf(map);
	}
}

Output

public abstract class Foo implements MyInterface {

	@Override
	public String foo() {
		Map<String, Map<String, Object>> deepCopy =
			(Map<String, Map<String, Object>>) Helpers.deepCopyOf(map);
	}
}

Relative issues or prs:

Closes #766

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected split of generic arguments

1 participant