diff options
-rw-r--r-- | doc/changelog.markdown | 1 | ||||
-rw-r--r-- | src/delombok/lombok/delombok/PrettyPrinter.java | 5 | ||||
-rw-r--r-- | test/pretty/resource/after/Lambda.java | 13 | ||||
-rw-r--r-- | test/pretty/resource/before/Lambda.java | 18 |
4 files changed, 33 insertions, 4 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown index d5850457..552ce261 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -6,6 +6,7 @@ Lombok Changelog * FEATURE: `@Builder` updates: The annotation can now be put on instance methods. [Issue #63](https://github.com/rzwitserloot/lombok/issues/63). * FEATURE: `@Builder` updates: `@Singular` now supports guava's ImmutableTable [Issue #937](https://github.com/rzwitserloot/lombok/issues/937). * FEATURE: A `lombok.config` key can now be used to make your fields `final` and/or `private`... __everywhere__. We'll be monitoring the performance impact of this for a while. We'll touch every source file if you turn these on, and even if you don't, we have to call into the lombok config system for every file. +* BUGFIX: lambdas with 1 argument that has an explicit type did not pretty print correctly. [Issue #972](https://github.com/rzwitserloot/lombok/issues/972). * BUGFIX: `@Value` and `@FieldDefaults` no longer make uninitialized static fields final. [Issue #928](https://github.com/rzwitserloot/lombok/issues/928). * BUGFIX: When using delombok, a source file with only `@NonNull` annotations on parameters as lombok feature would not get properly delomboked. [Issue #950](https://github.com/rzwitserloot/lombok/issues/950). * ENHANCEMENT: Putting `@NonNull` on a parameter of an abstract method no longer generates a warning, to allow you to use this annotation to document intended behaviour [Issue #807](https://github.com/rzwitserloot/lombok/issues/807). diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index d3b65cb8..38af8b16 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -1438,10 +1438,11 @@ public class PrettyPrinter extends JCTree.Visitor { List<JCVariableDecl> params = readObject(tree, "params", List.<JCVariableDecl>nil()); boolean explicit = true; int paramLength = params.size(); - if (paramLength != 1) print("("); try { explicit = readObject(tree, "paramKind", new Object()).toString().equals("EXPLICIT"); } catch (Exception e) {} + boolean useParens = paramLength != 1 || explicit; + if (useParens) print("("); if (explicit) { boolean first = true; for (JCVariableDecl vd : params) { @@ -1457,7 +1458,7 @@ public class PrettyPrinter extends JCTree.Visitor { sep = ", "; } } - if (paramLength != 1) print(")"); + if (useParens) print(")"); print(" -> "); JCTree body = readObject(tree, "body", (JCTree) null); if (body instanceof JCBlock) { diff --git a/test/pretty/resource/after/Lambda.java b/test/pretty/resource/after/Lambda.java index 54d7caa0..949c4c04 100644 --- a/test/pretty/resource/after/Lambda.java +++ b/test/pretty/resource/after/Lambda.java @@ -4,4 +4,15 @@ public class Lambda { java.util.Comparator<Integer> c2 = (Integer a, Integer b) -> { return a - b; }; -}
\ No newline at end of file + java.util.function.Function<String, String> fnc = (String c) -> c; + void testLambdaInArgsList(String name, java.util.function.Function<String, String> f) { + } + void testLambdaInArgsList2(java.util.function.Function<String, String> f, String name) { + } + void test() { + testLambdaInArgsList("hello", (String c) -> c); + testLambdaInArgsList("hello", c -> c); + testLambdaInArgsList2((String c) -> c, "hello"); + testLambdaInArgsList2(c -> c, "hello"); + } +} diff --git a/test/pretty/resource/before/Lambda.java b/test/pretty/resource/before/Lambda.java index e7784df5..b9f8c719 100644 --- a/test/pretty/resource/before/Lambda.java +++ b/test/pretty/resource/before/Lambda.java @@ -5,4 +5,20 @@ public class Lambda { java.util.Comparator<Integer> c2 = (Integer a, Integer b) -> { return a - b; }; -}
\ No newline at end of file + java.util.function.Function<String, String> fnc = (String c) -> c; + + void testLambdaInArgsList(String name, java.util.function.Function<String, String> f) { + + } + + void testLambdaInArgsList2(java.util.function.Function<String, String> f, String name) { + + } + + void test() { + testLambdaInArgsList("hello", (String c) -> c); + testLambdaInArgsList("hello", c -> c); + testLambdaInArgsList2((String c) -> c, "hello"); + testLambdaInArgsList2(c -> c, "hello"); + } +} |