|
Lines 1848-1856
Link Here
|
| 1848 |
CommentFormatterUtil.log(e); |
1848 |
CommentFormatterUtil.log(e); |
| 1849 |
return; |
1849 |
return; |
| 1850 |
} |
1850 |
} |
| 1851 |
int prefixOffset= inputBuffer.indexOf(contentPrefix, lineOffset); |
1851 |
int prefixOffset = inputBuffer.indexOf(contentPrefix, lineOffset); |
| 1852 |
if (prefixOffset >= 0 && inputBuffer.substring(lineOffset, prefixOffset).trim().length() == 0) |
1852 |
if (prefixOffset >= 0 && inputBuffer.substring(lineOffset, prefixOffset).trim().length() == 0) { |
| 1853 |
inputBuffer.delete(lineOffset, prefixOffset + 1 + 1); |
1853 |
int offsetEnd = prefixOffset + 1; |
|
|
1854 |
char ch = inputBuffer.charAt(offsetEnd); |
| 1855 |
switch (ch) { |
| 1856 |
case '\n': |
| 1857 |
case '\r': |
| 1858 |
break; |
| 1859 |
case ' ': |
| 1860 |
case '\t': |
| 1861 |
case '\u000c' : /* FORM FEED */ |
| 1862 |
offsetEnd++; |
| 1863 |
break; |
| 1864 |
default: |
| 1865 |
if (ScannerHelper.isWhitespace(ch)) { |
| 1866 |
offsetEnd++; |
| 1867 |
} |
| 1868 |
break; |
| 1869 |
} |
| 1870 |
inputBuffer.delete(lineOffset, offsetEnd); |
| 1871 |
} |
| 1854 |
} |
1872 |
} |
| 1855 |
|
1873 |
|
| 1856 |
// 2 - convert HTML to Java (@see JavaDocRegion#convertHtml2Java) |
1874 |
// 2 - convert HTML to Java (@see JavaDocRegion#convertHtml2Java) |
|
Lines 3267-3300
Link Here
|
| 3267 |
if (codeEnd > end) { |
3285 |
if (codeEnd > end) { |
| 3268 |
if (this.formatter.preferences.comment_format_source) { |
3286 |
if (this.formatter.preferences.comment_format_source) { |
| 3269 |
if (textStart < end) addReplaceEdit(textStart, end, buffer.toString()); |
3287 |
if (textStart < end) addReplaceEdit(textStart, end, buffer.toString()); |
| 3270 |
// Count the lines until the exact start position of the code |
3288 |
// See whether there's a space before the code |
| 3271 |
this.scanner.resetTo(end+1, nextStart-1); |
3289 |
boolean needLeadingSpace = false; |
| 3272 |
int newLines = 0; |
3290 |
if (linesGap > 0) { |
| 3273 |
try { |
3291 |
int lineStart = this.scanner.getLineStart(startLine); |
| 3274 |
int token = this.scanner.getNextToken(); |
3292 |
if (nextStart > lineStart) { // if code starts at the line, then no leading space is needed |
| 3275 |
loop: while (true) { |
3293 |
this.scanner.resetTo(lineStart, nextStart-1); |
| 3276 |
switch (token) { |
3294 |
try { |
| 3277 |
case TerminalTokens.TokenNameWHITESPACE: |
3295 |
int token = this.scanner.getNextToken(); |
| 3278 |
if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.currentPosition) < 0) { |
3296 |
if (token == TerminalTokens.TokenNameWHITESPACE) { |
| 3279 |
break loop; |
3297 |
// skip indentation |
| 3280 |
} |
3298 |
token = this.scanner.getNextToken(); |
| 3281 |
newLines++; |
3299 |
needLeadingSpace = false; // there may be no star after |
| 3282 |
break; |
3300 |
} else { |
| 3283 |
case TerminalTokens.TokenNameMULTIPLY: |
3301 |
needLeadingSpace = true; |
| 3284 |
nextStart = this.scanner.currentPosition + 1; |
3302 |
} |
| 3285 |
break; |
3303 |
if (token == TerminalTokens.TokenNameMULTIPLY) { |
| 3286 |
default: |
3304 |
nextStart = this.scanner.currentPosition; |
| 3287 |
break loop; |
3305 |
// skip javadoc comment star |
|
|
3306 |
token = this.scanner.getNextToken(); |
| 3307 |
needLeadingSpace = true; |
| 3308 |
} |
| 3309 |
if (token == TerminalTokens.TokenNameWHITESPACE) { |
| 3310 |
needLeadingSpace = false; |
| 3311 |
nextStart++; |
| 3312 |
} |
| 3313 |
} |
| 3314 |
catch (InvalidInputException iie) { |
| 3315 |
// skip |
| 3288 |
} |
3316 |
} |
| 3289 |
token = this.scanner.getNextToken(); |
|
|
| 3290 |
} |
3317 |
} |
| 3291 |
} |
3318 |
} |
| 3292 |
catch (InvalidInputException iie) { |
3319 |
// Format gap lines before code |
| 3293 |
// skip |
3320 |
int newLines = linesGap; |
| 3294 |
} |
|
|
| 3295 |
if (newLines == 0) newLines=1; |
3321 |
if (newLines == 0) newLines=1; |
| 3296 |
printJavadocGapLines(end+1, nextStart-1, newLines, false/* clear first blank lines inside <pre> tag as done by old formatter */, false, null); |
3322 |
printJavadocGapLines(end+1, nextStart-1, newLines, false/* clear first blank lines inside <pre> tag as done by old formatter */, false, null); |
|
|
3323 |
if (needLeadingSpace) { |
| 3324 |
addInsertEdit(nextStart, " "); //$NON-NLS-1$ |
| 3325 |
} |
| 3326 |
// Format the code |
| 3297 |
printCodeSnippet(nextStart, codeEnd); |
3327 |
printCodeSnippet(nextStart, codeEnd); |
|
|
3328 |
// Format the gap lines after the code |
| 3298 |
nextStart = (int) text.separators[max]; |
3329 |
nextStart = (int) text.separators[max]; |
| 3299 |
printJavadocGapLines(codeEnd+1, nextStart-1, 1, false/* clear blank lines inside <pre> tag as done by old formatter */, false, null); |
3330 |
printJavadocGapLines(codeEnd+1, nextStart-1, 1, false/* clear blank lines inside <pre> tag as done by old formatter */, false, null); |
| 3300 |
return 2; |
3331 |
return 2; |