Community
Participate
Working Groups
In Preferences>Java>Code Style>Formatter>Edit Set Maximum line width to 80 Format (Ctrl-Shift-F) a file with lines such as: reordered = new TreeSet( new DeprecatedAndLengthFirstComparator("territory"); This line gets joined into a single line, which exceeds 80 characters, breaking the limit that was just set. This makes it unusable on systems that have an 80 character limit, like ours, since you then have to go back by hand and repair all of the lines that Format has screwed up. (What makes this worse is that Format operates on the whole file, instead of the the selection. If the command were limited to the selection, at least the user could apply Format to a single method or part of a method, and not have to go back and fix everything else in the file.)
>What makes this worse is that Format operates on the whole file, instead of >the the selection It DOES operate on the selection but when none is present it formats the file. no plans to change this.
Could you please provide your formatter settings?
(In reply to comment #2) > Could you please provide your formatter settings? Is there a way to dump them all at once into a format that you can use, or do I need to go through the UI and record each and every setting? If the latter, are there particular ones that I can concentrate on? As to Format working on selections, that's not what I see happening. Take the following: * Note that it is quite common for the separator to be "_" instead of "-". Either separator can be used when creating a LanguageCode. When getting a * string from the LanguageCode, the "-" form is produced by {@link #toString}. * For more details, see * <a href='http://www.unicode.org/reports/tr35/'>LDML</a>. If I select the line starting "Note:" and Format, I get: * Note that it is quite common for the separator to be "_" instead of "-". * Either separator can be used when creating a LanguageCode. When getting a * string from the LanguageCode, the "-" form is produced by {@link #toString}. * For more details, see <a href='http://www.unicode.org/reports/tr35/'>LDML</a>. That is, it correctly breaks the line with Note, but then *joins* the line with the <a...>, incorrectly creating a line with 81 characters. (the lines might end up being broken by the bugs form, but you should be able to see what I mean) Here is another examples of incorrect formatting, where the result beforehand was legal 80 characters, and after formatting was too long. StringBuilder buffer = new StringBuilder(); buffer .append( "Long String Long String Long String Long String Long String Long String") .append( "Long String Long String Long String Long String Long String Long String") .append( "Long String Long String Long String Long String Long String Long String") ; } Format. Causes the lines to exceed 80 characters. buffer .append( "Long String Long String Long String Long String Long String Long String") .append( "Long String Long String Long String Long String Long String Long String") Even without breaking strings, the 80 character limit could be observed by not indenting so deeply. (And strings could also be broken by inserting ..." + "... if necessary.)
Created attachment 63425 [details] copy of requested preferences
(In reply to comment #2) > Could you please provide your formatter settings? > I'm attaching them (with xxxxxx replacing my company's name)
*** This bug has been marked as a duplicate of bug 59891 ***
This is not a duplicate. The other is "merely" aesthetics -- this is a serious problem, since not only is it breaking an 80 character limit, it is actively screwing up lines that *do* satisfy an 80 character limit, by joining them incorrectly.
See and vote for Bug 198074 https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074
I've just came across this issue as well. You can even see the same behaviour in the Formatter. Go to Java -> Code Style -> Formatter in Preferences and Edit the active profile. Indentation set to Tabs only, tab size set to 4. Click on Line Wrapping tab. Select Method Declarations -> Parameters. In the "Set line width for preview window:" set it to 70. Line will wrap. Now set it to 71. Line will not wrap, scroll to end of window, you will see the line where the break should occur running between the arg6 and closing bracket ). I thought this was explained by the tab character being counted as a single character rather than 4 spaces in regards to line length, so I tried going back to the Indentation tab and changing tab size to 8. This is an increase in tab size by 4 spaces. Going back to Line Wrapping, we see that the wrapping is now different (if tab counted as a single character wouldn't matter how long it is). Setting line width for preview to 74/75 has the same effect as before.
Ownership has changed for the formatter, but I surely will not have enough time to fix your bug during the 3.5 development process, hence set its priority to P5. Please provide a patch if you definitely need the bug to be fixed in this version and I'll have a look at it... TIA
This problem no longer occurs after the formatter redesign. *** This bug has been marked as a duplicate of bug 303519 ***
(In reply to Mateusz Matela from comment #11) > This problem no longer occurs after the formatter redesign. > > *** This bug has been marked as a duplicate of bug 303519 *** @Mateusz: I still see the issue reported in comment 3. Can you please take a look?
I don't see the problems from comment #3 anymore. I played around with various options including tab size set to 2 and 4 and don't see any wrapping issue.
(In reply to Jay Arthanareeswaran from comment #13) > I don't see the problems from comment #3 anymore. I played around with > various options including tab size set to 2 and 4 and don't see any wrapping > issue. Jay- try this from comment 3 If I select the line starting "Note:" and Format, I get: * Note that it is quite common for the separator to be "_" instead of "-". * Either separator can be used when creating a LanguageCode. When getting a * string from the LanguageCode, the "-" form is produced by {@link #toString}. .. That is, it correctly breaks the line with Note, but then *joins* the line with the <a...>, incorrectly creating a line with 81 characters. . if you don't see this you can set this to verified
(In reply to Manoj Palat from comment #14) > if you don't see this you can set this to verified For me, the output is same when I select the first lone alone or format the entire class. This is what I get after formatting: * Note that it is quite common for the separator to be "_" instead of "-". * Either separator can be used when creating a LanguageCode. When getting a * string from the LanguageCode, the "-" form is produced by * {@link #toString}. The @link corrected pushed to a new line. I20160914-0430