You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An annotation with arguments on a lambda parameter forces a line break after it #101
Formatting a lambda whose parameter carries an annotation with arguments, such as @SuppressWarnings("unused"), breaks the parameter list across lines even when the whole statement fits in 120 columns.
Input
classT {
BiFunction<Integer, Integer, Integer> g = (finalvarx, @SuppressWarnings("unused") vary) -> x + y;
}
Output of main (2fbf175), the same on JDK 21, 25 and 27
classT {
BiFunction<Integer, Integer, Integer> g =
(finalvarx,
@SuppressWarnings("unused")
vary) -> x + y;
}
Expected
The input, unchanged. A lambda parameter is a parameter, and method parameters keep such an annotation on their line: void m(@SuppressWarnings("unused") int y) {} is left alone.
A marker annotation (@Deprecated var x) is already kept inline; it is the arguments that trigger the break. An explicit type instead of var, a block body or a second annotation make no difference.
Cause
JavaInputAstVisitor.visitLambdaExpression declares each parameter with inlineAnnotationDirection(parameter.getModifiers()), which answers VERTICAL for any annotation that has arguments, and a vertical annotation ends in a forced break. That rule is meant for local variable declarations, where
@SuppressWarnings("unchecked")
Function<Object, String> local = o -> (String) o;
is the wanted shape. Method parameters go through visitToDeclare(DeclarationKind.PARAMETER, Direction.HORIZONTAL, ...) instead, so their annotations stay inline.
Activity