Community
Participate
Working Groups
Placing a comment in a lambda causes following lines to be indented incorrectly: import java.util.stream.*; public class FormatBug { public void good(int[] output) { IntStream.range(0, output.length).parallel().forEach(p -> { System.out.println(output[p]); }); } public void bad(int[] output) { IntStream.range(0, output.length).parallel().forEach(p -> { // A comment System.out.println(output[p]); }); } }
Created attachment 242172 [details] Configuration used by Code Formatter
moving to 4.5
*** Bug 440620 has been marked as a duplicate of this bug. ***
Since this is not yet fixed, one could use block comments to work around the issue, e.g.: import java.util.stream.*; public class FormatBug { public void workaround(int[] output) { IntStream.range(0, output.length).parallel().forEach(p -> { /* A comment */ System.out.println(output[p]); }); } }
This issue has hit us too. This issue occurs as follows (formatted code): public class Bug433177 { public Function<String, String> testOK() { return foo((s) -> { // nothing System.out.println(""); return ""; }); } public Function<String, String> testBad() { return this.foo((s) -> { // nothing System.out.println(""); return ""; }); } public Function<String, String> foo(Function<String, String> f) { return null; } } Note the difference between invoking foo() vs this.foo(). The incorrect formatting indents all lines in the lambda block after the first comment. Subsequent comments are not further indented. In other words, the bug occurs when the lambda is passed directly to a method expression that includes a dot method invocation. Both // and /* */ comments are affected. We'd love to see a fix for this ;-)
From M6 (bug 303519 for formatter redesign) this issue is fixed. The Test case committed via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=43acf92f388300d5f01b9f356b08fd3725e374b7
(In reply to Manoj Palat from comment #6) > From M6 (bug 303519 for formatter redesign) this issue is fixed. The Test > case committed via > http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/ > ?id=43acf92f388300d5f01b9f356b08fd3725e374b7 *** This bug has been marked as a duplicate of bug 303519 ***
Verified for 4.5 RC1 using 20150514-1000 build