Lines 1143-1148
Link Here
|
1143 |
|
1143 |
|
1144 |
private void printBlockComment(int currentTokenStartPosition, int currentTokenEndPosition) { |
1144 |
private void printBlockComment(int currentTokenStartPosition, int currentTokenEndPosition) { |
1145 |
|
1145 |
|
|
|
1146 |
|
1147 |
// Compute indentation |
1148 |
int firstColumn = this.column; |
1149 |
int indentLevel = this.indentationLevel; |
1150 |
int indentations = this.numberOfIndentations; |
1151 |
this.indentationLevel = getNextIndentationLevel(firstColumn); |
1152 |
this.numberOfIndentations = this.indentationLevel % this.indentationSize; |
1153 |
|
1146 |
// Consume the comment prefix |
1154 |
// Consume the comment prefix |
1147 |
StringBuffer buffer = new StringBuffer(); |
1155 |
StringBuffer buffer = new StringBuffer(); |
1148 |
this.scanner.getNextChar(); |
1156 |
this.scanner.getNextChar(); |
Lines 1274-1279
Link Here
|
1274 |
this.column += breakBuffer.length(); |
1282 |
this.column += breakBuffer.length(); |
1275 |
previousToken = token; |
1283 |
previousToken = token; |
1276 |
scannerLine = lineNumber; |
1284 |
scannerLine = lineNumber; |
|
|
1285 |
newLine = false; |
1277 |
continue; |
1286 |
continue; |
1278 |
} |
1287 |
} |
1279 |
} |
1288 |
} |
Lines 1332-1338
Link Here
|
1332 |
int tokenStart = this.scanner.getCurrentTokenStartPosition(); |
1341 |
int tokenStart = this.scanner.getCurrentTokenStartPosition(); |
1333 |
int tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - tokenStart; |
1342 |
int tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - tokenStart; |
1334 |
hasTokens = true; |
1343 |
hasTokens = true; |
1335 |
if (scannerLine == firstLine) hastTextOnFirstLine = true; |
1344 |
if (!hastTextOnFirstLine && scannerLine == firstLine) { |
|
|
1345 |
hastTextOnFirstLine = true; |
1346 |
this.column++; |
1347 |
} |
1336 |
this.column += tokenLength; |
1348 |
this.column += tokenLength; |
1337 |
if (previousToken == -1 || insertSpace) this.column++; |
1349 |
if (previousToken == -1 || insertSpace) this.column++; |
1338 |
|
1350 |
|
Lines 1379-1384
Link Here
|
1379 |
} |
1391 |
} |
1380 |
|
1392 |
|
1381 |
// Reset |
1393 |
// Reset |
|
|
1394 |
this.indentationLevel = indentLevel; |
1395 |
this.numberOfIndentations = indentations; |
1382 |
this.lastNumberOfNewLines = 0; |
1396 |
this.lastNumberOfNewLines = 0; |
1383 |
needSpace = false; |
1397 |
needSpace = false; |
1384 |
this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1); |
1398 |
this.scanner.resetTo(currentTokenEndPosition, this.scannerEndPosition - 1); |
Lines 2062-2067
Link Here
|
2062 |
} |
2076 |
} |
2063 |
|
2077 |
|
2064 |
// tag section: iterate through the blocks composing this tag but the last one |
2078 |
// tag section: iterate through the blocks composing this tag but the last one |
|
|
2079 |
int maxColumn = this.formatter.preferences.comment_line_length; |
2080 |
if (block.isHeaderLine()) maxColumn++; |
2065 |
for (int i=0; i<=maxNodes; i++) { |
2081 |
for (int i=0; i<=maxNodes; i++) { |
2066 |
FormatJavadocNode node = block.nodes[i]; |
2082 |
FormatJavadocNode node = block.nodes[i]; |
2067 |
int nodeStart = node.sourceStart; |
2083 |
int nodeStart = node.sourceStart; |
Lines 2089-2095
Link Here
|
2089 |
if (newLines < text.linesBefore) newLines = text.linesBefore; |
2105 |
if (newLines < text.linesBefore) newLines = text.linesBefore; |
2090 |
if (newLines == 0 && text.isImmutableHtmlTag()) { |
2106 |
if (newLines == 0 && text.isImmutableHtmlTag()) { |
2091 |
textLength = getTextLength(block, text); |
2107 |
textLength = getTextLength(block, text); |
2092 |
if ((this.column + textLength) > this.formatter.preferences.comment_line_length) { |
2108 |
if ((this.column + textLength) > maxColumn) { |
2093 |
newLines = 1; |
2109 |
newLines = 1; |
2094 |
} |
2110 |
} |
2095 |
} |
2111 |
} |
Lines 2116-2122
Link Here
|
2116 |
if (nodeStart > (previousEnd+1)) { |
2132 |
if (nodeStart > (previousEnd+1)) { |
2117 |
tokenLength++; // include space between nodes |
2133 |
tokenLength++; // include space between nodes |
2118 |
} |
2134 |
} |
2119 |
if ((this.column + tokenLength) > this.formatter.preferences.comment_line_length) { |
2135 |
if ((this.column + tokenLength) > maxColumn) { |
2120 |
// finally a new line will be inserted while printing next text |
2136 |
// finally a new line will be inserted while printing next text |
2121 |
newLines = 1; |
2137 |
newLines = 1; |
2122 |
((FormatJavadocText)node).linesBefore = 1; |
2138 |
((FormatJavadocText)node).linesBefore = 1; |
Lines 2436-2444
Link Here
|
2436 |
} |
2452 |
} |
2437 |
|
2453 |
|
2438 |
private int printJavadocHtmlTag(FormatJavadocText text, FormatJavadocBlock block) { |
2454 |
private int printJavadocHtmlTag(FormatJavadocText text, FormatJavadocBlock block) { |
2439 |
|
2455 |
|
2440 |
// Local variables init |
2456 |
// Compute indentation if necessary |
2441 |
boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment; |
2457 |
boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment; |
|
|
2458 |
boolean indentRootTags = this.formatter.preferences.comment_indent_root_tags && !block.isDescription(); |
2459 |
boolean indentParamTag = this.formatter.preferences.comment_indent_parameter_description && block.isParamTag(); |
2460 |
boolean headerLine = block.isHeaderLine() && this.lastNumberOfNewLines == 0; |
2461 |
int firstColumn = 1 + this.indentationLevel + BLOCK_LINE_PREFIX_LENGTH; |
2462 |
if (headerLine) firstColumn++; |
2463 |
StringBuffer indentationBuffer = null; |
2464 |
if (indentRootTags) { |
2465 |
int indentLevel = this.indentationLevel; |
2466 |
int indentations = this.numberOfIndentations; |
2467 |
this.numberOfIndentations += (BLOCK_LINE_PREFIX_LENGTH / this.indentationSize) + 1; |
2468 |
this.indentationLevel = this.numberOfIndentations * this.indentationSize; |
2469 |
int currentColumn = this.column; |
2470 |
this.column = firstColumn; |
2471 |
if (indentParamTag) { |
2472 |
this.indentationLevel += this.indentationSize; |
2473 |
this.numberOfIndentations++; |
2474 |
} |
2475 |
printIndentationIfNecessary(indentationBuffer = new StringBuffer()); |
2476 |
this.column = currentColumn; |
2477 |
this.indentationLevel = indentLevel; |
2478 |
this.numberOfIndentations = indentations; |
2479 |
} |
2480 |
|
2481 |
// Local variables init |
2442 |
int textStart = text.sourceStart; |
2482 |
int textStart = text.sourceStart; |
2443 |
int nextStart = textStart; |
2483 |
int nextStart = textStart; |
2444 |
int startLine = Util.getLineNumber(textStart, this.lineEnds, 0, this.maxLines); |
2484 |
int startLine = Util.getLineNumber(textStart, this.lineEnds, 0, this.maxLines); |
Lines 2468-2484
Link Here
|
2468 |
newLines = linesAfter; |
2508 |
newLines = linesAfter; |
2469 |
if (newLines > 1 && clearBlankLines) newLines = 1; |
2509 |
if (newLines > 1 && clearBlankLines) newLines = 1; |
2470 |
} |
2510 |
} |
2471 |
if (textStart < previousEnd) addReplaceEdit(textStart, previousEnd, buffer.toString()); |
2511 |
if (textStart < previousEnd) { |
|
|
2512 |
addReplaceEdit(textStart, previousEnd, buffer.toString()); |
2513 |
// this.column += buffer.length(); |
2514 |
} |
2515 |
boolean immutable = htmlTag == null ? false : htmlTag.isImmutableHtmlTag(); |
2516 |
boolean overEndLine = false; |
2517 |
if (immutable) { |
2518 |
overEndLine = (this.column + htmlTag.getLength()) > this.formatter.preferences.comment_line_length; |
2519 |
if (overEndLine) { |
2520 |
if (newLines < 1) newLines = 1; |
2521 |
} |
2522 |
} |
2472 |
printJavadocGapLines(previousEnd+1, node.sourceStart-1, newLines, clearBlankLines, false, null); |
2523 |
printJavadocGapLines(previousEnd+1, node.sourceStart-1, newLines, clearBlankLines, false, null); |
2473 |
if (newLines > 0) textOnNewLine = true; |
2524 |
if (newLines > 0) textOnNewLine = true; |
|
|
2525 |
buffer = new StringBuffer(); |
2474 |
if (node.isText()) { |
2526 |
if (node.isText()) { |
2475 |
linesAfter = printJavadocHtmlTag(htmlTag, block); |
2527 |
if (immutable) { |
|
|
2528 |
// do not change immutable tags, just increment column |
2529 |
this.column += getTextLength(block, htmlTag); |
2530 |
linesAfter = 0; |
2531 |
if (overEndLine) { |
2532 |
// need to indent |
2533 |
if (indentationBuffer != null) { |
2534 |
addInsertEdit(node.sourceStart, indentationBuffer.toString()); |
2535 |
} |
2536 |
// buffer.append(' '); |
2537 |
// this.column++; |
2538 |
} |
2539 |
} else { |
2540 |
linesAfter = printJavadocHtmlTag(htmlTag, block); |
2541 |
} |
2476 |
} else { |
2542 |
} else { |
2477 |
printJavadocBlock((FormatJavadocBlock)node); |
2543 |
printJavadocBlock((FormatJavadocBlock)node); |
2478 |
linesAfter = 0; |
2544 |
linesAfter = 0; |
2479 |
} |
2545 |
} |
2480 |
buffer = new StringBuffer(); |
2546 |
textStart = node.sourceEnd+1; |
2481 |
textStart = node.sourceEnd + 1; |
|
|
2482 |
ptr++; |
2547 |
ptr++; |
2483 |
if (idx > max) { |
2548 |
if (idx > max) { |
2484 |
return linesAfter; |
2549 |
return linesAfter; |
Lines 2515-2521
Link Here
|
2515 |
if (clearBlankLines) { |
2580 |
if (clearBlankLines) { |
2516 |
// keep previously computed lines after |
2581 |
// keep previously computed lines after |
2517 |
} else { |
2582 |
} else { |
2518 |
if (wasHtmlTag || idx==0 || (idx==max && ((text.htmlIndexes[max] & JAVADOC_TAGS_ID_MASK) == htmlTagID))) { |
2583 |
// if (wasHtmlTag || idx==0 || (idx==max && ((text.htmlIndexes[max] & JAVADOC_TAGS_ID_MASK) == htmlTagID))) { |
|
|
2584 |
if (idx==0 || (idx==max && ((text.htmlIndexes[max] & JAVADOC_TAGS_ID_MASK) == htmlTagID)) || (idx < max && wasHtmlTag && (text.htmlIndexes[idx-1] & JAVADOC_TAGS_ID_MASK) != JAVADOC_IMMUTABLE_TAGS_ID)) { |
2519 |
if (linesAfter < linesGap) { |
2585 |
if (linesAfter < linesGap) { |
2520 |
linesAfter = linesGap; |
2586 |
linesAfter = linesGap; |
2521 |
} |
2587 |
} |
Lines 2652-2658
Link Here
|
2652 |
|
2718 |
|
2653 |
boolean indentRootTags = this.formatter.preferences.comment_indent_root_tags && !block.isDescription(); |
2719 |
boolean indentRootTags = this.formatter.preferences.comment_indent_root_tags && !block.isDescription(); |
2654 |
boolean indentParamTag = this.formatter.preferences.comment_indent_parameter_description && block.isParamTag(); |
2720 |
boolean indentParamTag = this.formatter.preferences.comment_indent_parameter_description && block.isParamTag(); |
2655 |
boolean headerLine = block.isHeaderLine() && this.lastNumberOfNewLines == 0; |
2721 |
boolean headerLine = (buffer.indexOf(Util.LINE_SEPARATOR) < 0) && block.isHeaderLine() && this.lastNumberOfNewLines == 0; |
2656 |
StringBuffer textBuffer = isHtmlTag ? new StringBuffer() : buffer; |
2722 |
StringBuffer textBuffer = isHtmlTag ? new StringBuffer() : buffer; |
2657 |
|
2723 |
|
2658 |
// First we need to know what is the indentation |
2724 |
// First we need to know what is the indentation |
Lines 2689-2694
Link Here
|
2689 |
this.scanner.resetTo(textStart, textEnd); |
2755 |
this.scanner.resetTo(textStart, textEnd); |
2690 |
this.scanner.skipComments = true; |
2756 |
this.scanner.skipComments = true; |
2691 |
int previousToken = -1; |
2757 |
int previousToken = -1; |
|
|
2758 |
boolean openedString =false; |
2692 |
|
2759 |
|
2693 |
// Consume text token per token |
2760 |
// Consume text token per token |
2694 |
while (!this.scanner.atEnd()) { |
2761 |
while (!this.scanner.atEnd()) { |
Lines 2696-2713
Link Here
|
2696 |
try { |
2763 |
try { |
2697 |
token = this.scanner.getNextToken(); |
2764 |
token = this.scanner.getNextToken(); |
2698 |
} catch (InvalidInputException iie) { |
2765 |
} catch (InvalidInputException iie) { |
|
|
2766 |
boolean insertSpace = previousToken == TerminalTokens.TokenNameWHITESPACE; |
2699 |
String msg = iie.getMessage(); |
2767 |
String msg = iie.getMessage(); |
2700 |
if (msg == Scanner.INVALID_CHARACTER_CONSTANT) { |
2768 |
if (msg == Scanner.INVALID_CHARACTER_CONSTANT) { |
|
|
2769 |
if (insertSpace) { |
2770 |
buffer.append(' '); |
2771 |
this.column++; |
2772 |
} |
2701 |
buffer.append('\''); |
2773 |
buffer.append('\''); |
|
|
2774 |
this.column++; |
2702 |
} else if (msg == Scanner.INVALID_CHAR_IN_STRING) { |
2775 |
} else if (msg == Scanner.INVALID_CHAR_IN_STRING) { |
|
|
2776 |
if (openedString) { |
2777 |
openedString = false; |
2778 |
} else { |
2779 |
if (insertSpace) { |
2780 |
buffer.append(' '); |
2781 |
this.column++; |
2782 |
} |
2783 |
openedString = true; |
2784 |
} |
2703 |
buffer.append('"'); |
2785 |
buffer.append('"'); |
|
|
2786 |
this.column++; |
2704 |
} else { |
2787 |
} else { |
2705 |
// skip failure |
2788 |
// skip failure |
2706 |
} |
2789 |
} |
2707 |
this.column++; |
|
|
2708 |
// Need to retrieve correct position |
2790 |
// Need to retrieve correct position |
2709 |
this.scanner.resetTo(this.scanner.startPosition, textEnd); |
2791 |
this.scanner.resetTo(this.scanner.startPosition, textEnd); |
2710 |
this.scanner.getNextChar(); |
2792 |
this.scanner.getNextChar(); |
|
|
2793 |
previousToken = 1; |
2711 |
continue; |
2794 |
continue; |
2712 |
} |
2795 |
} |
2713 |
if (token == TerminalTokens.TokenNameWHITESPACE) { |
2796 |
if (token == TerminalTokens.TokenNameWHITESPACE) { |
Lines 2734-2740
Link Here
|
2734 |
this.column = 1; |
2817 |
this.column = 1; |
2735 |
printIndentationIfNecessary(buffer); |
2818 |
printIndentationIfNecessary(buffer); |
2736 |
buffer.append(BLOCK_LINE_PREFIX); |
2819 |
buffer.append(BLOCK_LINE_PREFIX); |
2737 |
this.column = firstColumn; |
2820 |
this.column = headerLine ? firstColumn-1 : firstColumn; |
2738 |
if (indentationBuffer != null) { |
2821 |
if (indentationBuffer != null) { |
2739 |
buffer.append(indentationBuffer); |
2822 |
buffer.append(indentationBuffer); |
2740 |
} |
2823 |
} |