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

(-)src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java (-1 / +9 lines)
Lines 54-60 Link Here
54
	private long time;
54
	private long time;
55
	
55
	
56
	static {
56
	static {
57
//		TESTS_NUMBERS = new int[] { 667 };
57
//		TESTS_NUMBERS = new int[] { 668 };
58
//		TESTS_RANGE = new int[] { 658, -1 };
58
//		TESTS_RANGE = new int[] { 658, -1 };
59
	}
59
	}
60
	public static Test suite() {
60
	public static Test suite() {
Lines 9361-9364 Link Here
9361
			JavaCore.setOptions(javaCoreOptions);
9361
			JavaCore.setOptions(javaCoreOptions);
9362
		}
9362
		}
9363
	}
9363
	}
9364
	
9365
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128630
9366
	public void test668() {
9367
		final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
9368
		DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
9369
		DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences);
9370
		runTest(codeFormatter, "test668", "A.java", CodeFormatter.K_COMPILATION_UNIT);//$NON-NLS-1$ //$NON-NLS-2$
9371
	}
9364
}
9372
}
(-)workspace/Formatter/test668/A_in.java (+37 lines)
Added Link Here
1
public   
2
class   
3
FormatTest   {
4
5
	int 
6
	foo() 
7
	{
8
				// foo or bar?
9
int i = 3;
10
	return i   + 
11
1;
12
	}
13
14
	// DO NOT REFORMAT BELOW THIS LINE
15
	int 
16
	bar() 
17
	{
18
				// foo or bar?
19
// DO NOT REFORMAT BELOW THIS LINE
20
int i = 3;
21
// DO NOT REFORMAT ABOVE THIS LINE
22
	return i   + 
23
1;
24
	}
25
	// DO NOT REFORMAT ABOVE THIS LINE
26
	
27
	int 
28
	baz() 
29
	{
30
				// foo or bar?
31
int i = 3;
32
	return i   + 
33
1;
34
	}
35
36
	
37
}
(-)workspace/Formatter/test668/A_out.java (+28 lines)
Added Link Here
1
public class FormatTest {
2
3
	int foo() {
4
		// foo or bar?
5
		int i = 3;
6
		return i + 1;
7
	}
8
9
	// DO NOT REFORMAT BELOW THIS LINE
10
	int 
11
	bar() 
12
	{
13
				// foo or bar?
14
// DO NOT REFORMAT BELOW THIS LINE
15
int i = 3;
16
// DO NOT REFORMAT ABOVE THIS LINE
17
	return i   + 
18
1;
19
	}
20
	// DO NOT REFORMAT ABOVE THIS LINE
21
22
	int baz() {
23
		// foo or bar?
24
		int i = 3;
25
		return i + 1;
26
	}
27
28
}
(-)formatter/org/eclipse/jdt/internal/formatter/Scribe.java (+29 lines)
Lines 35-40 Link Here
35
 */
35
 */
36
public class Scribe {
36
public class Scribe {
37
	private static final int INITIAL_SIZE = 100;
37
	private static final int INITIAL_SIZE = 100;
38
	private static final String BEGIN_NOFORMAT = "DO NOT REFORMAT BELOW THIS LINE"; //$NON-NLS-1$
39
	private static final String END_NOFORMAT = "DO NOT REFORMAT ABOVE THIS LINE"; //$NON-NLS-1$
38
	
40
	
39
	private boolean checkLineWrapping;
41
	private boolean checkLineWrapping;
40
	/** one-based column */
42
	/** one-based column */
Lines 46-51 Link Here
46
	public int currentToken;
48
	public int currentToken;
47
	
49
	
48
	// edits management
50
	// edits management
51
	private int editsSuppressedCount = 0;
49
	private OptimizedReplaceEdit[] edits;
52
	private OptimizedReplaceEdit[] edits;
50
	public int editsIndex;
53
	public int editsIndex;
51
	
54
	
Lines 110-116 Link Here
110
		reset();
113
		reset();
111
	}
114
	}
112
	
115
	
116
	private final boolean editsSuppressed() {
117
		return this.editsSuppressedCount > 0;
118
	}
119
	
120
	private final void suppressEdits() {
121
		this.editsSuppressedCount++;
122
	}
123
124
	private final void allowEdits() {
125
		if (this.editsSuppressedCount > 0) {
126
			this.editsSuppressedCount--;
127
		}
128
	}
129
113
	private final void addDeleteEdit(int start, int end) {
130
	private final void addDeleteEdit(int start, int end) {
131
		if (this.editsSuppressed()) return;
114
		if (this.edits.length == this.editsIndex) {
132
		if (this.edits.length == this.editsIndex) {
115
			// resize
133
			// resize
116
			resize();
134
			resize();
Lines 119-124 Link Here
119
	}
137
	}
120
138
121
	public final void addInsertEdit(int insertPosition, String insertedString) {
139
	public final void addInsertEdit(int insertPosition, String insertedString) {
140
		if (this.editsSuppressed()) return;
122
		if (this.edits.length == this.editsIndex) {
141
		if (this.edits.length == this.editsIndex) {
123
			// resize
142
			// resize
124
			resize();
143
			resize();
Lines 127-132 Link Here
127
	}
146
	}
128
147
129
	private final void addOptimizedReplaceEdit(int offset, int length, String replacement) {
148
	private final void addOptimizedReplaceEdit(int offset, int length, String replacement) {
149
		if (this.editsSuppressed()) return;
130
		if (this.editsIndex > 0) {
150
		if (this.editsIndex > 0) {
131
			// try to merge last two edits
151
			// try to merge last two edits
132
			final OptimizedReplaceEdit previous = this.edits[this.editsIndex-1];
152
			final OptimizedReplaceEdit previous = this.edits[this.editsIndex-1];
Lines 209-214 Link Here
209
	}
229
	}
210
	
230
	
211
	public final void addReplaceEdit(int start, int end, String replacement) {
231
	public final void addReplaceEdit(int start, int end, String replacement) {
232
		if (this.editsSuppressed()) return;
212
		if (this.edits.length == this.editsIndex) {
233
		if (this.edits.length == this.editsIndex) {
213
			// resize
234
			// resize
214
			resize();
235
			resize();
Lines 1153-1159 Link Here
1153
			}
1174
			}
1154
		}
1175
		}
1155
		this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
1176
		this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1);
1177
1178
		final String comment = String.valueOf(s);
1179
		if (comment.contains(BEGIN_NOFORMAT)) {
1180
			suppressEdits();
1181
		} else if (comment.contains(END_NOFORMAT)) {
1182
			allowEdits();
1183
		}
1156
	}
1184
	}
1185
	
1157
	public void printEmptyLines(int linesNumber) {
1186
	public void printEmptyLines(int linesNumber) {
1158
		this.printEmptyLines(linesNumber, this.scanner.getCurrentTokenEndPosition() + 1);
1187
		this.printEmptyLines(linesNumber, this.scanner.getCurrentTokenEndPosition() + 1);
1159
	}
1188
	}

Return to bug 128630