Skip to content

Commit

Permalink
Revert lambda compactness regression
Browse files Browse the repository at this point in the history
This reverts #708 and #707 which made expression lambdas less
readable.
  • Loading branch information
carterkozak committed Apr 28, 2022
1 parent 923d577 commit eb18b66
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import static com.sun.source.tree.Tree.Kind.BLOCK;
import static com.sun.source.tree.Tree.Kind.EXTENDS_WILDCARD;
import static com.sun.source.tree.Tree.Kind.IF;
import static com.sun.source.tree.Tree.Kind.LAMBDA_EXPRESSION;
import static com.sun.source.tree.Tree.Kind.METHOD_INVOCATION;
import static com.sun.source.tree.Tree.Kind.NEW_ARRAY;
import static com.sun.source.tree.Tree.Kind.NEW_CLASS;
Expand Down Expand Up @@ -107,7 +106,6 @@
import com.sun.source.tree.IntersectionTypeTree;
import com.sun.source.tree.LabeledStatementTree;
import com.sun.source.tree.LambdaExpressionTree;
import com.sun.source.tree.LambdaExpressionTree.BodyKind;
import com.sun.source.tree.LiteralTree;
import com.sun.source.tree.MemberReferenceTree;
import com.sun.source.tree.MemberSelectTree;
Expand Down Expand Up @@ -2785,13 +2783,7 @@ private void visitRegularDot(List<ExpressionTree> items, boolean needDot) {
int length = needDot0 ? minLength : 0;
for (ExpressionTree e : items) {
if (needDot) {
// Also break if invoked with a multi-statement lambda -- palantir-break-lambda-arg
// foo
// .doSomething(() -> {
// bar();
// })
// .doSomethingElse();
if (length > minLength || methodHasMultiStatementLambdaArg(e)) {
if (length > minLength) {
builder.breakOp(Break.builder()
.fillMode(FillMode.UNIFIED)
.flat("")
Expand All @@ -2816,17 +2808,6 @@ private void visitRegularDot(List<ExpressionTree> items, boolean needDot) {
}
}

private boolean methodHasMultiStatementLambdaArg(ExpressionTree e) {
if (!e.getKind().equals(METHOD_INVOCATION)) {
return false;
}
return ((MethodInvocationTree) e)
.getArguments().stream()
.filter(argExpr -> argExpr.getKind().equals(LAMBDA_EXPRESSION))
.map(argExpr -> (LambdaExpressionTree) argExpr)
.anyMatch(lambda -> lambda.getBodyKind().equals(BodyKind.STATEMENT));
}

// avoid formattings like:
//
// when(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class PalantirLambdaBreakChain {
void foo() {
return hello
.read(txn -> {
return hello.read(txn -> {
doSomeWork();
doSomeMoreWork();
})
Expand Down

0 comments on commit eb18b66

Please sign in to comment.