New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 762355 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Nov 27
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug

Blocked on:
issue 768586



Sign in to add a comment

clang-format doesn't handle single-statement Java lambdas very well

Project Member Reported by ntfschr@chromium.org, Sep 6 2017

Issue description

clang-format produced code that (choose all that apply): 
X Doesn't match Chromium style
- Doesn't match blink style
X Riles my finely honed stylistic dander
- No sane human would ever choose

Here's the code before formatting:
paramName -> {
    doSomething();
}

Here's the code after formatting:
paramName -> { doSomething(); }

Here's how it ought to look:
paramName -> doSomething()

Code review link for full files/context:

clank-team discussion: https://groups.google.com/a/google.com/forum/#!topic/clank-team/hKuyfkrPKcE

Example CL I encountered this on: https://chromium-review.googlesource.com/c/chromium/src/+/624996/3/android_webview/javatests/src/org/chromium/android_webview/test/SafeBrowsingTest.java#1023

In my example, I want to write a Java lambda for ValueCallback<Boolean> [1], which accepts a Boolean and returns void. I only need my lambda to call another void method (doSomething) for its side effects.

Our style guide [2] is vague on what to do for single-statement lambdas, however I suspect the "code after formatting" breaks chromium style because `git cl presubmit` gives the error:

'{' at column 14 should have line break after

We discussed this in the thread linked above, and nobody raised a strong opinion on "correct" stylistic format. Given that, I think acceptable solutions would be any of:

 * change clang-format to produce the "ought to look" output
 * relax git cl presubmit checks here, or
 * disable clang-format for this case

[1] https://developer.android.com/reference/android/webkit/ValueCallback.html
[2] https://chromium.googlesource.com/chromium/src/+/master/styleguide/java/java.md
 

Comment 1 by thakis@chromium.org, Sep 25 2017

Blockedon: 768576
Components: Tools
Blockedon: -768576 768586
Labels: clang-format
Status: Fixed (was: Assigned)

paramName -> {
    doSomething();
}

bar(() -> { baz(); });

I think this is better, I'm going to call it fixed.

Sign in to add a comment