Lines 1157-1163
Link Here
|
1157 |
this.scanner.getNextChar(); |
1157 |
this.scanner.getNextChar(); |
1158 |
this.column += 2; |
1158 |
this.column += 2; |
1159 |
this.scanner.skipComments = true; |
1159 |
this.scanner.skipComments = true; |
1160 |
|
1160 |
StringBuffer tokensBuffer = new StringBuffer(); |
|
|
1161 |
|
1161 |
// Consume text token per token |
1162 |
// Consume text token per token |
1162 |
int maxColumn = this.formatter.preferences.comment_line_length + 1; |
1163 |
int maxColumn = this.formatter.preferences.comment_line_length + 1; |
1163 |
int previousToken = -1; |
1164 |
int previousToken = -1; |
Lines 1172-1178
Link Here
|
1172 |
int lineNumber = scannerLine; |
1173 |
int lineNumber = scannerLine; |
1173 |
int lastTextLine = -1; |
1174 |
int lastTextLine = -1; |
1174 |
boolean openedString = false; |
1175 |
boolean openedString = false; |
1175 |
boolean openedChar = false; |
|
|
1176 |
while (!this.scanner.atEnd()) { |
1176 |
while (!this.scanner.atEnd()) { |
1177 |
|
1177 |
|
1178 |
// Consume token |
1178 |
// Consume token |
Lines 1183-1211
Link Here
|
1183 |
String msg = iie.getMessage(); |
1183 |
String msg = iie.getMessage(); |
1184 |
boolean insertSpace = (previousToken == TerminalTokens.TokenNameWHITESPACE || newLine) && !firstWord; |
1184 |
boolean insertSpace = (previousToken == TerminalTokens.TokenNameWHITESPACE || newLine) && !firstWord; |
1185 |
if (msg == Scanner.INVALID_CHARACTER_CONSTANT) { |
1185 |
if (msg == Scanner.INVALID_CHARACTER_CONSTANT) { |
1186 |
if (openedChar) { |
1186 |
if (insertSpace) { |
1187 |
openedChar = false; |
1187 |
tokensBuffer.append(' '); |
1188 |
} else { |
|
|
1189 |
if (insertSpace) { |
1190 |
buffer.append(' '); |
1191 |
this.column++; |
1192 |
} |
1193 |
openedChar = true; |
1194 |
} |
1188 |
} |
1195 |
buffer.append('\''); |
1189 |
tokensBuffer.append('\''); |
1196 |
this.column++; |
|
|
1197 |
} else if (msg == Scanner.INVALID_CHAR_IN_STRING) { |
1190 |
} else if (msg == Scanner.INVALID_CHAR_IN_STRING) { |
1198 |
if (openedString) { |
1191 |
if (openedString) { |
1199 |
openedString = false; |
1192 |
openedString = false; |
1200 |
} else { |
1193 |
} else { |
1201 |
if (insertSpace) { |
1194 |
if (insertSpace) { |
1202 |
buffer.append(' '); |
1195 |
tokensBuffer.append(' '); |
1203 |
this.column++; |
|
|
1204 |
} |
1196 |
} |
1205 |
openedString = true; |
1197 |
openedString = true; |
1206 |
} |
1198 |
} |
1207 |
buffer.append('"'); |
1199 |
tokensBuffer.append('"'); |
1208 |
this.column++; |
|
|
1209 |
} else { |
1200 |
} else { |
1210 |
// skip failure |
1201 |
// skip failure |
1211 |
} |
1202 |
} |
Lines 1218-1226
Link Here
|
1218 |
} |
1209 |
} |
1219 |
|
1210 |
|
1220 |
// Look at specific tokens |
1211 |
// Look at specific tokens |
1221 |
boolean insertSpace = (previousToken == TerminalTokens.TokenNameWHITESPACE || newLine) && !firstWord; |
1212 |
boolean insertSpace = (previousToken == TerminalTokens.TokenNameWHITESPACE || newLine) && (!firstWord || !hasTokens); |
1222 |
switch (token) { |
1213 |
switch (token) { |
1223 |
case TerminalTokens.TokenNameWHITESPACE: |
1214 |
case TerminalTokens.TokenNameWHITESPACE: |
|
|
1215 |
buffer.append(tokensBuffer); |
1216 |
this.column += tokensBuffer.length(); |
1217 |
tokensBuffer.setLength(0); |
1224 |
previousToken = token; |
1218 |
previousToken = token; |
1225 |
lineNumber = Util.getLineNumber(this.scanner.getCurrentTokenEndPosition(), this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1219 |
lineNumber = Util.getLineNumber(this.scanner.getCurrentTokenEndPosition(), this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1226 |
if (lineNumber > scannerLine) { |
1220 |
if (lineNumber > scannerLine) { |
Lines 1230-1237
Link Here
|
1230 |
scannerLine = lineNumber; |
1224 |
scannerLine = lineNumber; |
1231 |
continue; |
1225 |
continue; |
1232 |
case TerminalTokens.TokenNameMULTIPLY: |
1226 |
case TerminalTokens.TokenNameMULTIPLY: |
|
|
1227 |
previousToken = token; |
1233 |
lineNumber = Util.getLineNumber(this.scanner.getCurrentTokenEndPosition(), this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1228 |
lineNumber = Util.getLineNumber(this.scanner.getCurrentTokenEndPosition(), this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1234 |
if (this.scanner.currentCharacter == '/') { |
1229 |
if (this.scanner.currentCharacter == '/') { |
|
|
1230 |
// Add remaining buffered tokens |
1231 |
if (tokensBuffer.length() > 0) { |
1232 |
buffer.append(tokensBuffer); |
1233 |
this.column += tokensBuffer.length(); |
1234 |
} |
1235 |
// end of comment |
1235 |
// end of comment |
1236 |
if (multiLines) { |
1236 |
if (multiLines) { |
1237 |
buffer.append(this.lineSeparator); |
1237 |
buffer.append(this.lineSeparator); |
Lines 1240-1303
Link Here
|
1240 |
} |
1240 |
} |
1241 |
buffer.append(' '); |
1241 |
buffer.append(' '); |
1242 |
buffer.append(BLOCK_FOOTER); |
1242 |
buffer.append(BLOCK_FOOTER); |
1243 |
this.column += BLOCK_LINE_PREFIX_LENGTH + 1; |
1243 |
this.column += BLOCK_FOOTER_LENGTH + 1; |
1244 |
this.scanner.getNextChar(); // reach the end of scanner |
1244 |
this.scanner.getNextChar(); // reach the end of scanner |
1245 |
continue; |
1245 |
continue; |
1246 |
} |
1246 |
} |
1247 |
scannerLine = lineNumber; |
1247 |
scannerLine = lineNumber; |
1248 |
continue; |
1248 |
continue; |
1249 |
case TerminalTokens.TokenNameLESS: |
|
|
1250 |
// We cannot break tags |
1251 |
StringBuffer breakBuffer = new StringBuffer(); |
1252 |
int start = this.scanner.startPosition; |
1253 |
int tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - this.scanner.startPosition; |
1254 |
breakBuffer.append(this.scanner.source, this.scanner.startPosition, tokenLength); |
1255 |
try { |
1256 |
boolean closing = false; |
1257 |
if ((token = this.scanner.getNextToken()) == TerminalTokens.TokenNameDIVIDE) { |
1258 |
tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - this.scanner.startPosition; |
1259 |
breakBuffer.append(this.scanner.source, this.scanner.startPosition, tokenLength); |
1260 |
token = this.scanner.getNextToken(); |
1261 |
closing = true; |
1262 |
} |
1263 |
if (token == TerminalTokens.TokenNameIdentifier) { |
1264 |
tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - this.scanner.startPosition; |
1265 |
breakBuffer.append(this.scanner.source, this.scanner.startPosition, tokenLength); |
1266 |
token = this.scanner.getNextToken(); |
1267 |
if (token == TerminalTokens.TokenNameGREATER) { |
1268 |
tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - this.scanner.startPosition; |
1269 |
breakBuffer.append(this.scanner.source, this.scanner.startPosition, tokenLength); |
1270 |
if ((this.column + breakBuffer.length()) > maxColumn) { |
1271 |
buffer.append(this.lineSeparator); |
1272 |
this.column = 1; |
1273 |
printIndentationIfNecessary(buffer); |
1274 |
buffer.append(BLOCK_LINE_PREFIX); |
1275 |
this.column += BLOCK_LINE_PREFIX_LENGTH; |
1276 |
multiLines = true; |
1277 |
} else if (!closing) { |
1278 |
buffer.append(' '); |
1279 |
this.column++; |
1280 |
} |
1281 |
buffer.append(breakBuffer); |
1282 |
this.column += breakBuffer.length(); |
1283 |
previousToken = token; |
1284 |
scannerLine = lineNumber; |
1285 |
newLine = false; |
1286 |
continue; |
1287 |
} |
1288 |
} |
1289 |
} |
1290 |
catch (InvalidInputException iie) { |
1291 |
// forget as we're started after next token |
1292 |
} |
1293 |
// Need to retrieve correct position |
1294 |
this.scanner.resetTo(start, currentTokenEndPosition-1); |
1295 |
try { |
1296 |
token = this.scanner.getNextToken(); |
1297 |
} catch (InvalidInputException e) { |
1298 |
// will not happen |
1299 |
} |
1300 |
break; |
1301 |
} |
1249 |
} |
1302 |
|
1250 |
|
1303 |
// Look at gap and insert corresponding lines if necessary |
1251 |
// Look at gap and insert corresponding lines if necessary |
Lines 1324-1329
Link Here
|
1324 |
} |
1272 |
} |
1325 |
} |
1273 |
} |
1326 |
for (int i=0; i<linesGap; i++) { |
1274 |
for (int i=0; i<linesGap; i++) { |
|
|
1275 |
// Add remaining buffered tokens |
1276 |
if (tokensBuffer.length() > 0) { |
1277 |
buffer.append(tokensBuffer); |
1278 |
tokensBuffer.setLength(0); |
1279 |
} |
1327 |
buffer.append(this.lineSeparator); |
1280 |
buffer.append(this.lineSeparator); |
1328 |
this.column = 1; |
1281 |
this.column = 1; |
1329 |
printIndentationIfNecessary(buffer); |
1282 |
printIndentationIfNecessary(buffer); |
Lines 1343-1370
Link Here
|
1343 |
hasTokens = true; |
1296 |
hasTokens = true; |
1344 |
if (!hastTextOnFirstLine && scannerLine == firstLine) { |
1297 |
if (!hastTextOnFirstLine && scannerLine == firstLine) { |
1345 |
hastTextOnFirstLine = true; |
1298 |
hastTextOnFirstLine = true; |
1346 |
this.column++; |
|
|
1347 |
} |
1299 |
} |
1348 |
this.column += tokenLength; |
1300 |
int lastColumn = this.column + tokensBuffer.length() + tokenLength; |
1349 |
if (previousToken == -1 || insertSpace) this.column++; |
1301 |
if (previousToken == -1 || insertSpace) lastColumn++; |
1350 |
|
1302 |
|
1351 |
// Append next token inserting a new line if max line is reached |
1303 |
// Append next token inserting a new line if max line is reached |
1352 |
if (!firstWord && this.column > maxColumn) { |
1304 |
if (!firstWord && lastColumn > maxColumn) { |
|
|
1305 |
String tokensString = tokensBuffer.toString().trim(); |
1306 |
if ((firstColumn+tokensString.length()+tokenLength) > maxColumn) { |
1307 |
// there won't be enough room even if we break the line before the buffered tokens |
1308 |
// So add the buffered tokens now |
1309 |
if (buffer.length() == 0) { |
1310 |
buffer.append(' '); |
1311 |
this.column++; |
1312 |
} |
1313 |
buffer.append(tokensString); |
1314 |
this.column += tokensString.length(); |
1315 |
tokensBuffer.setLength(0); |
1316 |
} |
1353 |
// not enough space on the line |
1317 |
// not enough space on the line |
1354 |
buffer.append(this.lineSeparator); |
1318 |
buffer.append(this.lineSeparator); |
1355 |
this.column = 1; |
1319 |
this.column = 1; |
1356 |
printIndentationIfNecessary(buffer); |
1320 |
printIndentationIfNecessary(buffer); |
1357 |
buffer.append(BLOCK_LINE_PREFIX); |
1321 |
buffer.append(BLOCK_LINE_PREFIX); |
1358 |
this.column += BLOCK_LINE_PREFIX_LENGTH; |
1322 |
this.column += BLOCK_LINE_PREFIX_LENGTH; |
|
|
1323 |
if (tokensBuffer.length() > 0) { |
1324 |
buffer.append(tokensString); |
1325 |
this.column += tokensString.length(); |
1326 |
tokensBuffer.setLength(0); |
1327 |
} |
1359 |
buffer.append(this.scanner.source, tokenStart, tokenLength); |
1328 |
buffer.append(this.scanner.source, tokenStart, tokenLength); |
1360 |
this.column += tokenLength; |
1329 |
this.column += tokenLength; |
1361 |
multiLines = true; |
1330 |
multiLines = true; |
1362 |
} else { |
1331 |
} else { |
1363 |
// append token to the line |
1332 |
// append token to the line |
1364 |
if (insertSpace) { |
1333 |
if (insertSpace) { |
1365 |
if (buffer.length() > 0) buffer.append(' '); |
1334 |
tokensBuffer.append(' '); |
1366 |
} |
1335 |
} |
1367 |
buffer.append(this.scanner.source, tokenStart, tokenLength); |
1336 |
tokensBuffer.append(this.scanner.source, tokenStart, tokenLength); |
1368 |
} |
1337 |
} |
1369 |
previousToken = token; |
1338 |
previousToken = token; |
1370 |
newLine = false; |
1339 |
newLine = false; |
Lines 1380-1390
Link Here
|
1380 |
replacement.append(this.lineSeparator); |
1349 |
replacement.append(this.lineSeparator); |
1381 |
this.column = 1; |
1350 |
this.column = 1; |
1382 |
printIndentationIfNecessary(replacement); |
1351 |
printIndentationIfNecessary(replacement); |
1383 |
replacement.append(BLOCK_LINE_PREFIX); |
1352 |
if (buffer.charAt(0) == ' ') { |
|
|
1353 |
replacement.append(' '); |
1354 |
replacement.append('*'); |
1355 |
} else { |
1356 |
replacement.append(BLOCK_LINE_PREFIX); |
1357 |
this.column++; |
1358 |
} |
1384 |
this.column = col; |
1359 |
this.column = col; |
1385 |
} |
1360 |
} |
1386 |
} else { |
1361 |
} else { |
1387 |
if (hasTokens) replacement.append(' '); |
1362 |
if (buffer.charAt(0) != ' ') { |
|
|
1363 |
replacement.append(' '); |
1364 |
this.column++; |
1365 |
} |
1388 |
} |
1366 |
} |
1389 |
replacement.append(buffer); |
1367 |
replacement.append(buffer); |
1390 |
addReplaceEdit(currentTokenStartPosition, currentTokenEndPosition-1, replacement.toString()); |
1368 |
addReplaceEdit(currentTokenStartPosition, currentTokenEndPosition-1, replacement.toString()); |
Lines 2057-2074
Link Here
|
2057 |
int maxNodes = block.nodesPtr; |
2035 |
int maxNodes = block.nodesPtr; |
2058 |
|
2036 |
|
2059 |
// format tag section if necessary |
2037 |
// format tag section if necessary |
|
|
2038 |
int maxColumn = this.formatter.preferences.comment_line_length; |
2039 |
boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment; |
2060 |
if (!block.isDescription()) { |
2040 |
if (!block.isDescription()) { |
2061 |
this.column += previousEnd - block.sourceStart + 1; |
2041 |
this.column += previousEnd - block.sourceStart + 1; |
2062 |
if (block.isInlined()) { |
2042 |
if (block.isInlined()) { |
2063 |
this.column++; // Add extra character for inline tag |
2043 |
this.column++; // Add extra character for inline tag |
2064 |
} |
2044 |
} |
2065 |
FormatJavadocNode reference= block.reference; |
2045 |
FormatJavadocReference reference= block.reference; |
2066 |
if (reference != null) { |
2046 |
if (reference != null) { |
2067 |
// format between tag name and reference |
2047 |
// format reference |
2068 |
addReplaceEdit(previousEnd+1, reference.sourceStart - 1, " "); //$NON-NLS-1$ |
2048 |
StringBuffer buffer = new StringBuffer(); |
2069 |
this.column++; |
2049 |
printJavadocBlockReference(buffer, reference, block); |
|
|
2050 |
addReplaceEdit(previousEnd+1, reference.sourceEnd, buffer.toString()); |
2070 |
previousEnd = reference.sourceEnd; |
2051 |
previousEnd = reference.sourceEnd; |
2071 |
this.column += previousEnd - reference.sourceStart + 1; |
|
|
2072 |
} |
2052 |
} |
2073 |
|
2053 |
|
2074 |
// Nothing else to do if the tag has no node |
2054 |
// Nothing else to do if the tag has no node |
Lines 2076-2082
Link Here
|
2076 |
} |
2056 |
} |
2077 |
|
2057 |
|
2078 |
// tag section: iterate through the blocks composing this tag but the last one |
2058 |
// 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++; |
2059 |
if (block.isHeaderLine()) maxColumn++; |
2081 |
for (int i=0; i<=maxNodes; i++) { |
2060 |
for (int i=0; i<=maxNodes; i++) { |
2082 |
FormatJavadocNode node = block.nodes[i]; |
2061 |
FormatJavadocNode node = block.nodes[i]; |
Lines 2084-2093
Link Here
|
2084 |
|
2063 |
|
2085 |
// Print empty lines before the node |
2064 |
// Print empty lines before the node |
2086 |
int textLength = -1; |
2065 |
int textLength = -1; |
|
|
2066 |
int newLines; |
2087 |
if (i == 0) { |
2067 |
if (i == 0) { |
2088 |
int newLines = this.formatter.preferences.comment_insert_new_line_for_parameter && block.isParamTag() ? 1 : 0; |
2068 |
newLines = this.formatter.preferences.comment_insert_new_line_for_parameter && !block.isInlined() && block.isParamTag() ? 1 : 0; |
2089 |
if (nodeStart > (previousEnd+1)) { |
2069 |
if (nodeStart > (previousEnd+1)) { |
2090 |
printJavadocGapLines(previousEnd+1, nodeStart-1, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, false, null); |
2070 |
printJavadocGapLines(previousEnd+1, nodeStart-1, newLines, clearBlankLines, false, null); |
2091 |
} else { |
2071 |
} else { |
2092 |
StringBuffer buffer = new StringBuffer(); |
2072 |
StringBuffer buffer = new StringBuffer(); |
2093 |
if (newLines > 0) { |
2073 |
if (newLines > 0) { |
Lines 2098-2104
Link Here
|
2098 |
} |
2078 |
} |
2099 |
} |
2079 |
} |
2100 |
} else { |
2080 |
} else { |
2101 |
int newLines = this.column > this.formatter.preferences.comment_line_length ? 1 : 0; |
2081 |
newLines = this.column > this.formatter.preferences.comment_line_length ? 1 : 0; |
2102 |
if (node.isText()) { |
2082 |
if (node.isText()) { |
2103 |
// Need to verify if new line is necessary for immutable tag |
2083 |
// Need to verify if new line is necessary for immutable tag |
2104 |
FormatJavadocText text = (FormatJavadocText) node; |
2084 |
FormatJavadocText text = (FormatJavadocText) node; |
Lines 2137-2148
Link Here
|
2137 |
newLines = 1; |
2117 |
newLines = 1; |
2138 |
((FormatJavadocText)node).linesBefore = 1; |
2118 |
((FormatJavadocText)node).linesBefore = 1; |
2139 |
} |
2119 |
} |
2140 |
printJavadocGapLines(previousEnd+1, nodeStart-1, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, false, null); |
2120 |
printJavadocGapLines(previousEnd+1, nodeStart-1, newLines, clearBlankLines, false, null); |
2141 |
} catch (InvalidInputException iie) { |
2121 |
} catch (InvalidInputException iie) { |
2142 |
// skip |
2122 |
// skip |
2143 |
} |
2123 |
} |
2144 |
} else { |
2124 |
} else { |
2145 |
printJavadocGapLines(previousEnd+1, nodeStart-1, newLines, this.formatter.preferences.comment_clear_blank_lines_in_javadoc_comment, false, null); |
2125 |
printJavadocGapLines(previousEnd+1, nodeStart-1, newLines, clearBlankLines, false, null); |
2146 |
} |
2126 |
} |
2147 |
} |
2127 |
} |
2148 |
} |
2128 |
} |
Lines 2156-2161
Link Here
|
2156 |
if (textLength == -1) { |
2136 |
if (textLength == -1) { |
2157 |
textLength = getTextLength(block, text); |
2137 |
textLength = getTextLength(block, text); |
2158 |
} |
2138 |
} |
|
|
2139 |
// Indent if new line was added |
2140 |
if (newLines > 0) { |
2141 |
int col = this.column; |
2142 |
StringBuffer buffer = new StringBuffer(); |
2143 |
int textEnd = text.separatorsPtr == -1 ? text.sourceEnd : (int) (text.separators[0] >>> 32); |
2144 |
printJavadocTextLine(buffer, text.sourceStart, textEnd, block, true, true, true); |
2145 |
addReplaceEdit(text.sourceStart, textEnd, buffer.toString()); |
2146 |
textLength -= this.column - col; |
2147 |
} |
2159 |
this.column += textLength; |
2148 |
this.column += textLength; |
2160 |
} else { |
2149 |
} else { |
2161 |
printJavadocHtmlTag(text, block); |
2150 |
printJavadocHtmlTag(text, block); |
Lines 2172-2177
Link Here
|
2172 |
} |
2161 |
} |
2173 |
} |
2162 |
} |
2174 |
|
2163 |
|
|
|
2164 |
private void printJavadocBlockReference(StringBuffer buffer, FormatJavadocReference reference, FormatJavadocBlock block) { |
2165 |
|
2166 |
boolean indentRootTags = this.formatter.preferences.comment_indent_root_tags && !block.isDescription(); |
2167 |
boolean indentParamTag = this.formatter.preferences.comment_indent_parameter_description && block.isParamTag(); |
2168 |
boolean headerLine = block.isHeaderLine() && this.lastNumberOfNewLines == 0; |
2169 |
StringBuffer tokensBuffer = new StringBuffer(); |
2170 |
|
2171 |
// First we need to know what is the indentation |
2172 |
int firstColumn = 1 + this.indentationLevel + BLOCK_LINE_PREFIX_LENGTH; |
2173 |
if (headerLine) firstColumn++; |
2174 |
StringBuffer indentationBuffer = null; |
2175 |
if (indentRootTags) { |
2176 |
int indentLevel = this.indentationLevel; |
2177 |
int indentations = this.numberOfIndentations; |
2178 |
this.numberOfIndentations += (BLOCK_LINE_PREFIX_LENGTH / this.indentationSize) + 1; |
2179 |
this.indentationLevel = this.numberOfIndentations * this.indentationSize; |
2180 |
int currentColumn = this.column; |
2181 |
this.column = firstColumn; |
2182 |
if (indentParamTag) { |
2183 |
this.indentationLevel += this.indentationSize; |
2184 |
this.numberOfIndentations++; |
2185 |
} |
2186 |
printIndentationIfNecessary(indentationBuffer = new StringBuffer()); |
2187 |
firstColumn = this.indentationLevel + 1; |
2188 |
this.column = currentColumn; |
2189 |
this.indentationLevel = indentLevel; |
2190 |
this.numberOfIndentations = indentations; |
2191 |
} |
2192 |
|
2193 |
// Scan the text token per token to compact it and size it the max line length |
2194 |
int maxColumn = this.formatter.preferences.comment_line_length + 1; |
2195 |
int previousToken = -1; |
2196 |
this.scanner.resetTo(reference.sourceStart, reference.sourceEnd); |
2197 |
while (!this.scanner.atEnd()) { |
2198 |
int token; |
2199 |
try { |
2200 |
token = this.scanner.getNextToken(); |
2201 |
switch (token) { |
2202 |
case TerminalTokens.TokenNameWHITESPACE: |
2203 |
buffer.append(tokensBuffer); |
2204 |
this.column += tokensBuffer.length(); |
2205 |
tokensBuffer.setLength(0); |
2206 |
if (CharOperation.indexOf('\n', this.scanner.source, this.scanner.startPosition, this.scanner.getCurrentTokenEndPosition()) >= 0) { |
2207 |
// consume line break |
2208 |
loop: while (true) { |
2209 |
token = this.scanner.getNextToken(); |
2210 |
switch (token) { |
2211 |
case TerminalTokens.TokenNameWHITESPACE: |
2212 |
case TerminalTokens.TokenNameMULTIPLY: |
2213 |
previousToken = token; // will not insert space |
2214 |
continue; |
2215 |
default: |
2216 |
break loop; |
2217 |
} |
2218 |
} |
2219 |
break; |
2220 |
} |
2221 |
previousToken = token; |
2222 |
continue; |
2223 |
case TerminalTokens.TokenNameMULTIPLY: |
2224 |
previousToken = token; |
2225 |
continue; |
2226 |
} |
2227 |
} catch (InvalidInputException iie) { |
2228 |
continue; |
2229 |
} |
2230 |
int tokenStart = this.scanner.getCurrentTokenStartPosition(); |
2231 |
int tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - tokenStart; |
2232 |
int lastColumn = this.column + tokensBuffer.length() + tokenLength; |
2233 |
boolean insertSpace = previousToken == TerminalTokens.TokenNameWHITESPACE || previousToken == -1; |
2234 |
if (insertSpace) lastColumn++; |
2235 |
if (headerLine) { |
2236 |
// special case when text is on the same line of the javadoc's header |
2237 |
if (lastColumn > maxColumn) { |
2238 |
lastColumn--; // new line gives an extra character |
2239 |
} |
2240 |
} |
2241 |
if (lastColumn > maxColumn) { |
2242 |
String tokensString = tokensBuffer.toString().trim(); |
2243 |
int indentLength = indentationBuffer==null ? 0 : indentationBuffer.length(); |
2244 |
if ((firstColumn-1+indentLength+tokensString.length()+tokenLength) > maxColumn) { |
2245 |
// there won't be enough room even if we break the line before the buffered tokens |
2246 |
// So add the buffered tokens now |
2247 |
if (buffer.length() == 0) { |
2248 |
buffer.append(' '); |
2249 |
this.column++; |
2250 |
} |
2251 |
buffer.append(tokensString); |
2252 |
this.column += tokensString.length(); |
2253 |
tokensBuffer.setLength(0); |
2254 |
} |
2255 |
// not enough space on the line |
2256 |
buffer.append(this.lineSeparator); |
2257 |
this.column = 1; |
2258 |
printIndentationIfNecessary(buffer); |
2259 |
buffer.append(BLOCK_LINE_PREFIX); |
2260 |
this.column = headerLine ? firstColumn-1 : firstColumn; |
2261 |
if (indentationBuffer != null) { |
2262 |
buffer.append(indentationBuffer); |
2263 |
} |
2264 |
if (tokensBuffer.length() > 0) { |
2265 |
buffer.append(tokensString); |
2266 |
this.column += tokensString.length(); |
2267 |
tokensBuffer.setLength(0); |
2268 |
} |
2269 |
buffer.append(this.scanner.source, tokenStart, tokenLength); |
2270 |
this.column += tokenLength; |
2271 |
if (headerLine) { |
2272 |
firstColumn--; |
2273 |
headerLine = false; |
2274 |
} |
2275 |
} else { |
2276 |
// append token to the line |
2277 |
if (insertSpace) { |
2278 |
tokensBuffer.append(' '); |
2279 |
} |
2280 |
tokensBuffer.append(this.scanner.source, tokenStart, tokenLength); |
2281 |
} |
2282 |
previousToken = token; |
2283 |
} |
2284 |
if (tokensBuffer.length() > 0) { |
2285 |
buffer.append(tokensBuffer); |
2286 |
this.column += tokensBuffer.length(); |
2287 |
} |
2288 |
} |
2289 |
|
2175 |
private int getTextLength(FormatJavadocBlock block, FormatJavadocText text) { |
2290 |
private int getTextLength(FormatJavadocBlock block, FormatJavadocText text) { |
2176 |
|
2291 |
|
2177 |
// Simple for one line tags |
2292 |
// Simple for one line tags |
Lines 2482-2488
Link Here
|
2482 |
int textStart = text.sourceStart; |
2597 |
int textStart = text.sourceStart; |
2483 |
int nextStart = textStart; |
2598 |
int nextStart = textStart; |
2484 |
int startLine = Util.getLineNumber(textStart, this.lineEnds, 0, this.maxLines); |
2599 |
int startLine = Util.getLineNumber(textStart, this.lineEnds, 0, this.maxLines); |
2485 |
boolean textOnNewLine = (text == block.nodes[0] && ((block.isParamTag() && this.formatter.preferences.comment_insert_new_line_for_parameter) || !block.hasTextOnTagLine())) || text.linesBefore > 0; |
2600 |
boolean textOnNewLine = (text == block.nodes[0] && ((!block.isInlined() && block.isParamTag() && this.formatter.preferences.comment_insert_new_line_for_parameter) || !block.hasTextOnTagLine())) || text.linesBefore > 0; |
2486 |
int htmlTagID = text.getHtmlTagID(); |
2601 |
int htmlTagID = text.getHtmlTagID(); |
2487 |
StringBuffer buffer = new StringBuffer(); |
2602 |
StringBuffer buffer = new StringBuffer(); |
2488 |
|
2603 |
|
Lines 2510-2516
Link Here
|
2510 |
} |
2625 |
} |
2511 |
if (textStart < previousEnd) { |
2626 |
if (textStart < previousEnd) { |
2512 |
addReplaceEdit(textStart, previousEnd, buffer.toString()); |
2627 |
addReplaceEdit(textStart, previousEnd, buffer.toString()); |
2513 |
// this.column += buffer.length(); |
|
|
2514 |
} |
2628 |
} |
2515 |
boolean immutable = htmlTag == null ? false : htmlTag.isImmutableHtmlTag(); |
2629 |
boolean immutable = htmlTag == null ? false : htmlTag.isImmutableHtmlTag(); |
2516 |
boolean overEndLine = false; |
2630 |
boolean overEndLine = false; |
Lines 2533-2540
Link Here
|
2533 |
if (indentationBuffer != null) { |
2647 |
if (indentationBuffer != null) { |
2534 |
addInsertEdit(node.sourceStart, indentationBuffer.toString()); |
2648 |
addInsertEdit(node.sourceStart, indentationBuffer.toString()); |
2535 |
} |
2649 |
} |
2536 |
// buffer.append(' '); |
|
|
2537 |
// this.column++; |
2538 |
} |
2650 |
} |
2539 |
} else { |
2651 |
} else { |
2540 |
linesAfter = printJavadocHtmlTag(htmlTag, block); |
2652 |
linesAfter = printJavadocHtmlTag(htmlTag, block); |
Lines 2554-2560
Link Here
|
2554 |
printJavadocGapLines(previousEnd+1, nextStart, linesAfter, clearBlankLines, false, buffer); |
2666 |
printJavadocGapLines(previousEnd+1, nextStart, linesAfter, clearBlankLines, false, buffer); |
2555 |
textOnNewLine = true; |
2667 |
textOnNewLine = true; |
2556 |
} |
2668 |
} |
2557 |
boolean needIndentation = buffer.length() == 0 && textOnNewLine; |
2669 |
boolean needIndentation = textOnNewLine; |
2558 |
if (idx > 0) { |
2670 |
if (idx > 0) { |
2559 |
if (!needIndentation && (text.htmlIndexes[idx-1] & JAVADOC_TAGS_ID_MASK) == JAVADOC_SEPARATOR_TAGS_ID) { |
2671 |
if (!needIndentation && (text.htmlIndexes[idx-1] & JAVADOC_TAGS_ID_MASK) == JAVADOC_SEPARATOR_TAGS_ID) { |
2560 |
needIndentation = true; |
2672 |
needIndentation = true; |
Lines 2580-2586
Link Here
|
2580 |
if (clearBlankLines) { |
2692 |
if (clearBlankLines) { |
2581 |
// keep previously computed lines after |
2693 |
// keep previously computed lines after |
2582 |
} else { |
2694 |
} else { |
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)) { |
2695 |
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)) { |
2585 |
if (linesAfter < linesGap) { |
2696 |
if (linesAfter < linesGap) { |
2586 |
linesAfter = linesGap; |
2697 |
linesAfter = linesGap; |
Lines 2668-2674
Link Here
|
2668 |
int textStart = text.sourceStart; |
2779 |
int textStart = text.sourceStart; |
2669 |
int nextStart = textStart; |
2780 |
int nextStart = textStart; |
2670 |
int startLine = Util.getLineNumber(textStart, this.lineEnds, 0, this.maxLines); |
2781 |
int startLine = Util.getLineNumber(textStart, this.lineEnds, 0, this.maxLines); |
2671 |
boolean textOnNewLine = (text == block.nodes[0] && block.isParamTag() && (this.formatter.preferences.comment_insert_new_line_for_parameter || !block.hasTextOnTagLine())) || text.linesBefore > 0; |
2782 |
boolean textOnNewLine = (text == block.nodes[0] && !block.isInlined() && block.isParamTag() && (this.formatter.preferences.comment_insert_new_line_for_parameter || !block.hasTextOnTagLine())) || text.linesBefore > 0 || this.column > (this.formatter.preferences.comment_line_length+1); |
2672 |
|
2783 |
|
2673 |
// Iterate on text line separators |
2784 |
// Iterate on text line separators |
2674 |
for (int idx=0, max=text.separatorsPtr; idx<=max ; idx++) { |
2785 |
for (int idx=0, max=text.separatorsPtr; idx<=max ; idx++) { |
Lines 2719-2725
Link Here
|
2719 |
boolean indentRootTags = this.formatter.preferences.comment_indent_root_tags && !block.isDescription(); |
2830 |
boolean indentRootTags = this.formatter.preferences.comment_indent_root_tags && !block.isDescription(); |
2720 |
boolean indentParamTag = this.formatter.preferences.comment_indent_parameter_description && block.isParamTag(); |
2831 |
boolean indentParamTag = this.formatter.preferences.comment_indent_parameter_description && block.isParamTag(); |
2721 |
boolean headerLine = (buffer.indexOf(Util.LINE_SEPARATOR) < 0) && block.isHeaderLine() && this.lastNumberOfNewLines == 0; |
2832 |
boolean headerLine = (buffer.indexOf(Util.LINE_SEPARATOR) < 0) && block.isHeaderLine() && this.lastNumberOfNewLines == 0; |
2722 |
StringBuffer textBuffer = isHtmlTag ? new StringBuffer() : buffer; |
2833 |
StringBuffer tokensBuffer = new StringBuffer(); |
2723 |
|
2834 |
|
2724 |
// First we need to know what is the indentation |
2835 |
// First we need to know what is the indentation |
2725 |
int firstColumn = 1 + this.indentationLevel + BLOCK_LINE_PREFIX_LENGTH; |
2836 |
int firstColumn = 1 + this.indentationLevel + BLOCK_LINE_PREFIX_LENGTH; |
Lines 2739-2745
Link Here
|
2739 |
printIndentationIfNecessary(indentationBuffer = new StringBuffer()); |
2850 |
printIndentationIfNecessary(indentationBuffer = new StringBuffer()); |
2740 |
if (needIndentation) { |
2851 |
if (needIndentation) { |
2741 |
this.column = firstColumn; |
2852 |
this.column = firstColumn; |
2742 |
printIndentationIfNecessary(textBuffer); |
2853 |
printIndentationIfNecessary(buffer); |
2743 |
} |
2854 |
} |
2744 |
firstColumn = this.indentationLevel + 1; |
2855 |
firstColumn = this.indentationLevel + 1; |
2745 |
this.column = currentColumn < firstColumn ? firstColumn : currentColumn; |
2856 |
this.column = currentColumn < firstColumn ? firstColumn : currentColumn; |
Lines 2767-2789
Link Here
|
2767 |
String msg = iie.getMessage(); |
2878 |
String msg = iie.getMessage(); |
2768 |
if (msg == Scanner.INVALID_CHARACTER_CONSTANT) { |
2879 |
if (msg == Scanner.INVALID_CHARACTER_CONSTANT) { |
2769 |
if (insertSpace) { |
2880 |
if (insertSpace) { |
2770 |
buffer.append(' '); |
2881 |
tokensBuffer.append(' '); |
2771 |
this.column++; |
|
|
2772 |
} |
2882 |
} |
2773 |
buffer.append('\''); |
2883 |
tokensBuffer.append('\''); |
2774 |
this.column++; |
|
|
2775 |
} else if (msg == Scanner.INVALID_CHAR_IN_STRING) { |
2884 |
} else if (msg == Scanner.INVALID_CHAR_IN_STRING) { |
2776 |
if (openedString) { |
2885 |
if (openedString) { |
2777 |
openedString = false; |
2886 |
openedString = false; |
2778 |
} else { |
2887 |
} else { |
2779 |
if (insertSpace) { |
2888 |
if (insertSpace) { |
2780 |
buffer.append(' '); |
2889 |
tokensBuffer.append(' '); |
2781 |
this.column++; |
|
|
2782 |
} |
2890 |
} |
2783 |
openedString = true; |
2891 |
openedString = true; |
2784 |
} |
2892 |
} |
2785 |
buffer.append('"'); |
2893 |
tokensBuffer.append('"'); |
2786 |
this.column++; |
|
|
2787 |
} else { |
2894 |
} else { |
2788 |
// skip failure |
2895 |
// skip failure |
2789 |
} |
2896 |
} |
Lines 2795-2818
Link Here
|
2795 |
} |
2902 |
} |
2796 |
if (token == TerminalTokens.TokenNameWHITESPACE) { |
2903 |
if (token == TerminalTokens.TokenNameWHITESPACE) { |
2797 |
previousToken = token; |
2904 |
previousToken = token; |
|
|
2905 |
buffer.append(tokensBuffer); |
2906 |
this.column += tokensBuffer.length(); |
2907 |
tokensBuffer.setLength(0); |
2798 |
continue; |
2908 |
continue; |
2799 |
} |
2909 |
} |
2800 |
int tokenStart = this.scanner.getCurrentTokenStartPosition(); |
2910 |
int tokenStart = this.scanner.getCurrentTokenStartPosition(); |
2801 |
int tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - tokenStart; |
2911 |
int tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - tokenStart; |
2802 |
boolean insertSpace = previousToken == TerminalTokens.TokenNameWHITESPACE || (tokenStart == textStart && this.column > firstColumn && !(firstText || isHtmlTag)); |
2912 |
boolean insertSpace = previousToken == TerminalTokens.TokenNameWHITESPACE || (tokenStart == textStart && this.column > firstColumn && !(firstText || isHtmlTag)); |
2803 |
this.column += tokenLength; |
2913 |
int lastColumn = this.column + tokensBuffer.length() + tokenLength; |
2804 |
if (insertSpace) this.column++; |
2914 |
if (insertSpace) lastColumn++; |
2805 |
int col = column; |
|
|
2806 |
if (headerLine) { |
2915 |
if (headerLine) { |
2807 |
// special case when text is on the same line of the javadoc's header |
2916 |
// special case when text is on the same line of the javadoc's header |
2808 |
if (col > maxColumn) { |
2917 |
if (lastColumn > maxColumn) { |
2809 |
col--; // new line gives an extra character |
2918 |
lastColumn--; // new line gives an extra character |
2810 |
this.lastNumberOfNewLines++; // in case we leave just after |
2919 |
this.lastNumberOfNewLines++; // in case we leave just after |
2811 |
} |
2920 |
} |
2812 |
} |
2921 |
} |
2813 |
if (col > maxColumn) { |
2922 |
if (lastColumn > maxColumn) { |
2814 |
// not enough space on the line |
2923 |
// not enough space on the line |
2815 |
if (col == this.column) this.lastNumberOfNewLines++; |
2924 |
if (lastColumn == this.column) this.lastNumberOfNewLines++; |
2816 |
buffer.append(this.lineSeparator); |
2925 |
buffer.append(this.lineSeparator); |
2817 |
this.column = 1; |
2926 |
this.column = 1; |
2818 |
printIndentationIfNecessary(buffer); |
2927 |
printIndentationIfNecessary(buffer); |
Lines 2821-2831
Link Here
|
2821 |
if (indentationBuffer != null) { |
2930 |
if (indentationBuffer != null) { |
2822 |
buffer.append(indentationBuffer); |
2931 |
buffer.append(indentationBuffer); |
2823 |
} |
2932 |
} |
2824 |
if (isHtmlTag && buffer != textBuffer) { |
2933 |
if (tokensBuffer.length() > 0) { |
2825 |
buffer.append(textBuffer); |
2934 |
String tokensString = tokensBuffer.toString().trim(); |
2826 |
textBuffer = buffer; |
2935 |
buffer.append(tokensString); |
2827 |
} |
2936 |
this.column += tokensString.length(); |
2828 |
textBuffer.append(this.scanner.source, tokenStart, tokenLength); |
2937 |
tokensBuffer.setLength(0); |
|
|
2938 |
} |
2939 |
buffer.append(this.scanner.source, tokenStart, tokenLength); |
2829 |
this.column += tokenLength; |
2940 |
this.column += tokenLength; |
2830 |
if (headerLine) { |
2941 |
if (headerLine) { |
2831 |
firstColumn--; |
2942 |
firstColumn--; |
Lines 2833-2850
Link Here
|
2833 |
} |
2944 |
} |
2834 |
} else { |
2945 |
} else { |
2835 |
// append token to the line |
2946 |
// append token to the line |
2836 |
if (insertSpace) { |
2947 |
if (insertSpace) { |
2837 |
textBuffer.append(' '); |
2948 |
tokensBuffer.append(' '); |
2838 |
} |
2949 |
} |
2839 |
textBuffer.append(this.scanner.source, tokenStart, tokenLength); |
2950 |
tokensBuffer.append(this.scanner.source, tokenStart, tokenLength); |
2840 |
} |
2951 |
} |
2841 |
previousToken = token; |
2952 |
previousToken = token; |
2842 |
} |
2953 |
} |
2843 |
} |
2954 |
} |
2844 |
finally { |
2955 |
finally { |
2845 |
this.scanner.skipComments = false; |
2956 |
this.scanner.skipComments = false; |
2846 |
if (isHtmlTag && buffer != textBuffer) { |
2957 |
// Add remaining buffered tokens |
2847 |
buffer.append(textBuffer); |
2958 |
if (tokensBuffer.length() > 0) { |
|
|
2959 |
buffer.append(tokensBuffer); |
2960 |
this.column += tokensBuffer.length(); |
2848 |
} |
2961 |
} |
2849 |
} |
2962 |
} |
2850 |
} |
2963 |
} |