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 |
} |