Community
Participate
Working Groups
In Eclipse 4.5m6, formatting the code below leaves all the contents of the line in a single line even if the setting "Never join already wrapped lines" is turned on. Note that this does not happen if the '+' from the string concatenation is on the other side (i.e.: + "b = 20\n" instead of "b = 20\n" +) package org.python.pydev.core.docutils; public class Test { public static void main(String[] args) { String docContents = "" + "a = 10\n" + "b = 20\n" + "c = 30\n"; } }
This will be fixed as part of bug 458208 comment 11 (I suggested a new setting, but it's too late for it). I have it implemented already and I planned to upload the complete patch after bug 462945 is pushed in.
Great! Thank you very much :)
I'm also experiencing this problem with "Eclipse IDE for Java Developers" Version: Mars Release Candidate 3 (4.5.0RC3) Build id: 20150604-1155 Hardware "Macintosh" "Mac OS X" I tested it with the example from Fabio and in both cases, '+' at the end or at the beginning of the line, it joins the lines to one line: Start: public class Test { public static void main(String[] args) { String docContents = "" + "a = 10\n" + "b = 20\n" + "c = 30\n"; } } Result: public class Test { public static void main(String[] args) { String docContents = "" + "a = 10\n" + "b = 20\n" + "c = 30\n"; } }
And in my opinion it is a major bug as it is extremely annoying. It can rewrite a lot of lines before one realises it.
(In reply to Stephan Leicht Vogt from comment #4) > And in my opinion it is a major bug as it is extremely annoying. It can > rewrite a lot of lines before one realises it. Hi Mateusz, please weigh in with your opinion. Thanks!
Well, my opinion is that it works :) Stephan, are you sure you've checked the "Never join already wrapped lines"? I just tested with RC4 (I20150603-2000): 1. start with completely new workspace 2. create a new formatter profile copying Eclipse[build-in], check "Never join already wrapped lines" 3. Create a new java project, paste example code from Fabio, add second main method from Stephan 4. Ctrl+Shift+F: none of the lines are joined
(In reply to Mateusz Matela from comment #6) > Well, my opinion is that it works :) > Stephan, are you sure you've checked the "Never join already wrapped lines"? You are right. I always tried it with my own project with a Formatter Profile heavily customised. If I try it your way it works. Comparing the two Formatter Profiles and beginning to set my options on the blank project I found the option which breaks the formatter: Expressions->Binary Expression. If I set this option to "Do not wrap" it joins the lines as described in this bug.
(In reply to Stephan Leicht Vogt from comment #7) > Expressions->Binary Expression. > If I set this option to "Do not wrap" it joins the lines as described in > this bug. So do you still consider this a problem? To me the current behavior seems logical. If you agree, I think we can close.
No, we can't close it. Here is another example which affects me even more as similar code exists many times in our code. public class Test { public static void main(String[] args) { StringBuilder docContentsBuilder = new StringBuilder(). append("a = 10\n"). append("b = 20\n"). append("c = 30\n"); } } I do not know how to set the formatter options so it doesn't join these lines to a single line.
For custom formatting like that the general advice is to use @formatter:off tags. You can also consider switching back to the old formatter: http://eclipse-n-mati.blogspot.com/2015/06/eclipse-mars-how-to-switch-back-to.html The reasons behind different behavior for "never join lines" is explained in bug 372801 and I don't think we're going to take a step back here.
Thanks for pointing me to both, the old formatter and the bug. The old formatter worked fine as it did the same as in luna. But reading the bug it pointed me to the other "solution". Line breaks will be kept intact "before '.' character in member access". This is great as I have to do only a small rewrite of my code so it will look like this: public class Test { public static void main(String[] args) { StringBuilder docContentsBuilder = new StringBuilder() .append("a = 10\n") .append("b = 20\n") .append("c = 30\n"); } } So for me all is fine and the bug can be closed.
I have "Never join already wrapped lines" checked. The following code: boolean retainRespondentAccessAfterDeliveryAndHasRespondentEmail = delivery.getForm().getRetainRespondentAccessAfterDelivery() && hasRespondentEmail; get formatted to boolean retainRespondentAccessAfterDeliveryAndHasRespondentEmail = delivery.getForm() .getRetainRespondentAccessAfterDelivery() && hasRespondentEmail; I'm running Eclipse Java EE IDE for Web Developers. Version: Mars Release (4.5.0). Build id: 20150621-1200.
(In reply to Kaj Hejer from comment #12) > I have "Never join already wrapped lines" checked. What about the wrapping policy for Expressions -> Assignments? If it's "Wrap where necessary", it should not remove the line break after the equal sign.
Thanks! For Expressions -> Assignments I had "Do not wrap". When I changed it do "Wrap where necessary" it did NOT rewrap my code. I find it a bit strange that the code gets rewrapped when I have "Do not wrap" but not when I have "Wrap where necessary".