Community
Participate
Working Groups
Build Identifier: 20110615-0604 With "Never join already wrapped lines" and Braces set to "Same line", users can circumvent the Brace style manually. This code: public static void main(String[] args) { System.out.println("hi"); } should instead look like this code since the Brace style is "Same line": public static void main(String[] args) { System.out.println("hi"); } Brace style should override "Never join already wrapped lines" I understand this is subjective (which style _should_ override the other?) but I want the brace style enforced and still prevent lines from auto-joining. Reproducible: Always Steps to Reproduce: 1. make a copy of the Eclipse [built in] formatter 2. Edit it and in "Line Wrapping" check "Never join already wrapped lines" 3. Write code with a brace on next line: public static void main(String[] args) { System.out.println("hi"); } 4. Run the formatter 5. Notice the brace is still on its own line EXPECTED: the formatter should move the brace so it's on the same line, after "args)"
I agree that it may be a bit of an inconvenience. Will investigate, time permitting.
Not unexpected, but this is not a Windows specific bug, can confirm also affecting Ubuntu. It is also affecting our team considerably due to us having company coding conventions and pre-commit hooks for subversion that enforce the coding standard. If you could point us in the right direction, we may be able to patch this.
You can try debugging /org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java and /org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java#printNewLine() and see where the formatter is inserting a new line before opening brace.
FWIW, I think the way it worked in Helios was the desired behaviour; I use that combination of settings, and Eclipse does the "right" thing (where right is, of course, subjective). A potential workaround is to put the // @formatter:off and // @formatter:on comments around blocks you don't want formatted, and then uncheck "never join", though if you have a lot of those, it's going to be cumbersome. My personal preference would be for line wrapping to have the lowest precedence after all the other line-wrap-affecting settings, like the braces settings, blank lines, new lines, control statements, and comments, etc.
(Also we're seeing this behavior on Mac and Windows, so as someone else also noted with Ubuntu, it's almost certainly not platform-dependent.)
(In reply to Nick Johnson from comment #4) > FWIW, I think the way it worked in Helios was the desired behaviour; I use > that combination of settings, and Eclipse does the "right" thing (where > right is, of course, subjective). > > A potential workaround is to put the // @formatter:off and // @formatter:on > comments around blocks you don't want formatted, and then uncheck "never > join", though if you have a lot of those, it's going to be cumbersome. > > My personal preference would be for line wrapping to have the lowest > precedence after all the other line-wrap-affecting settings, like the braces > settings, blank lines, new lines, control statements, and comments, etc. I agree that the old behavior is (subjectively) "right." I am surprised that this is listed as trivial - to ensure consistent code style across a team, the formatter should be able to fix simple things like brace location automatically, while respecting the 'never join lines' option to avoid the formatter making sweeping changes that potentially reduce code readability.
*** Bug 470433 has been marked as a duplicate of this bug. ***
This problem no longer occurs after the formatter redesign. *** This bug has been marked as a duplicate of bug 303519 ***