Keep an annotated lambda parameter on its line - #103
Merged
Merged
Conversation
An annotation with arguments on a lambda parameter, such as `(final var x, @SuppressWarnings("unused") var y) -> x + y`, forced a line break after the annotation, so a statement that fits in 120 columns came out as four lines. visitLambdaExpression declared each parameter with inlineAnnotationDirection, which answers VERTICAL, a forced break, for any annotation that has arguments. That rule is for local variable declarations, where the annotation above the type is the wanted shape. Method parameters are declared with Direction.HORIZONTAL and keep their annotations inline; lambda parameters now do the same. Golden ojf-issue-101-annotated-lambda-parameters covers the broken shape, a one-line input, two annotations, marker annotations, a block body, a lambda too long for one line and one whose parameters do not fit, with a method parameter and a local variable as controls. The JDK 21 and 25 sources format exactly as before: they have no lambda parameter with an annotation that takes arguments. Closes #101.
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.
Closes #101.
An annotation with arguments on a lambda parameter,
(final var x, @SuppressWarnings("unused") var y) -> x + y, forced a line break after the annotation, so a statement that fits in 120 columns came out as four lines:visitLambdaExpressiondeclared each parameter withinlineAnnotationDirection, which answersVERTICAL, a forced break, for any annotation that has arguments. That rule is for local variable declarations, where the annotation above the type is the wanted shape. Method parameters are declared withDirection.HORIZONTALand keep their annotations inline; lambda parameters now do the same. One line inJavaInputAstVisitor.Golden
ojf-issue-101-annotated-lambda-parameters, every statement in a different input shape: the four-line output above, one line with odd spacing, two annotations split before the type, marker annotations (already inline, as a regression guard), a block body, a lambda too long for one line (it breaks after->, as an unannotated one does) and one whose parameters do not fit on a line (one per line, each annotation on its parameter's line). A method parameter and a local variable serve as controls: the local keeps its annotation above the type. The golden fails on main in all four runs of the integration test and passes with the change.Checks
:open-java-format:teston JDK 21 and 27: 0 failures.Both upstreams carry the same code, palantir/palantir-java-format on
developand google/google-java-format, where the method isfieldAnnotationDirection; neither tracker has a report of it.