Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 435242 - [1.8][lambda][formatter] inline comment shifts text over
Summary: [1.8][lambda][formatter] inline comment shifts text over
Status: VERIFIED DUPLICATE of bug 303519
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Mac OS X
: P3 minor with 7 votes (vote)
Target Milestone: 4.9 M2   Edit
Assignee: Mateusz Matela CLA
QA Contact:
URL:
Whiteboard: To be verified for 4.9 M2
Keywords:
Depends on:
Blocks:
 
Reported: 2014-05-19 23:16 EDT by Brandon Pedersen CLA
Modified: 2018-08-01 10:18 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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