diff --git a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java index 5bce89e7a..7195b1097 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java @@ -1185,11 +1185,7 @@ public Void visitLambdaExpression(LambdaExpressionTree node, Void unused) { builder.space(); builder.op("->"); builder.open(statementBody ? ZERO : plusFour); - if (statementBody) { - builder.space(); - } else { - builder.breakOp(" "); - } + builder.space(); if (node.getBody().getKind() == Tree.Kind.BLOCK) { visitBlock( (BlockTree) node.getBody(), @@ -2793,7 +2789,13 @@ void addArguments(List arguments, Indent plusIndent) { builder.close(); builder.close(); } else { - builder.breakOp(); + if (arguments.size() == 1) { + if (!(arguments.get(0) instanceof JCTree.JCLambda)) { + builder.breakOp(); + } + } else { + builder.breakOp(); + } argList(arguments); } } diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B20128760.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B20128760.output index 0e043fe32..12316c98e 100644 --- a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B20128760.output +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B20128760.output @@ -89,19 +89,13 @@ class B20128760 { { Stream itemIdsStream = stream(members) - .flatMap( - m -> - m.getFieldValues() + .flatMap(m -> m.getFieldValues() .entrySet() .stream() .filter(fv -> itemLinkFieldIds.contains(fv.getKey())) - .flatMap( - fv -> - FieldDTO.deserializeStringToListOfStrings(fv.getValue()) + .flatMap(fv -> FieldDTO.deserializeStringToListOfStrings(fv.getValue()) .stream() - .map( - id -> - new ItemKey( + .map(id -> new ItemKey( fieldsById.get(fv.getKey()).getItemTypeId(), id)))); } } diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B21305044.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B21305044.output index 32296d215..1c77d554b 100644 --- a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B21305044.output +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B21305044.output @@ -37,8 +37,7 @@ class B21305044 { { Function f = () -> moderatelyLongResult; Function f = - () -> - breakableResult + () -> breakableResult + breakableResult + breakableResult + breakableResult @@ -48,11 +47,10 @@ class B21305044 { + breakableResult + breakableResult; Function f = - () -> - System.err.println( + () -> System.err.println( "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); Function f = - (someParam) -> - System.err.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + (someParam) -> System.err.println( + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); } } diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B22873322.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B22873322.output index 776838319..8c1825d85 100644 --- a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B22873322.output +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B22873322.output @@ -1,21 +1,15 @@ class B22873322 { { - f( - param -> - veryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongExpr( + f(param -> veryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongExpr( param)); - f( - (param1, param2) -> - veryLooooooooooooooooooooooooooooooooooooooooooooooooongExpr(param1, param2)); - f( - (int param) -> - veryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongExpr(param)); - f( - (param1, param2) -> { + f((param1, param2) -> veryLooooooooooooooooooooooooooooooooooooooooooooooooongExpr( + param1, param2)); + f((int param) -> veryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongExpr( + param)); + f((param1, param2) -> { return expr(param1, param2); }); - f( - (param1, param2) -> { + f((param1, param2) -> { Object foo = expr(param1, param2); return foo; }); diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B33358723.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B33358723.output index da0000ce1..8bdc872c6 100644 --- a/core/src/test/resources/com/google/googlejavaformat/java/testdata/B33358723.output +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/B33358723.output @@ -2,22 +2,19 @@ class B33358723 { { f( // - x -> - System.err.println( + x -> System.err.println( // "hello")); f( // ( // - x) -> - System.err.println( + x) -> System.err.println( // "hello")); f( // (int // - x) -> - System.err.println( + x) -> System.err.println( // "hello")); }