Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: compact lambda formatting #1

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,6 @@ public Void visitLabeledStatement(LabeledStatementTree node, Void unused) {
@Override
public Void visitLambdaExpression(LambdaExpressionTree node, Void unused) {
sync(node);
boolean statementBody = node.getBodyKind() == LambdaExpressionTree.BodyKind.STATEMENT;
boolean parens = builder.peekToken().equals(Optional.of("("));
builder.open(parens ? plusFour : ZERO);
if (parens) {
Expand All @@ -1256,12 +1255,7 @@ public Void visitLambdaExpression(LambdaExpressionTree node, Void unused) {
builder.close();
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(),
Expand All @@ -1271,7 +1265,6 @@ public Void visitLambdaExpression(LambdaExpressionTree node, Void unused) {
} else {
scan(node.getBody(), null);
}
builder.close();
return null;
}

Expand Down Expand Up @@ -3243,7 +3236,8 @@ void addTypeArguments(List<? extends Tree> typeArguments, Indent plusIndent) {
* @param plusIndent the extra indent for the arguments
*/
void addArguments(List<? extends ExpressionTree> arguments, Indent plusIndent) {
builder.open(plusIndent);
final boolean lambdaArg = arguments.size() == 1 && arguments.get(0) instanceof JCTree.JCLambda;
if (!lambdaArg) builder.open(plusIndent);
token("(");
if (!arguments.isEmpty()) {
if (arguments.size() % 2 == 0 && argumentsAreTabular(arguments) == 2) {
Expand Down Expand Up @@ -3277,12 +3271,12 @@ void addArguments(List<? extends ExpressionTree> arguments, Indent plusIndent) {
builder.close();
builder.close();
} else {
builder.breakOp();
if (!lambdaArg) builder.breakOp();
argList(arguments);
}
}
token(")");
builder.close();
if (!lambdaArg) builder.close();
}

private void argList(List<? extends ExpressionTree> arguments) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,9 @@ class B20128760 {
{
Stream<ItemKey> itemIdsStream =
stream(members)
.flatMap(
m ->
m.getFieldValues().entrySet().stream()
.filter(fv -> itemLinkFieldIds.contains(fv.getKey()))
.flatMap(
fv ->
FieldDTO.deserializeStringToListOfStrings(fv.getValue()).stream()
.map(
id ->
new ItemKey(
fieldsById.get(fv.getKey()).getItemTypeId(), id))));
.flatMap(m -> m.getFieldValues().entrySet().stream()
.filter(fv -> itemLinkFieldIds.contains(fv.getKey()))
.flatMap(fv -> FieldDTO.deserializeStringToListOfStrings(fv.getValue()).stream()
.map(id -> new ItemKey(fieldsById.get(fv.getKey()).getItemTypeId(), id))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,20 @@ class B21305044 {
{
Function f = () -> moderatelyLongResult;
Function f =
() ->
breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult;
() -> breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult
+ breakableResult;
Function f =
() ->
System.err.println(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
() -> System.err.println(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Function f =
(someParam) ->
System.err.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
(someParam) -> System.err.println(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
class B22873322 {
{
f(
param ->
veryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongExpr(
param));
f(
(param1, param2) ->
veryLooooooooooooooooooooooooooooooooooooooooooooooooongExpr(param1, param2));
f(
(int param) ->
veryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongExpr(param));
f(
(param1, param2) -> {
f(param -> veryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongExpr(
param));
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;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ class B33358723 {
{
f(
//
x ->
System.err.println(
//
"hello"));
x -> System.err.println(
//
"hello"));
f(
//
( //
x) ->
System.err.println(
//
"hello"));
x) -> System.err.println(
//
"hello"));
f(
//
(int //
x) ->
System.err.println(
//
"hello"));
x) -> System.err.println(
//
"hello"));
}
}