Skip to content

Commit 0e6949e

Browse files
cushongoogle-java-format Team
authored andcommitted
Add baseline test cases for lambda hugging in google-java-format.
Add `LambdaHug.input` and its current formatting output in `LambdaHug.output` so that follow-up lambda hugging changes show the formatting diff against the existing behavior. PiperOrigin-RevId: 1000056807
1 parent 57967f7 commit 0e6949e

2 files changed

Lines changed: 215 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
class LambdaHug {
2+
void statements() {
3+
executor.submit(() -> { run(); });
4+
executor.submit(() -> { runSomethingThatIsLong(); runSomethingElseThatIsAlsoLong(); run(); });
5+
listenableFuture.addListener(() -> { System.err.println("done"); }, MoreExecutors.directExecutor());
6+
Futures.addCallback(future, new FutureCallback<Object>() { public void onSuccess(Object o) {} });
7+
foo.bar(firstArgument, secondArgument, (param1, param2) -> { return expr(param1, param2); });
8+
foo.bar(firstArgument, secondArgument, (param1, param2) -> param1.someLongMethodName(param2).another());
9+
foo.bar(someVeryLongFirstArgumentExpressionThatIsReallyLong, anotherVeryLongArgument, x -> { run(); });
10+
foo.bar(x -> {}, y -> { run(); runSomethingElseThatIsAlsoLong(); runSomethingElseThatIsAlsoLong(); });
11+
foo.bar(new Object[] {aaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb}, x -> { run(); run(); run(); });
12+
foo.bar((param1, param2) -> param1.someLongMethodName(param2).anotherLongMethodName().andAnotherOne());
13+
}
14+
15+
int returns() {
16+
return computeSomething(input, (a, b) -> { return a.combineWith(b).withSomethingElse(c); });
17+
}
18+
19+
void assignments() {
20+
Runnable r = executor.submit(() -> { runSomethingThatIsLong(); runSomethingElseThatIsAlsoLong(); });
21+
x = list.stream().map(element -> element.transformWithSomethingLong().andSomethingElse()).collect(toList());
22+
Runnable r = () -> { runSomethingThatIsLong(); runSomethingElseThatIsAlsoLong(); run(); };
23+
Comparator<String> c = new Comparator<String>() { public int compare(String a, String b) { return 0; } };
24+
listener = new Listener(someArgument, anotherArgument, yetAnotherArgumentThatIsLong) { void f() {} };
25+
callbacks += register(event -> { handle(event); handleAgain(event); handleOnceMore(event); });
26+
x = someObject.withSomeMethod(argument).andAnotherMethod(argument).thenAccept(y -> { consume(y); });
27+
ImmutableMap<String, SomeVeryLongTypeName<AnotherLongTypeName>> someLongVariableName = compute(k -> { return k; });
28+
}
29+
30+
private final Runnable field = () -> { runSomethingThatIsLong(); runSomethingElseThatIsAlsoLong(); };
31+
32+
void chains() {
33+
list.stream()
34+
.filter(x -> x.isSomethingThatIsLong() && x.isSomethingElseThatIsLong() && x.isThirdThing())
35+
.map(x -> { Object y = x.transform(); return y.transformAgainWithSomethingLonger(); })
36+
.forEach(System.out::println);
37+
CompletableFuture.supplyAsync(() -> computeSomethingExpensive(input, parameters)).thenAccept(result -> { consume(result); consumeAgain(result); });
38+
someObject.someModerateLengthFunctionName(foo -> doOtherModerateLengthName(foo, bar, baz, qux, quux));
39+
}
40+
41+
void nested() {
42+
outer(a -> inner(b -> innermost(c -> { doSomethingWith(a, b, c); doSomethingElseWith(a, b, c); })));
43+
}
44+
45+
void comments() {
46+
f(
47+
// comment
48+
x -> System.err.println("hello, world, this is a long string that doesn't fit on the line"));
49+
f(x -> { // trailing comment
50+
run();
51+
});
52+
}
53+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
class LambdaHug {
2+
void statements() {
3+
executor.submit(
4+
() -> {
5+
run();
6+
});
7+
executor.submit(
8+
() -> {
9+
runSomethingThatIsLong();
10+
runSomethingElseThatIsAlsoLong();
11+
run();
12+
});
13+
listenableFuture.addListener(
14+
() -> {
15+
System.err.println("done");
16+
},
17+
MoreExecutors.directExecutor());
18+
Futures.addCallback(
19+
future,
20+
new FutureCallback<Object>() {
21+
public void onSuccess(Object o) {}
22+
});
23+
foo.bar(
24+
firstArgument,
25+
secondArgument,
26+
(param1, param2) -> {
27+
return expr(param1, param2);
28+
});
29+
foo.bar(
30+
firstArgument,
31+
secondArgument,
32+
(param1, param2) -> param1.someLongMethodName(param2).another());
33+
foo.bar(
34+
someVeryLongFirstArgumentExpressionThatIsReallyLong,
35+
anotherVeryLongArgument,
36+
x -> {
37+
run();
38+
});
39+
foo.bar(
40+
x -> {},
41+
y -> {
42+
run();
43+
runSomethingElseThatIsAlsoLong();
44+
runSomethingElseThatIsAlsoLong();
45+
});
46+
foo.bar(
47+
new Object[] {aaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb},
48+
x -> {
49+
run();
50+
run();
51+
run();
52+
});
53+
foo.bar(
54+
(param1, param2) ->
55+
param1.someLongMethodName(param2).anotherLongMethodName().andAnotherOne());
56+
}
57+
58+
int returns() {
59+
return computeSomething(
60+
input,
61+
(a, b) -> {
62+
return a.combineWith(b).withSomethingElse(c);
63+
});
64+
}
65+
66+
void assignments() {
67+
Runnable r =
68+
executor.submit(
69+
() -> {
70+
runSomethingThatIsLong();
71+
runSomethingElseThatIsAlsoLong();
72+
});
73+
x =
74+
list.stream()
75+
.map(element -> element.transformWithSomethingLong().andSomethingElse())
76+
.collect(toList());
77+
Runnable r =
78+
() -> {
79+
runSomethingThatIsLong();
80+
runSomethingElseThatIsAlsoLong();
81+
run();
82+
};
83+
Comparator<String> c =
84+
new Comparator<String>() {
85+
public int compare(String a, String b) {
86+
return 0;
87+
}
88+
};
89+
listener =
90+
new Listener(someArgument, anotherArgument, yetAnotherArgumentThatIsLong) {
91+
void f() {}
92+
};
93+
callbacks +=
94+
register(
95+
event -> {
96+
handle(event);
97+
handleAgain(event);
98+
handleOnceMore(event);
99+
});
100+
x =
101+
someObject
102+
.withSomeMethod(argument)
103+
.andAnotherMethod(argument)
104+
.thenAccept(
105+
y -> {
106+
consume(y);
107+
});
108+
ImmutableMap<String, SomeVeryLongTypeName<AnotherLongTypeName>> someLongVariableName =
109+
compute(
110+
k -> {
111+
return k;
112+
});
113+
}
114+
115+
private final Runnable field =
116+
() -> {
117+
runSomethingThatIsLong();
118+
runSomethingElseThatIsAlsoLong();
119+
};
120+
121+
void chains() {
122+
list.stream()
123+
.filter(x -> x.isSomethingThatIsLong() && x.isSomethingElseThatIsLong() && x.isThirdThing())
124+
.map(
125+
x -> {
126+
Object y = x.transform();
127+
return y.transformAgainWithSomethingLonger();
128+
})
129+
.forEach(System.out::println);
130+
CompletableFuture.supplyAsync(() -> computeSomethingExpensive(input, parameters))
131+
.thenAccept(
132+
result -> {
133+
consume(result);
134+
consumeAgain(result);
135+
});
136+
someObject.someModerateLengthFunctionName(
137+
foo -> doOtherModerateLengthName(foo, bar, baz, qux, quux));
138+
}
139+
140+
void nested() {
141+
outer(
142+
a ->
143+
inner(
144+
b ->
145+
innermost(
146+
c -> {
147+
doSomethingWith(a, b, c);
148+
doSomethingElseWith(a, b, c);
149+
})));
150+
}
151+
152+
void comments() {
153+
f(
154+
// comment
155+
x ->
156+
System.err.println("hello, world, this is a long string that doesn't fit on the line"));
157+
f(
158+
x -> { // trailing comment
159+
run();
160+
});
161+
}
162+
}

0 commit comments

Comments
 (0)