mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 00:16:47 +00:00
[Fixes #972] 1-arg lambdas with explicit typing on the argument did not pretty print correctly.
This commit is contained in:
1 parent
e05feead3f
commit
ba2cde332a
4 files changed
+33
-4
No files matched your search
@@ -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).
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -4,4 +4,15 @@ public class Lambda {
|
||||
java.util.Comparator<Integer> c2 = (Integer a, Integer b) -> {
|
||||
return a - b;
|
||||
};
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -5,4 +5,20 @@ public class Lambda {
|
||||
java.util.Comparator<Integer> c2 = (Integer a, Integer b) -> {
|
||||
return a - b;
|
||||
};
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user