Lines 108-113
Link Here
|
108 |
/** disabling */ |
108 |
/** disabling */ |
109 |
boolean editsEnabled; |
109 |
boolean editsEnabled; |
110 |
boolean useTags; |
110 |
boolean useTags; |
|
|
111 |
int tagsKind; |
111 |
|
112 |
|
112 |
/* Comments formatting */ |
113 |
/* Comments formatting */ |
113 |
private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT; |
114 |
private static final int INCLUDE_BLOCK_COMMENTS = CodeFormatter.F_INCLUDE_COMMENTS | CodeFormatter.K_MULTI_LINE_COMMENT; |
Lines 1419-1424
Link Here
|
1419 |
|
1420 |
|
1420 |
private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) { |
1421 |
private void initializeScanner(long sourceLevel, DefaultCodeFormatterOptions preferences) { |
1421 |
this.useTags = preferences.use_tags; |
1422 |
this.useTags = preferences.use_tags; |
|
|
1423 |
this.tagsKind = 0; |
1422 |
char[][] taskTags = null; |
1424 |
char[][] taskTags = null; |
1423 |
if (this.useTags) { |
1425 |
if (this.useTags) { |
1424 |
this.disablingTag = preferences.disabling_tag; |
1426 |
this.disablingTag = preferences.disabling_tag; |
Lines 1433-1438
Link Here
|
1433 |
taskTags = new char[][] { this.disablingTag, this.enablingTag }; |
1435 |
taskTags = new char[][] { this.disablingTag, this.enablingTag }; |
1434 |
} |
1436 |
} |
1435 |
} |
1437 |
} |
|
|
1438 |
if (taskTags != null) { |
1439 |
loop: for (int i=0,length=taskTags.length; i<length; i++) { |
1440 |
if (taskTags[i].length > 2 && taskTags[i][0] == '/') { |
1441 |
switch (taskTags[i][1]) { |
1442 |
case '/': |
1443 |
this.tagsKind = TerminalTokens.TokenNameCOMMENT_LINE; |
1444 |
break loop; |
1445 |
case '*': |
1446 |
if (taskTags[i][2] != '*') { |
1447 |
this.tagsKind = TerminalTokens.TokenNameCOMMENT_BLOCK; |
1448 |
break loop; |
1449 |
} |
1450 |
break; |
1451 |
} |
1452 |
} |
1453 |
} |
1454 |
} |
1436 |
this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, taskTags, null/*taskPriorities*/, true/*taskCaseSensitive*/); |
1455 |
this.scanner = new Scanner(true, true, false/*nls*/, sourceLevel/*sourceLevel*/, taskTags, null/*taskPriorities*/, true/*taskCaseSensitive*/); |
1437 |
this.editsEnabled = true; |
1456 |
this.editsEnabled = true; |
1438 |
} |
1457 |
} |
Lines 2368-2378
Link Here
|
2368 |
int lines = 0; |
2387 |
int lines = 0; |
2369 |
while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { |
2388 |
while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { |
2370 |
int foundTaskCount = this.scanner.foundTaskCount; |
2389 |
int foundTaskCount = this.scanner.foundTaskCount; |
|
|
2390 |
int tokenStartPosition = this.scanner.getCurrentTokenStartPosition(); |
2391 |
int tokenEndPosition = this.scanner.getCurrentTokenEndPosition(); |
2371 |
switch(this.currentToken) { |
2392 |
switch(this.currentToken) { |
2372 |
case TerminalTokens.TokenNameWHITESPACE : |
2393 |
case TerminalTokens.TokenNameWHITESPACE : |
2373 |
char[] whiteSpaces = this.scanner.getCurrentTokenSource(); |
2394 |
char[] whiteSpaces = this.scanner.getCurrentTokenSource(); |
2374 |
int whitespacesStartPosition = this.scanner.getCurrentTokenStartPosition(); |
|
|
2375 |
int whitespacesEndPosition = this.scanner.getCurrentTokenEndPosition(); |
2376 |
lines = 0; |
2395 |
lines = 0; |
2377 |
for (int i = 0, max = whiteSpaces.length; i < max; i++) { |
2396 |
for (int i = 0, max = whiteSpaces.length; i < max; i++) { |
2378 |
switch(whiteSpaces[i]) { |
2397 |
switch(whiteSpaces[i]) { |
Lines 2445-2453
Link Here
|
2445 |
// if a line comment is consumed, no other comment can be on the same line after |
2464 |
// if a line comment is consumed, no other comment can be on the same line after |
2446 |
if (hasLineComment) { |
2465 |
if (hasLineComment) { |
2447 |
if (lines >= 1) { |
2466 |
if (lines >= 1) { |
2448 |
currentTokenStartPosition = whitespacesStartPosition; |
2467 |
currentTokenStartPosition = tokenStartPosition; |
2449 |
preserveEmptyLines(lines, currentTokenStartPosition); |
2468 |
preserveEmptyLines(lines, currentTokenStartPosition); |
2450 |
addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition); |
2469 |
addDeleteEdit(currentTokenStartPosition, tokenEndPosition); |
2451 |
this.scanner.resetTo(this.scanner.currentPosition, this.scannerEndPosition - 1); |
2470 |
this.scanner.resetTo(this.scanner.currentPosition, this.scannerEndPosition - 1); |
2452 |
return; |
2471 |
return; |
2453 |
} |
2472 |
} |
Lines 2457-2463
Link Here
|
2457 |
// if one or several new lines are consumed, following comments cannot be considered as trailing ones |
2476 |
// if one or several new lines are consumed, following comments cannot be considered as trailing ones |
2458 |
if (lines >= 1) { |
2477 |
if (lines >= 1) { |
2459 |
if (hasComment) { |
2478 |
if (hasComment) { |
2460 |
this.printNewLine(whitespacesStartPosition); |
2479 |
this.printNewLine(tokenStartPosition); |
2461 |
} |
2480 |
} |
2462 |
this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1); |
2481 |
this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1); |
2463 |
return; |
2482 |
return; |
Lines 2465-2501
Link Here
|
2465 |
// delete consumed white spaces |
2484 |
// delete consumed white spaces |
2466 |
hasWhitespaces = true; |
2485 |
hasWhitespaces = true; |
2467 |
currentTokenStartPosition = this.scanner.currentPosition; |
2486 |
currentTokenStartPosition = this.scanner.currentPosition; |
2468 |
addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition); |
2487 |
addDeleteEdit(tokenStartPosition, tokenEndPosition); |
2469 |
} else { |
2488 |
} else { |
2470 |
if (lines == 0) { |
2489 |
if (lines == 0) { |
2471 |
hasWhitespaces = true; |
2490 |
hasWhitespaces = true; |
2472 |
addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition); |
2491 |
addDeleteEdit(tokenStartPosition, tokenEndPosition); |
2473 |
} else if (hasLineComment) { |
2492 |
} else if (hasLineComment) { |
2474 |
currentTokenStartPosition = whitespacesStartPosition; |
2493 |
currentTokenStartPosition = tokenStartPosition; |
2475 |
preserveEmptyLines(lines, currentTokenStartPosition); |
2494 |
preserveEmptyLines(lines, currentTokenStartPosition); |
2476 |
addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition); |
2495 |
addDeleteEdit(currentTokenStartPosition, tokenEndPosition); |
2477 |
} else if (hasComment) { |
2496 |
} else if (hasComment) { |
2478 |
if (lines == 1) { |
2497 |
if (lines == 1) { |
2479 |
this.printNewLine(whitespacesStartPosition); |
2498 |
this.printNewLine(tokenStartPosition); |
2480 |
} else { |
2499 |
} else { |
2481 |
preserveEmptyLines(lines - 1, whitespacesStartPosition); |
2500 |
preserveEmptyLines(lines - 1, tokenStartPosition); |
2482 |
} |
2501 |
} |
2483 |
addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition); |
2502 |
addDeleteEdit(tokenStartPosition, tokenEndPosition); |
2484 |
} else if (lines != 0 && (!this.formatter.preferences.join_wrapped_lines || this.formatter.preferences.number_of_empty_lines_to_preserve != 0 || this.blank_lines_between_import_groups > 0)) { |
2503 |
} else if (lines != 0 && (!this.formatter.preferences.join_wrapped_lines || this.formatter.preferences.number_of_empty_lines_to_preserve != 0 || this.blank_lines_between_import_groups > 0)) { |
2485 |
addReplaceEdit(whitespacesStartPosition, whitespacesEndPosition, getPreserveEmptyLines(lines-1)); |
2504 |
addReplaceEdit(tokenStartPosition, tokenEndPosition, getPreserveEmptyLines(lines-1)); |
2486 |
} else { |
2505 |
} else { |
2487 |
addDeleteEdit(whitespacesStartPosition, whitespacesEndPosition); |
2506 |
addDeleteEdit(tokenStartPosition, tokenEndPosition); |
2488 |
} |
2507 |
} |
2489 |
} |
2508 |
} |
2490 |
currentTokenStartPosition = this.scanner.currentPosition; |
2509 |
currentTokenStartPosition = this.scanner.currentPosition; |
2491 |
break; |
2510 |
break; |
2492 |
case TerminalTokens.TokenNameCOMMENT_LINE : |
2511 |
case TerminalTokens.TokenNameCOMMENT_LINE : |
2493 |
if (this.useTags && this.editsEnabled && foundTaskCount > 0) { |
2512 |
tokenEndPosition = -this.scanner.commentStops[this.scanner.commentPtr]; |
2494 |
setEditsEnabled(foundTaskCount); |
2513 |
if (this.useTags && this.editsEnabled) { |
2495 |
if (!this.editsEnabled && this.editsIndex > 1) { |
2514 |
boolean turnOff = false; |
2496 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
2515 |
if (foundTaskCount > 0) { |
2497 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
2516 |
setEditsEnabled(foundTaskCount); |
2498 |
printNewLinesBeforeDisablingComment(); |
2517 |
turnOff = true; |
|
|
2518 |
} else if (this.tagsKind == this.currentToken |
2519 |
&& CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition)) { |
2520 |
this.editsEnabled = false; |
2521 |
turnOff = true; |
2522 |
} |
2523 |
if (turnOff) { |
2524 |
if (!this.editsEnabled && this.editsIndex > 1) { |
2525 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
2526 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
2527 |
printNewLinesBeforeDisablingComment(); |
2528 |
} |
2499 |
} |
2529 |
} |
2500 |
} |
2530 |
} |
2501 |
} |
2531 |
} |
Lines 2514-2530
Link Here
|
2514 |
currentTokenStartPosition = this.scanner.currentPosition; |
2544 |
currentTokenStartPosition = this.scanner.currentPosition; |
2515 |
hasLineComment = true; |
2545 |
hasLineComment = true; |
2516 |
lines = 0; |
2546 |
lines = 0; |
2517 |
if (this.useTags && !this.editsEnabled && foundTaskCount > 0) { |
2547 |
if (this.useTags && !this.editsEnabled) { |
2518 |
setEditsEnabled(foundTaskCount); |
2548 |
if (foundTaskCount > 0) { |
|
|
2549 |
setEditsEnabled(foundTaskCount); |
2550 |
} else if (this.tagsKind == this.currentToken) { |
2551 |
this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition); |
2552 |
} |
2519 |
} |
2553 |
} |
2520 |
break; |
2554 |
break; |
2521 |
case TerminalTokens.TokenNameCOMMENT_BLOCK : |
2555 |
case TerminalTokens.TokenNameCOMMENT_BLOCK : |
2522 |
if (this.useTags && this.editsEnabled && foundTaskCount > 0) { |
2556 |
if (this.useTags && this.editsEnabled) { |
2523 |
setEditsEnabled(foundTaskCount); |
2557 |
boolean turnOff = false; |
2524 |
if (!this.editsEnabled && this.editsIndex > 1) { |
2558 |
if (foundTaskCount > 0) { |
2525 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
2559 |
setEditsEnabled(foundTaskCount); |
2526 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
2560 |
turnOff = true; |
2527 |
printNewLinesBeforeDisablingComment(); |
2561 |
} else if (this.tagsKind == this.currentToken |
|
|
2562 |
&& CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1)) { |
2563 |
this.editsEnabled = false; |
2564 |
turnOff = true; |
2565 |
} |
2566 |
if (turnOff) { |
2567 |
if (!this.editsEnabled && this.editsIndex > 1) { |
2568 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
2569 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
2570 |
printNewLinesBeforeDisablingComment(); |
2571 |
} |
2528 |
} |
2572 |
} |
2529 |
} |
2573 |
} |
2530 |
} |
2574 |
} |
Lines 2550-2557
Link Here
|
2550 |
hasLineComment = false; |
2594 |
hasLineComment = false; |
2551 |
hasComment = true; |
2595 |
hasComment = true; |
2552 |
lines = 0; |
2596 |
lines = 0; |
2553 |
if (this.useTags && !this.editsEnabled && foundTaskCount > 0) { |
2597 |
if (this.useTags && !this.editsEnabled) { |
2554 |
setEditsEnabled(foundTaskCount); |
2598 |
if (foundTaskCount > 0) { |
|
|
2599 |
setEditsEnabled(foundTaskCount); |
2600 |
} else if (this.tagsKind == this.currentToken) { |
2601 |
this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1); |
2602 |
} |
2555 |
} |
2603 |
} |
2556 |
break; |
2604 |
break; |
2557 |
case TerminalTokens.TokenNameCOMMENT_JAVADOC : |
2605 |
case TerminalTokens.TokenNameCOMMENT_JAVADOC : |
Lines 4430-4435
Link Here
|
4430 |
boolean hasModifiers = false; |
4478 |
boolean hasModifiers = false; |
4431 |
while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { |
4479 |
while ((this.currentToken = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { |
4432 |
int foundTaskCount = this.scanner.foundTaskCount; |
4480 |
int foundTaskCount = this.scanner.foundTaskCount; |
|
|
4481 |
int tokenStartPosition = this.scanner.getCurrentTokenStartPosition(); |
4482 |
int tokenEndPosition = this.scanner.getCurrentTokenEndPosition(); |
4433 |
switch(this.currentToken) { |
4483 |
switch(this.currentToken) { |
4434 |
case TerminalTokens.TokenNamepublic : |
4484 |
case TerminalTokens.TokenNamepublic : |
4435 |
case TerminalTokens.TokenNameprotected : |
4485 |
case TerminalTokens.TokenNameprotected : |
Lines 4494-4528
Link Here
|
4494 |
break; |
4544 |
break; |
4495 |
case TerminalTokens.TokenNameCOMMENT_BLOCK : |
4545 |
case TerminalTokens.TokenNameCOMMENT_BLOCK : |
4496 |
case TerminalTokens.TokenNameCOMMENT_JAVADOC : |
4546 |
case TerminalTokens.TokenNameCOMMENT_JAVADOC : |
4497 |
if (this.useTags && this.editsEnabled && foundTaskCount > 0) { |
4547 |
if (this.useTags && this.editsEnabled) { |
4498 |
setEditsEnabled(foundTaskCount); |
4548 |
boolean turnOff = false; |
4499 |
if (!this.editsEnabled && this.editsIndex > 1) { |
4549 |
if (foundTaskCount > 0) { |
4500 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
4550 |
setEditsEnabled(foundTaskCount); |
4501 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
4551 |
turnOff = true; |
4502 |
printNewLinesBeforeDisablingComment(); |
4552 |
} else if (this.tagsKind == this.currentToken |
|
|
4553 |
&& CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1)) { |
4554 |
this.editsEnabled = false; |
4555 |
turnOff = true; |
4556 |
} |
4557 |
if (turnOff) { |
4558 |
if (!this.editsEnabled && this.editsIndex > 1) { |
4559 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
4560 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
4561 |
printNewLinesBeforeDisablingComment(); |
4562 |
} |
4503 |
} |
4563 |
} |
4504 |
} |
4564 |
} |
4505 |
} |
4565 |
} |
4506 |
printBlockComment(this.currentToken == TerminalTokens.TokenNameCOMMENT_JAVADOC); |
4566 |
printBlockComment(this.currentToken == TerminalTokens.TokenNameCOMMENT_JAVADOC); |
4507 |
if (this.useTags && !this.editsEnabled && foundTaskCount > 0) { |
4567 |
if (this.useTags && !this.editsEnabled) { |
4508 |
setEditsEnabled(foundTaskCount); |
4568 |
if (foundTaskCount > 0) { |
|
|
4569 |
setEditsEnabled(foundTaskCount); |
4570 |
} else if (this.tagsKind == this.currentToken) { |
4571 |
this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition+1); |
4572 |
} |
4509 |
} |
4573 |
} |
4510 |
currentTokenStartPosition = this.scanner.currentPosition; |
4574 |
currentTokenStartPosition = this.scanner.currentPosition; |
4511 |
hasComment = true; |
4575 |
hasComment = true; |
4512 |
break; |
4576 |
break; |
4513 |
case TerminalTokens.TokenNameCOMMENT_LINE : |
4577 |
case TerminalTokens.TokenNameCOMMENT_LINE : |
4514 |
if (this.useTags && this.editsEnabled && foundTaskCount > 0) { |
4578 |
tokenEndPosition = -this.scanner.commentStops[this.scanner.commentPtr]; |
4515 |
setEditsEnabled(foundTaskCount); |
4579 |
if (this.useTags && this.editsEnabled) { |
4516 |
if (!this.editsEnabled && this.editsIndex > 1) { |
4580 |
boolean turnOff = false; |
4517 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
4581 |
if (foundTaskCount > 0) { |
4518 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
4582 |
setEditsEnabled(foundTaskCount); |
4519 |
printNewLinesBeforeDisablingComment(); |
4583 |
turnOff = true; |
|
|
4584 |
} else if (this.tagsKind == this.currentToken |
4585 |
&& CharOperation.equals(this.disablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition)) { |
4586 |
this.editsEnabled = false; |
4587 |
turnOff = true; |
4588 |
} |
4589 |
if (turnOff) { |
4590 |
if (!this.editsEnabled && this.editsIndex > 1) { |
4591 |
OptimizedReplaceEdit currentEdit = this.edits[this.editsIndex-1]; |
4592 |
if (this.scanner.startPosition == currentEdit.offset+currentEdit.length) { |
4593 |
printNewLinesBeforeDisablingComment(); |
4594 |
} |
4520 |
} |
4595 |
} |
4521 |
} |
4596 |
} |
4522 |
} |
4597 |
} |
4523 |
printLineComment(); |
4598 |
printLineComment(); |
4524 |
if (this.useTags && !this.editsEnabled && foundTaskCount > 0) { |
4599 |
if (this.useTags && !this.editsEnabled) { |
4525 |
setEditsEnabled(foundTaskCount); |
4600 |
if (foundTaskCount > 0) { |
|
|
4601 |
setEditsEnabled(foundTaskCount); |
4602 |
} else if (this.tagsKind == this.currentToken) { |
4603 |
this.editsEnabled = CharOperation.equals(this.enablingTag, this.scanner.source, tokenStartPosition, tokenEndPosition); |
4604 |
} |
4526 |
} |
4605 |
} |
4527 |
currentTokenStartPosition = this.scanner.currentPosition; |
4606 |
currentTokenStartPosition = this.scanner.currentPosition; |
4528 |
break; |
4607 |
break; |