Lines 78-87
Link Here
|
78 |
|
78 |
|
79 |
private int[] lineEnds; |
79 |
private int[] lineEnds; |
80 |
private int maxLines; |
80 |
private int maxLines; |
81 |
private String lineSeparator; |
|
|
82 |
public Alignment memberAlignment; |
81 |
public Alignment memberAlignment; |
83 |
public boolean needSpace = false; |
82 |
public boolean needSpace = false; |
84 |
|
83 |
|
|
|
84 |
// Line separator infos |
85 |
final private String lineSeparator; |
86 |
final private char firstLS; |
87 |
final private int lsLength; |
88 |
|
85 |
public int nlsTagCounter; |
89 |
public int nlsTagCounter; |
86 |
public int pageWidth; |
90 |
public int pageWidth; |
87 |
public boolean pendingSpace = false; |
91 |
public boolean pendingSpace = false; |
Lines 100-105
Link Here
|
100 |
private final boolean indentEmptyLines; |
104 |
private final boolean indentEmptyLines; |
101 |
int blank_lines_between_import_groups = -1; |
105 |
int blank_lines_between_import_groups = -1; |
102 |
|
106 |
|
|
|
107 |
/** disabling */ |
108 |
boolean editsEnabled = true; |
109 |
|
103 |
/* Comments formatting */ |
110 |
/* Comments formatting */ |
104 |
private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT; |
111 |
private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT; |
105 |
private static final int INCLUDE_JAVA_DOC = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_JAVA_DOC; |
112 |
private static final int INCLUDE_JAVA_DOC = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_JAVA_DOC; |
Lines 114-119
Link Here
|
114 |
private int formatComments = 0; |
121 |
private int formatComments = 0; |
115 |
private int headerEndPosition = -1; |
122 |
private int headerEndPosition = -1; |
116 |
String commentIndentation; // indentation requested in comments (usually in javadoc root tags description) |
123 |
String commentIndentation; // indentation requested in comments (usually in javadoc root tags description) |
|
|
124 |
|
117 |
// Class to store previous line comment information |
125 |
// Class to store previous line comment information |
118 |
static class LineComment { |
126 |
static class LineComment { |
119 |
boolean contiguous = false; |
127 |
boolean contiguous = false; |
Lines 123-134
Link Here
|
123 |
} |
131 |
} |
124 |
final LineComment lastLineComment = new LineComment(); |
132 |
final LineComment lastLineComment = new LineComment(); |
125 |
|
133 |
|
126 |
|
|
|
127 |
// New way to format javadoc |
134 |
// New way to format javadoc |
128 |
private FormatterCommentParser formatterCommentParser; // specialized parser to format comments |
135 |
private FormatterCommentParser formatterCommentParser; // specialized parser to format comments |
129 |
|
136 |
|
|
|
137 |
// Disabling and enabling tags |
138 |
OptimizedReplaceEdit previousDisabledEdit; |
139 |
private char[][] validationTags; |
140 |
private int disablingTagsLength; |
141 |
private int validationTagsLength; |
142 |
|
130 |
Scribe(CodeFormatterVisitor formatter, long sourceLevel, IRegion[] regions, CodeSnippetParsingUtil codeSnippetParsingUtil, boolean includeComments) { |
143 |
Scribe(CodeFormatterVisitor formatter, long sourceLevel, IRegion[] regions, CodeSnippetParsingUtil codeSnippetParsingUtil, boolean includeComments) { |
131 |
this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); |
144 |
initializeScanner(sourceLevel, formatter.preferences); |
132 |
this.formatter = formatter; |
145 |
this.formatter = formatter; |
133 |
this.pageWidth = formatter.preferences.page_width; |
146 |
this.pageWidth = formatter.preferences.page_width; |
134 |
this.tabLength = formatter.preferences.tab_size; |
147 |
this.tabLength = formatter.preferences.tab_size; |
Lines 143-148
Link Here
|
143 |
this.indentationSize = this.tabLength; |
156 |
this.indentationSize = this.tabLength; |
144 |
} |
157 |
} |
145 |
this.lineSeparator = formatter.preferences.line_separator; |
158 |
this.lineSeparator = formatter.preferences.line_separator; |
|
|
159 |
this.firstLS = this.lineSeparator.charAt(0); |
160 |
this.lsLength = this.lineSeparator.length(); |
146 |
this.indentationLevel = formatter.preferences.initial_indentation_level * this.indentationSize; |
161 |
this.indentationLevel = formatter.preferences.initial_indentation_level * this.indentationSize; |
147 |
this.regions= regions; |
162 |
this.regions= regions; |
148 |
if (codeSnippetParsingUtil != null) { |
163 |
if (codeSnippetParsingUtil != null) { |
Lines 447-452
Link Here
|
447 |
} |
462 |
} |
448 |
|
463 |
|
449 |
private final void addOptimizedReplaceEdit(int offset, int length, String replacement) { |
464 |
private final void addOptimizedReplaceEdit(int offset, int length, String replacement) { |
|
|
465 |
if (!this.editsEnabled) { |
466 |
if (this.previousDisabledEdit != null && this.previousDisabledEdit.offset == offset) { |
467 |
replacement = this.previousDisabledEdit.replacement; |
468 |
} |
469 |
this.previousDisabledEdit = null; |
470 |
if (replacement.indexOf(this.lineSeparator) >= 0) { |
471 |
if (length == 0 || printNewLinesCharacters(offset, length)) { |
472 |
this.previousDisabledEdit = new OptimizedReplaceEdit(offset, length, replacement); |
473 |
} |
474 |
} |
475 |
return; |
476 |
} |
450 |
if (this.editsIndex > 0) { |
477 |
if (this.editsIndex > 0) { |
451 |
// try to merge last two edits |
478 |
// try to merge last two edits |
452 |
final OptimizedReplaceEdit previous = this.edits[this.editsIndex-1]; |
479 |
final OptimizedReplaceEdit previous = this.edits[this.editsIndex-1]; |
Lines 1269-1286
Link Here
|
1269 |
this.numberOfIndentations++; |
1296 |
this.numberOfIndentations++; |
1270 |
} |
1297 |
} |
1271 |
|
1298 |
|
1272 |
/** |
1299 |
private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) { |
1273 |
* @param compilationUnitSource |
1300 |
char[][] disablingTags = preferences.disabling_tags; |
1274 |
*/ |
1301 |
char[][] enablingTags = preferences.enabling_tags; |
1275 |
public void initializeScanner(char[] compilationUnitSource) { |
1302 |
this.disablingTagsLength = disablingTags == null ? 0 : disablingTags.length; |
1276 |
this.scanner.setSource(compilationUnitSource); |
1303 |
int eLength = enablingTags == null ? 0 : enablingTags.length; |
1277 |
this.scannerEndPosition = compilationUnitSource.length; |
1304 |
this.validationTagsLength = this.disablingTagsLength + eLength; |
1278 |
this.scanner.resetTo(0, this.scannerEndPosition - 1); |
1305 |
char[][] taskTags = null; |
1279 |
this.edits = new OptimizedReplaceEdit[INITIAL_SIZE]; |
1306 |
if (this.validationTagsLength > 0) { |
1280 |
this.maxLines = this.lineEnds == null ? -1 : this.lineEnds.length - 1; |
1307 |
this.validationTags = new char[this.validationTagsLength][]; |
1281 |
this.scanner.lineEnds = this.lineEnds; |
1308 |
if (this.disablingTagsLength > 0) { |
1282 |
this.scanner.linePtr = this.maxLines; |
1309 |
System.arraycopy(disablingTags, 0, this.validationTags, 0, this.disablingTagsLength); |
1283 |
initFormatterCommentParser(); |
1310 |
} |
|
|
1311 |
if (eLength > 0) { |
1312 |
System.arraycopy(enablingTags, 0, this.validationTags, this.disablingTagsLength, eLength); |
1313 |
} |
1314 |
// copy the task tags array as it will be reordered by the scanner |
1315 |
taskTags = new char[this.validationTagsLength][]; |
1316 |
System.arraycopy(this.validationTags, 0, taskTags, 0, this.validationTagsLength); |
1317 |
} |
1318 |
this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, taskTags, null/*taskPriorities*/, true/*taskCaseSensitive*/); |
1284 |
} |
1319 |
} |
1285 |
|
1320 |
|
1286 |
private void initFormatterCommentParser() { |
1321 |
private void initFormatterCommentParser() { |
Lines 2153-2159
Link Here
|
2153 |
boolean hasLineComment = false; |
2188 |
boolean hasLineComment = false; |
2154 |
boolean hasWhitespaces = false; |
2189 |
boolean hasWhitespaces = false; |
2155 |
int lines = 0; |
2190 |
int lines = 0; |
|
|
2191 |
int previousFoundTaskCount = this.scanner.foundTaskCount; |
2156 |
while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { |
2192 |
while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { |
|
|
2193 |
int foundTaskCount = this.scanner.foundTaskCount; |
2157 |
switch(this.currentToken) { |
2194 |
switch(this.currentToken) { |
2158 |
case TerminalTokens.TokenNameWHITESPACE : |
2195 |
case TerminalTokens.TokenNameWHITESPACE : |
2159 |
char[] whiteSpaces = this.scanner.getCurrentTokenSource(); |
2196 |
char[] whiteSpaces = this.scanner.getCurrentTokenSource(); |
Lines 2279-2284
Link Here
|
2279 |
currentTokenStartPosition = this.scanner.currentPosition; |
2316 |
currentTokenStartPosition = this.scanner.currentPosition; |
2280 |
break; |
2317 |
break; |
2281 |
case TerminalTokens.TokenNameCOMMENT_LINE : |
2318 |
case TerminalTokens.TokenNameCOMMENT_LINE : |
|
|
2319 |
if (this.editsEnabled && foundTaskCount > previousFoundTaskCount) { |
2320 |
setEditsEnabled(foundTaskCount, previousFoundTaskCount); |
2321 |
if (!this.editsEnabled && this.editsIndex > 1) { |
2322 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
2323 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
2324 |
printNewLinesBeforeDisablingComment(); |
2325 |
} |
2326 |
} |
2327 |
previousFoundTaskCount = foundTaskCount; |
2328 |
} |
2282 |
if (rejectLineComment) break; |
2329 |
if (rejectLineComment) break; |
2283 |
if (lines >= 1) { |
2330 |
if (lines >= 1) { |
2284 |
if (lines > 1) { |
2331 |
if (lines > 1) { |
Lines 2294-2301
Link Here
|
2294 |
currentTokenStartPosition = this.scanner.currentPosition; |
2341 |
currentTokenStartPosition = this.scanner.currentPosition; |
2295 |
hasLineComment = true; |
2342 |
hasLineComment = true; |
2296 |
lines = 0; |
2343 |
lines = 0; |
|
|
2344 |
if (!this.editsEnabled && foundTaskCount > previousFoundTaskCount) { |
2345 |
setEditsEnabled(foundTaskCount, previousFoundTaskCount); |
2346 |
} |
2297 |
break; |
2347 |
break; |
2298 |
case TerminalTokens.TokenNameCOMMENT_BLOCK : |
2348 |
case TerminalTokens.TokenNameCOMMENT_BLOCK : |
|
|
2349 |
if (this.editsEnabled && foundTaskCount > previousFoundTaskCount) { |
2350 |
setEditsEnabled(foundTaskCount, previousFoundTaskCount); |
2351 |
if (!this.editsEnabled && this.editsIndex > 1) { |
2352 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
2353 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
2354 |
printNewLinesBeforeDisablingComment(); |
2355 |
} |
2356 |
} |
2357 |
previousFoundTaskCount = foundTaskCount; |
2358 |
} |
2299 |
if (trailing > NO_TRAILING_COMMENT && lines >= 1) { |
2359 |
if (trailing > NO_TRAILING_COMMENT && lines >= 1) { |
2300 |
// a block comment on next line means that there's no trailing comment |
2360 |
// a block comment on next line means that there's no trailing comment |
2301 |
this.scanner.resetTo(this.scanner.getCurrentTokenStartPosition(), this.scannerEndPosition - 1); |
2361 |
this.scanner.resetTo(this.scanner.getCurrentTokenStartPosition(), this.scannerEndPosition - 1); |
Lines 2318-2325
Link Here
|
2318 |
hasLineComment = false; |
2378 |
hasLineComment = false; |
2319 |
hasComment = true; |
2379 |
hasComment = true; |
2320 |
lines = 0; |
2380 |
lines = 0; |
|
|
2381 |
if (!this.editsEnabled && foundTaskCount > previousFoundTaskCount) { |
2382 |
setEditsEnabled(foundTaskCount, previousFoundTaskCount); |
2383 |
} |
2321 |
break; |
2384 |
break; |
2322 |
case TerminalTokens.TokenNameCOMMENT_JAVADOC : |
2385 |
case TerminalTokens.TokenNameCOMMENT_JAVADOC : |
|
|
2386 |
if (this.editsEnabled && foundTaskCount > previousFoundTaskCount) { |
2387 |
setEditsEnabled(foundTaskCount, previousFoundTaskCount); |
2388 |
previousFoundTaskCount = foundTaskCount; |
2389 |
} |
2323 |
if (trailing > NO_TRAILING_COMMENT) { |
2390 |
if (trailing > NO_TRAILING_COMMENT) { |
2324 |
// a javadoc comment should not be considered as a trailing comment |
2391 |
// a javadoc comment should not be considered as a trailing comment |
2325 |
this.scanner.resetTo(this.scanner.getCurrentTokenStartPosition(), this.scannerEndPosition - 1); |
2392 |
this.scanner.resetTo(this.scanner.getCurrentTokenStartPosition(), this.scannerEndPosition - 1); |
Lines 2342-2347
Link Here
|
2342 |
} else { |
2409 |
} else { |
2343 |
printBlockComment(true); |
2410 |
printBlockComment(true); |
2344 |
} |
2411 |
} |
|
|
2412 |
if (!this.editsEnabled && foundTaskCount > previousFoundTaskCount) { |
2413 |
setEditsEnabled(foundTaskCount, previousFoundTaskCount); |
2414 |
} |
2345 |
printNewLine(); |
2415 |
printNewLine(); |
2346 |
currentTokenStartPosition = this.scanner.currentPosition; |
2416 |
currentTokenStartPosition = this.scanner.currentPosition; |
2347 |
hasLineComment = false; |
2417 |
hasLineComment = false; |
Lines 2354-2359
Link Here
|
2354 |
this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1); |
2424 |
this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1); |
2355 |
return; |
2425 |
return; |
2356 |
} |
2426 |
} |
|
|
2427 |
previousFoundTaskCount = foundTaskCount; |
2357 |
} |
2428 |
} |
2358 |
} catch (InvalidInputException e) { |
2429 |
} catch (InvalidInputException e) { |
2359 |
throw new AbortFormatting(e); |
2430 |
throw new AbortFormatting(e); |
Lines 2363-2369
Link Here
|
2363 |
void printComment(int kind, String source, int start, int end, int level) { |
2434 |
void printComment(int kind, String source, int start, int end, int level) { |
2364 |
|
2435 |
|
2365 |
// Set scanner |
2436 |
// Set scanner |
2366 |
initializeScanner(source.toCharArray()); |
2437 |
resetScanner(source.toCharArray()); |
2367 |
this.scanner.resetTo(start, end); |
2438 |
this.scanner.resetTo(start, end); |
2368 |
// Put back 3.4RC2 code => comment following line as it has an impact on Linux tests |
2439 |
// Put back 3.4RC2 code => comment following line as it has an impact on Linux tests |
2369 |
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=234336 |
2440 |
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=234336 |
Lines 2677-2685
Link Here
|
2677 |
} |
2748 |
} |
2678 |
} |
2749 |
} |
2679 |
|
2750 |
|
2680 |
// Delete leading whitespaces if any |
2751 |
// Replace the line separator at the end of the comment if any... |
2681 |
if (previousToken != -1 && lastTokenEndPosition != commentStart && spaceEndPosition > lastTokenEndPosition) { |
2752 |
int startReplace = previousToken == SKIP_FIRST_WHITESPACE_TOKEN ? spaceStartPosition : lastTokenEndPosition; |
2682 |
addDeleteEdit(lastTokenEndPosition, spaceEndPosition-1); |
2753 |
if (this.column == 1 && commentEnd >= startReplace) { |
|
|
2754 |
addReplaceEdit(startReplace, commentEnd, this.formatter.preferences.line_separator); |
2683 |
} |
2755 |
} |
2684 |
} |
2756 |
} |
2685 |
|
2757 |
|
Lines 4319-4324
Link Here
|
4319 |
this.lastLineComment.contiguous = false; |
4391 |
this.lastLineComment.contiguous = false; |
4320 |
} |
4392 |
} |
4321 |
|
4393 |
|
|
|
4394 |
/* |
4395 |
* Print the indentation of a disabling comment |
4396 |
*/ |
4397 |
private void printNewLinesBeforeDisablingComment() { |
4398 |
|
4399 |
// Get the beginning of comment line |
4400 |
int linePtr = Arrays.binarySearch(this.lineEnds, this.scanner.startPosition); |
4401 |
if (linePtr < 0) { |
4402 |
linePtr = -linePtr - 1; |
4403 |
} |
4404 |
int indentation = 0; |
4405 |
int beginningOfLine = getLineEnd(linePtr)+1; |
4406 |
if (beginningOfLine == -1) { |
4407 |
beginningOfLine = 0; |
4408 |
} |
4409 |
|
4410 |
// If the comment is in the middle of the line, then there's nothing to do |
4411 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
4412 |
int offset = currentEdit.offset; |
4413 |
if (offset >= beginningOfLine) return; |
4414 |
|
4415 |
// Compute the comment indentation |
4416 |
int scannerStartPosition = this.scanner.startPosition; |
4417 |
int scannerEofPosition = this.scanner.eofPosition; |
4418 |
int scannerCurrentPosition = this.scanner.currentPosition; |
4419 |
char scannerCurrentChar = this.scanner.currentCharacter; |
4420 |
int length = currentEdit.length; |
4421 |
this.scanner.resetTo(beginningOfLine, offset+length-1); |
4422 |
try { |
4423 |
while (!this.scanner.atEnd()) { |
4424 |
char ch = (char) this.scanner.getNextChar(); |
4425 |
switch (ch) { |
4426 |
case '\t' : |
4427 |
if (this.tabLength != 0) { |
4428 |
int reminder = indentation % this.tabLength; |
4429 |
if (reminder == 0) { |
4430 |
indentation += this.tabLength; |
4431 |
} else { |
4432 |
indentation = ((indentation / this.tabLength) + 1) * this.tabLength; |
4433 |
} |
4434 |
} |
4435 |
break; |
4436 |
case ' ': |
4437 |
indentation++; |
4438 |
break; |
4439 |
default: |
4440 |
// Should not happen as the offset of the edit is before the beginning of line |
4441 |
return; |
4442 |
} |
4443 |
} |
4444 |
|
4445 |
// Split the existing edit to keep the change before the beginning of the last line |
4446 |
// but change the indentation after. Note that at this stage, the add*Edit methods |
4447 |
// cannot be longer used as the edits are disabled |
4448 |
StringBuffer indentationBuffer = new StringBuffer(); |
4449 |
int currentIndentation = getCurrentIndentation(this.scanner.currentPosition); |
4450 |
if (currentIndentation > 0 && this.indentationLevel > 0) { |
4451 |
int col = this.column; |
4452 |
printIndentationIfNecessary(indentationBuffer); |
4453 |
this.column = col; |
4454 |
} |
4455 |
String replacement = currentEdit.replacement; |
4456 |
if (replacement.length() == 0) { |
4457 |
// previous edit was a delete, as we're sure to have a new line before |
4458 |
// the comment, then the edit needs to be either replaced entirely with |
4459 |
// the expected indentation |
4460 |
this.edits[this.editsIndex-1] = new OptimizedReplaceEdit(beginningOfLine, offset+length-beginningOfLine, indentationBuffer.toString()); |
4461 |
} else { |
4462 |
int idx = replacement.lastIndexOf(this.lineSeparator); |
4463 |
if (idx >= 0) { |
4464 |
// replace current edit if it contains a line separator |
4465 |
int start = idx + this.lsLength; |
4466 |
StringBuffer buffer = new StringBuffer(replacement.substring(0, start)); |
4467 |
buffer.append(indentationBuffer); |
4468 |
this.edits[this.editsIndex-1] = new OptimizedReplaceEdit(offset, length, buffer.toString()); |
4469 |
} |
4470 |
} |
4471 |
} |
4472 |
finally { |
4473 |
this.scanner.startPosition = scannerStartPosition; |
4474 |
this.scanner.eofPosition = scannerEofPosition; |
4475 |
this.scanner.currentPosition = scannerCurrentPosition; |
4476 |
this.scanner.currentCharacter = scannerCurrentChar; |
4477 |
} |
4478 |
} |
4479 |
|
4480 |
/* |
4481 |
* Print new lines characters when the edits are disabled. In this case, only |
4482 |
* the line separator is replaced if necessary, the other white spaces are untouched. |
4483 |
*/ |
4484 |
private boolean printNewLinesCharacters(int offset, int length) { |
4485 |
boolean foundNewLine = false; |
4486 |
int scannerStartPosition = this.scanner.startPosition; |
4487 |
int scannerEofPosition = this.scanner.eofPosition; |
4488 |
int scannerCurrentPosition = this.scanner.currentPosition; |
4489 |
char scannerCurrentChar = this.scanner.currentCharacter; |
4490 |
this.scanner.resetTo(offset, offset+length-1); |
4491 |
try { |
4492 |
while (!this.scanner.atEnd()) { |
4493 |
int start = this.scanner.currentPosition; |
4494 |
char ch = (char) this.scanner.getNextChar(); |
4495 |
boolean needReplace = ch != this.firstLS; |
4496 |
switch (ch) { |
4497 |
case '\r': |
4498 |
if (this.scanner.atEnd()) break; |
4499 |
ch = (char) this.scanner.getNextChar(); |
4500 |
if (ch != '\n') break; |
4501 |
needReplace = needReplace || this.lsLength != 2; |
4502 |
//$FALL-THROUGH$ |
4503 |
case '\n': |
4504 |
if (needReplace) { |
4505 |
if (this.editsIndex == 0 || this.edits[this.editsIndex-1].offset != start) { |
4506 |
this.edits[this.editsIndex++] = new OptimizedReplaceEdit(start, this.scanner.currentPosition-start, this.lineSeparator); |
4507 |
} |
4508 |
} |
4509 |
foundNewLine = true; |
4510 |
break; |
4511 |
} |
4512 |
} |
4513 |
} |
4514 |
finally { |
4515 |
this.scanner.startPosition = scannerStartPosition; |
4516 |
this.scanner.eofPosition = scannerEofPosition; |
4517 |
this.scanner.currentPosition = scannerCurrentPosition; |
4518 |
this.scanner.currentCharacter = scannerCurrentChar; |
4519 |
} |
4520 |
return foundNewLine; |
4521 |
} |
4522 |
|
4322 |
public void printNextToken(int expectedTokenType){ |
4523 |
public void printNextToken(int expectedTokenType){ |
4323 |
printNextToken(expectedTokenType, false); |
4524 |
printNextToken(expectedTokenType, false); |
4324 |
} |
4525 |
} |
Lines 4526-4535
Link Here
|
4526 |
this.formatter.lastLocalDeclarationSourceStart = location.lastLocalDeclarationSourceStart; |
4727 |
this.formatter.lastLocalDeclarationSourceStart = location.lastLocalDeclarationSourceStart; |
4527 |
} |
4728 |
} |
4528 |
|
4729 |
|
|
|
4730 |
/** |
4731 |
* @param compilationUnitSource |
4732 |
*/ |
4733 |
public void resetScanner(char[] compilationUnitSource) { |
4734 |
this.scanner.setSource(compilationUnitSource); |
4735 |
this.scannerEndPosition = compilationUnitSource.length; |
4736 |
this.scanner.resetTo(0, this.scannerEndPosition - 1); |
4737 |
this.edits = new OptimizedReplaceEdit[INITIAL_SIZE]; |
4738 |
this.maxLines = this.lineEnds == null ? -1 : this.lineEnds.length - 1; |
4739 |
this.scanner.lineEnds = this.lineEnds; |
4740 |
this.scanner.linePtr = this.maxLines; |
4741 |
initFormatterCommentParser(); |
4742 |
} |
4743 |
|
4529 |
private void resize() { |
4744 |
private void resize() { |
4530 |
System.arraycopy(this.edits, 0, (this.edits = new OptimizedReplaceEdit[this.editsIndex * 2]), 0, this.editsIndex); |
4745 |
System.arraycopy(this.edits, 0, (this.edits = new OptimizedReplaceEdit[this.editsIndex * 2]), 0, this.editsIndex); |
4531 |
} |
4746 |
} |
4532 |
|
4747 |
|
|
|
4748 |
/* |
4749 |
* Look for the tags identified by the scanner to see whether some of them |
4750 |
* may change the status of the edition for the formatter. |
4751 |
*/ |
4752 |
private void setEditsEnabled(int count, int previous) { |
4753 |
for (int i=previous; i<count; i++) { |
4754 |
for (int j=0; j<this.validationTagsLength; j++) { |
4755 |
if (CharOperation.equals(this.scanner.foundTaskTags[i], this.validationTags[j])) { |
4756 |
this.editsEnabled = j >= this.disablingTagsLength; |
4757 |
// do not return yet, as there may have several disabling/enabling |
4758 |
// tags in a comment, hence the last one will be the one really |
4759 |
// changing the formatter behavior... |
4760 |
} |
4761 |
} |
4762 |
} |
4763 |
} |
4764 |
|
4533 |
void setIncludeComments(boolean on) { |
4765 |
void setIncludeComments(boolean on) { |
4534 |
if (on) { |
4766 |
if (on) { |
4535 |
this.formatComments |= CodeFormatter.F_INCLUDE_COMMENTS; |
4767 |
this.formatComments |= CodeFormatter.F_INCLUDE_COMMENTS; |