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

Bug 455852

Summary: Eclipse formatter does not obey wrap width limits in some cases
Product: [Eclipse Project] JDT Reporter: Luke Hutchison <luke.hutch>
Component: CoreAssignee: Mateusz Matela <mateusz.matela>
Status: VERIFIED DUPLICATE QA Contact: Manoj N Palat <manoj.palat>
Severity: normal    
Priority: P3 CC: jarthana, mateusz.matela
Version: 4.5   
Target Milestone: 4.7 M5   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
The above code exactly as the Eclipse formatter formats it
none
Another example none

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