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

Bug 472296

Summary: [formatter] Inconsistent indentation depending on line comment
Product: [Eclipse Project] JDT Reporter: Roland Illig <rillig>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: javabrett, mateusz.matela
Version: 4.5   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Roland Illig CLA 2015-07-09 12:07:25 EDT
I have the following code:

public class Asdf {

    public static void main(String[] args) {
        String s1 = //
        "hello";
        String s2 =
                "hello";
    }
}

I am using the standard Eclipse formatting, with one change:
[x] Never join already wrapped lines

The declaration of s1 is not indented, while the declaration of s2 is.
Both should be indented in the same way, like s2.
Comment 1 Mateusz Matela CLA 2015-08-05 18:49:42 EDT
I can't reproduce your results when I test it.
In the standard Eclipse formatter profile, the configuration for Line Wrapping -> Expressions -> Assignments is "Do not wrap". In that case wrapping after '=' is not allowed even with "Never join lines" (as discussed in bug 372801), so s2 is joined into a single line and s1 is not indented because that new line is not considered a proper wrapping.

If the Assignments wrapping policy is changed to "Wrap where necessary", then s1 gets indented the same way as s2.

If you really get the behavior you described, please provide your formatter profile - maybe some other option affects this behavior.
Comment 2 Roland Illig CLA 2015-08-06 03:42:37 EDT
(In reply to Mateusz Matela from comment #1)
> If you really get the behavior you described, please provide your formatter
> profile - maybe some other option affects this behavior.

I tried it again with a freshly installed eclipse-jee-mars-R-win32-x86_64.zip, and I cannot reproduce it. I get the same behavior as you.

I accidentally reported this bug against 4.5 Mars, when I was really using 4.4 Luna. Since I won’t be using Luna anymore, I’m closing this bug.

Thank you for looking into this and explaining the “not a proper wrapping” thing.