Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 435242

Summary: [1.8][lambda][formatter] inline comment shifts text over
Product: [Eclipse Project] JDT Reporter: Brandon Pedersen <bpedman>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: VERIFIED DUPLICATE QA Contact:
Severity: minor    
Priority: P3 CC: guillaume.anctil, joffrey.bion, manoj.palat, mateusz.matela, Vikas.Chandra
Version: 4.4   
Target Milestone: 4.9 M2   
Hardware: PC   
OS: Mac OS X   
Whiteboard: To be verified for 4.9 M2

Description Brandon Pedersen CLA 2014-05-19 23:16:49 EDT
Overview: 
If I have an inline comment inside a lambda it gets incorrectly formatted

Steps To Reproduce:
- Create a simple test that has an inline comment inside a lambda, like so:

Executors.newSingleThreadExecutor().execute(() -> {
  // this is a comment
    System.err.println("this shouldn't be here");
  });

Actual results:
Not sure if bugzilla will format this correctly but the above example is what I see. The line under the comment is shifted to the right when it shouldn't be.

Expected results:
The line under the comment should be directly under the comment in the same column. I would also expect the closing brace and parenthesis to be shifted over to the left to align with where the initial statement begins.

Build:
Has been happening on Kepler with java 8 patches as well as the 4.4 nightly/integration builds with java 8 added (on a Mac)

See also:
bug 435241 - Very similar behavior but with if/else statements
Comment 1 Guillaume Anctil CLA 2014-07-04 13:48:14 EDT
Here's another example of bad behavior:

Executors.newSingleThreadExecutor().execute(() -> {
    System.err.println("this is ok"); // this is a comment
        System.err.println("this shouldn't be here");
        System.err.println("this shouldn't be here");
        System.err.println("this shouldn't be here"); // another comment
        System.err.println("this shouldn't be here"); // text only get shifted once for the whole lambda block
    });

When using multiline comments /* */, everything is fine.
Comment 2 Joffrey Bion CLA 2015-04-04 02:33:35 EDT
I stumbled upon the same problem. After a little investigation, I found that the indentation bug appears only in lambdas within a chained method call, not in simple method calls:

        new Sandbox().test(i -> {
            // test
                System.out.println("extra indent");
            });

        new Sandbox().test(i -> {
            System.out.println("no bug");
        });

        testStatic(i -> {
            //test
            System.out.println("no bug");
        });

        testStatic(i -> {
            System.out.println("no bug");
        });
Comment 3 Mateusz Matela CLA 2018-07-23 17:15:39 EDT
This problem no longer occurs, (probably) after the formatter redesign.

*** This bug has been marked as a duplicate of bug 303519 ***
Comment 4 Vikas Chandra CLA 2018-08-01 10:18:18 EDT
verified on

Version: 4.9
Build id: I20180731-1305