View | Details | Raw Unified | Return to bug 213283
Collapse All | Expand All

(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (-4 / +24 lines)
Lines 130-136 Link Here
130
					int lowerBound = 0;
130
					int lowerBound = 0;
131
					boolean upperFound = false;
131
					boolean upperFound = false;
132
					int regionEnd = offset + length;
132
					int regionEnd = offset + length;
133
					for (int j = 0, max2 = this.editsIndex; j < max2; j++) {
133
					for (int j = 0, max2 = this.editsIndex; j <= max2; j++) {
134
						// search for lower bound
134
						// search for lower bound
135
						int editOffset = this.edits[j].offset;
135
						int editOffset = this.edits[j].offset;
136
						if (upperFound && lowerBound == 0) {
136
						if (upperFound && lowerBound == 0) {
Lines 146-156 Link Here
146
							}
146
							}
147
							// search for upper bound
147
							// search for upper bound
148
						} else {
148
						} else {
149
							if (this.edits[j + 1].offset < offset) {
149
							int next = j+1;
150
							if (next == max2) {
151
								// https://bugs.eclipse.org/bugs/show_bug.cgi?id=213284
152
								// checked all edits, no upper bound found: leave the loop
153
								break;
154
							}
155
							if (this.edits[next].offset < offset) {
150
								continue;
156
								continue;
151
							} else {
157
							} else {
152
								upperBound = editOffset;
158
								upperBound = editOffset;
153
								upperFound = true;
159
								upperFound = true;
160
								// verify if region end is at EOF
161
								if (this.scannerEndPosition == regionEnd + 1) {
162
									lowerBound = this.scannerEndPosition;
163
									break;
164
								}
154
							}
165
							}
155
						}
166
						}
156
					}
167
					}
Lines 737-755 Link Here
737
	 * @return boolean true if line should be adapted, false otherwhise
748
	 * @return boolean true if line should be adapted, false otherwhise
738
	 */
749
	 */
739
	private boolean isAdaptableRegion(int offset, int length) {
750
	private boolean isAdaptableRegion(int offset, int length) {
740
		int regionEnd = offset + length + this.lineSeparator.length() - 1;
751
		int regionEnd = offset + length;
752
		
741
		// first check region width
753
		// first check region width
742
		if (regionEnd > this.pageWidth) {
754
		if (regionEnd > this.pageWidth) {
743
			return false;
755
			return false;
744
		}
756
		}
757
		
745
		int numberOfLineEnds = this.lineEnds != null && this.lineEnds.length > 0 ? this.lineEnds.length : 0;
758
		int numberOfLineEnds = this.lineEnds != null && this.lineEnds.length > 0 ? this.lineEnds.length : 0;
759
		if (this.line == numberOfLineEnds + 1) {
760
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=213283
761
			return true; // last line of the CU
762
		}
763
		
746
		if (this.line > 1 && numberOfLineEnds > 0) { // CU has more than one line
764
		if (this.line > 1 && numberOfLineEnds > 0) { // CU has more than one line
747
			int lineNumber = Util.getLineNumber(offset, this.lineEnds, 0, this.line);
765
			int lineNumber = Util.getLineNumber(offset, this.lineEnds, 0, this.line);
748
			int lineEnd = this.getLineEnd(lineNumber);
766
			int lineEnd = this.getLineEnd(lineNumber);
749
			if (regionEnd > lineEnd) {
767
			if (regionEnd > lineEnd) {
750
				// if more than one line selected, check whether selection is at line end
768
				// if more than one line selected, check whether selection is at line end
751
				for (int i = lineNumber + 1 ; i <=  numberOfLineEnds ; i++) {
769
				for (int i = lineNumber + 1 ; i <=  numberOfLineEnds ; i++) {
752
					if (regionEnd == this.getLineEnd(i)) {
770
					int nextLineEnd = this.getLineEnd(i);
771
					// accept both line ends and line starts
772
					if (regionEnd == nextLineEnd || regionEnd == nextLineEnd + 1) {
753
						return true;
773
						return true;
754
					}
774
					}
755
				}
775
				}
(-)workspace/Formatter/test688/A_out.java (-1 / +1 lines)
Lines 1-3 Link Here
1
public class A {
1
public class A {
2
	int i = 1;
2
	int i = 1;
3
}
3
}
(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (-1 / +119 lines)
Lines 9618-9624 Link Here
9618
	}
9618
	}
9619
	
9619
	
9620
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9620
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9621
	public void test688() {
9621
	public void test688a() {
9622
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9622
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9623
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9623
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9624
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9624
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
Lines 9628-9633 Link Here
9628
		runTest(codeFormatter, "test688", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9628
		runTest(codeFormatter, "test688", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9629
	}
9629
	}
9630
	
9630
	
9631
	public void test688b() {
9632
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9633
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9634
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9635
		IRegion[] regions = new IRegion[] {
9636
				new Region(18, 49)
9637
		};
9638
		runTest(codeFormatter, "test688", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9639
	}
9640
	
9631
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9641
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9632
	public void test689() {
9642
	public void test689() {
9633
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9643
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
Lines 9695-9698 Link Here
9695
		};
9705
		};
9696
		runTest(codeFormatter, "test693", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9706
		runTest(codeFormatter, "test693", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9697
	}
9707
	}
9708
	
9709
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=213283
9710
	public void test694a() {
9711
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9712
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9713
		preferences.line_separator = "\n";//$NON-NLS-1$
9714
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9715
		IRegion[] regions = new IRegion[] {
9716
				new Region(33, 32)
9717
		};
9718
		runTest(codeFormatter, "test694", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9719
	}
9720
	
9721
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=213283
9722
	public void test694b() {
9723
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9724
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9725
		preferences.line_separator = "\n";//$NON-NLS-1$
9726
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9727
		IRegion[] regions = new IRegion[] {
9728
				new Region(33, 33)
9729
		};
9730
		runTest(codeFormatter, "test694", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9731
	}
9732
	
9733
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=213284
9734
	public void test695() {
9735
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9736
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9737
		preferences.line_separator = "\n";//$NON-NLS-1$
9738
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9739
		IRegion[] regions = new IRegion[] {
9740
				new Region(59, 1)
9741
		};
9742
		runTest(codeFormatter, "test695", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9743
	}
9744
	
9745
	// variation on bugs 208541, 213283, 213284
9746
	public void test696a() {
9747
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9748
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9749
		preferences.line_separator = "\n";//$NON-NLS-1$
9750
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9751
		IRegion[] regions = new IRegion[] {
9752
				new Region(17, 56)
9753
		};
9754
		runTest(codeFormatter, "test696a", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9755
	}
9756
	
9757
	// variation on bugs 208541, 213283, 213284
9758
	public void test696b() {
9759
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9760
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9761
		preferences.line_separator = "\n";//$NON-NLS-1$
9762
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9763
		IRegion[] regions = new IRegion[] {
9764
				new Region(17, 57)
9765
		};
9766
		runTest(codeFormatter, "test696b", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9767
	}
9768
	
9769
	// variation on bugs 208541, 213283, 213284
9770
	public void test697a() {
9771
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9772
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9773
		preferences.line_separator = "\n";//$NON-NLS-1$
9774
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9775
		IRegion[] regions = new IRegion[] {
9776
				new Region(17, 55) // end of line selection
9777
		};
9778
		runTest(codeFormatter, "test697", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9779
	}
9780
	
9781
	// variation on bugs 208541, 213283, 213284
9782
	public void test697b() {
9783
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9784
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9785
		preferences.line_separator = "\n";//$NON-NLS-1$
9786
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9787
		IRegion[] regions = new IRegion[] {
9788
				new Region(17, 56) // end of line selection + 1
9789
		};
9790
		runTest(codeFormatter, "test697", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9791
	}
9792
	
9793
	// variation on bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541
9794
//	public void testONLY_698() {
9795
//		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9796
//		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9797
//		preferences.line_separator = "\n";//$NON-NLS-1$
9798
//		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9799
//		IRegion[] regions = new IRegion[] {
9800
//				new Region(17, 40) // partial line selection
9801
//		};
9802
//		runTest(codeFormatter, "test698", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9803
//	}
9804
	
9805
	// variation on bugs 208541, 213283, 213284
9806
	public void test699() {
9807
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9808
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9809
		preferences.line_separator = "\n";//$NON-NLS-1$
9810
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9811
		IRegion[] regions = new IRegion[] {
9812
				new Region(0, 78) // nothing selected --> format all
9813
		};
9814
		runTest(codeFormatter, "test699", "A.java", CodeFormatter.K_UNKNOWN, 0, false, regions, "\n");//$NON-NLS-1$ //$NON-NLS-2$
9815
	}
9698
}
9816
}
(-)workspace/Formatter/test696b/A_out.java (+4 lines)
Added Link Here
1
public class A {
2
3
	int i = 1;
4
}
(-)workspace/Formatter/test696a/A_out.java (+4 lines)
Added Link Here
1
public class A {
2
3
	int i = 1;
4
}
(-)workspace/Formatter/test696a/A_in.java (+6 lines)
Added Link Here
1
public class A {
2
	
3
	
4
	
5
                        int i = 1;               
6
}
(-)workspace/Formatter/test696b/A_in.java (+6 lines)
Added Link Here
1
public class A {
2
	
3
	
4
	
5
                        int i = 1;               
6
}
(-)workspace/Formatter/test694/A_in.java (+5 lines)
Added Link Here
1
package test1;
2
public class A {
3
4
        public int        field;
5
}
(-)workspace/Formatter/test695/A_in.java (+7 lines)
Added Link Here
1
package test1;
2
public class A {
3
4
        public int field;
5
6
7
}
(-)workspace/Formatter/test697/A_in.java (+9 lines)
Added Link Here
1
public class A {
2
	
3
	
4
	
5
                        int i = 1;               
6
7
8
9
}
(-)workspace/Formatter/test698/A_in.java (+9 lines)
Added Link Here
1
public class A {
2
	
3
	
4
	
5
                        int i = 1;               
6
7
8
9
}
(-)workspace/Formatter/test699/A_in.java (+9 lines)
Added Link Here
1
public class A {
2
	
3
	
4
	
5
                        int i = 1;               
6
7
8
9
}
(-)workspace/Formatter/test699/A_out.java (+5 lines)
Added Link Here
1
public class A {
2
3
	int i = 1;
4
5
}
(-)workspace/Formatter/test698/A_out.java (+5 lines)
Added Link Here
1
public class A {
2
3
	int i = 1;
4
5
}
(-)workspace/Formatter/test697/A_out.java (+5 lines)
Added Link Here
1
public class A {
2
3
	int i = 1;
4
5
}
(-)workspace/Formatter/test695/A_out.java (+7 lines)
Added Link Here
1
package test1;
2
public class A {
3
4
        public int field;
5
6
7
}
(-)workspace/Formatter/test694/A_out.java (+5 lines)
Added Link Here
1
package test1;
2
public class A {
3
4
	public int field;
5
}

Return to bug 213283