Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 455852 - Eclipse formatter does not obey wrap width limits in some cases
Summary: Eclipse formatter does not obey wrap width limits in some cases
Status: VERIFIED DUPLICATE of bug 303519
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: 4.7 M5   Edit
Assignee: Mateusz Matela CLA
QA Contact: Manoj N Palat CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-20 10:52 EST by Luke Hutchison CLA
Modified: 2017-01-25 01:41 EST (History)
2 users (show)

See Also:


Attachments
The above code exactly as the Eclipse formatter formats it (784 bytes, text/x-java)
2014-12-20 10:52 EST, Luke Hutchison CLA
no flags Details
Another example (1.49 KB, text/x-java)
2014-12-26 03:06 EST, Luke Hutchison CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Luke Hutchison CLA 2014-12-20 10:52:37 EST
Created attachment 249565 [details]
The above code exactly as the Eclipse formatter formats it

I created a new default Eclipse code formatter, then set all wrap settings to "Wrap as necessary". With a wrap width of 60, the following code is shown post-formatting. I will also attach the code as an attachment. Look at the attached version instead, since bugs.eclipse.org is going to wrap the text itself in places where Eclipse is not wrapping it -- the following is just included as a quick reference.


import java.util.ArrayList;

public class FormatWidthProblems {

	// format width ---------------------------------------|

	static class ReallyLongClassNameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX {
	}

	public static void main(String[] args) {
		int[] reallyLongArrayNameZZZZZZZZZZZZZZZZZZZZZZZZZ =
				new int[0];
		for (int reallyLongVariableNameZZZZZZZZZZZZZZZZZZZZZZZZZ : reallyLongArrayNameZZZZZZZZZZZZZZZZZZZZZZZZZ) {
		}
		int reallyLongVariableName1 = 1, reallyLongVariableName2 =
				2, reallyLongVariableName3 = 3;
		ArrayList<Integer> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx =
				new ArrayList<>();
		ArrayList<ReallyLongClassNameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX> xxxxxxxxxxxxxxxxxxxxx =
				new ArrayList<>();
	}

	// format width ---------------------------------------|
}
Comment 1 Luke Hutchison CLA 2014-12-20 11:12:54 EST
Another example I just came across:

        for (int segIdx = 0, escapePos = -1, escapedByte = 0, nSeg = segment.length(); segIdx < nSeg; segIdx++) {

The line width in this example is 108 characters, which is between "sexIdx" and "++". All of "++) {" sticks out past the wrap boundary even after formatting.
Comment 2 Noopur Gupta CLA 2014-12-20 12:21:07 EST
Moving to JDT Core for comments.
Comment 3 Luke Hutchison CLA 2014-12-26 03:06:25 EST
Created attachment 249627 [details]
Another example

Another example, all of "|| fieldType == Double.TYPE)) {" sticks out past the maximum wrap width of 120.
Comment 4 Jay Arthanareeswaran CLA 2015-01-08 01:29:49 EST
Manoj, please respond.
Comment 5 Mateusz Matela CLA 2016-12-11 17:10:28 EST
This problem no longer occurs after the formatter redesign.
If some lines do go over the width limit, it means they don't contain any spot where wrapping can be introduced. If a new kind of spot should be added as an option, that's for a new bug report.

*** This bug has been marked as a duplicate of bug 303519 ***
Comment 6 Sasikanth Bharadwaj CLA 2017-01-25 01:41:21 EST
Verified for 4.7 M5 using I20170123-2000 build