Lines 797-810
Link Here
|
797 |
case '\t' : |
797 |
case '\t' : |
798 |
offset += this.tabLength; |
798 |
offset += this.tabLength; |
799 |
break; |
799 |
break; |
800 |
case ' ' : |
|
|
801 |
offset++; |
802 |
break; |
803 |
case '\r' : |
800 |
case '\r' : |
804 |
case '\n' : |
801 |
case '\n' : |
805 |
break; |
802 |
break; |
806 |
default: |
803 |
default: |
807 |
return offset; |
804 |
offset++; |
|
|
805 |
break; |
808 |
} |
806 |
} |
809 |
} |
807 |
} |
810 |
return offset; |
808 |
return offset; |
Lines 1250-1300
Link Here
|
1250 |
this.needSpace = false; |
1248 |
this.needSpace = false; |
1251 |
this.pendingSpace = false; |
1249 |
this.pendingSpace = false; |
1252 |
|
1250 |
|
|
|
1251 |
int commentColumn = this.column; |
1253 |
if (includesBlockComments) { |
1252 |
if (includesBlockComments) { |
1254 |
if (printBlockComment(currentTokenStartPosition, currentTokenEndPosition)) { |
1253 |
if (printBlockComment(currentTokenStartPosition, currentTokenEndPosition)) { |
1255 |
return; |
1254 |
return; |
1256 |
} |
1255 |
} |
1257 |
} |
1256 |
} |
1258 |
|
1257 |
|
|
|
1258 |
int currentIndentationLevel = this.indentationLevel; |
1259 |
if ((commentColumn-1) > this.indentationLevel) { |
1260 |
this.indentationLevel = commentColumn-1; |
1261 |
} |
1259 |
int currentCommentOffset = onFirstColumn ? 0 : getCurrentCommentOffset(start); |
1262 |
int currentCommentOffset = onFirstColumn ? 0 : getCurrentCommentOffset(start); |
1260 |
boolean formatComment = (isJavadoc && (this.formatComments & CodeFormatter.K_JAVA_DOC) != 0) || (!isJavadoc && (this.formatComments & CodeFormatter.K_MULTI_LINE_COMMENT) != 0); |
1263 |
boolean formatComment = (isJavadoc && (this.formatComments & CodeFormatter.K_JAVA_DOC) != 0) || (!isJavadoc && (this.formatComments & CodeFormatter.K_MULTI_LINE_COMMENT) != 0); |
1261 |
|
1264 |
|
1262 |
while (nextCharacterStart <= currentTokenEndPosition && (currentCharacter = this.scanner.getNextChar()) != -1) { |
1265 |
try { |
1263 |
nextCharacterStart = this.scanner.currentPosition; |
1266 |
while (nextCharacterStart <= currentTokenEndPosition && (currentCharacter = this.scanner.getNextChar()) != -1) { |
1264 |
|
1267 |
nextCharacterStart = this.scanner.currentPosition; |
1265 |
switch(currentCharacter) { |
1268 |
|
1266 |
case '\r' : |
1269 |
switch(currentCharacter) { |
1267 |
start = previousStart; |
1270 |
case '\r' : |
1268 |
isNewLine = true; |
1271 |
start = previousStart; |
1269 |
if (this.scanner.getNextChar('\n')) { |
1272 |
isNewLine = true; |
1270 |
currentCharacter = '\n'; |
1273 |
if (this.scanner.getNextChar('\n')) { |
|
|
1274 |
currentCharacter = '\n'; |
1275 |
nextCharacterStart = this.scanner.currentPosition; |
1276 |
} |
1277 |
break; |
1278 |
case '\n' : |
1279 |
start = previousStart; |
1280 |
isNewLine = true; |
1271 |
nextCharacterStart = this.scanner.currentPosition; |
1281 |
nextCharacterStart = this.scanner.currentPosition; |
1272 |
} |
1282 |
break; |
1273 |
break; |
1283 |
default: |
1274 |
case '\n' : |
1284 |
if (isNewLine) { |
1275 |
start = previousStart; |
1285 |
this.column = 1; |
1276 |
isNewLine = true; |
1286 |
this.line++; |
1277 |
nextCharacterStart = this.scanner.currentPosition; |
1287 |
isNewLine = false; |
1278 |
break; |
1288 |
|
1279 |
default: |
1289 |
StringBuffer buffer = new StringBuffer(); |
1280 |
if (isNewLine) { |
1290 |
if (onFirstColumn) { |
1281 |
this.column = 1; |
1291 |
// simply insert indentation if necessary |
1282 |
this.line++; |
1292 |
buffer.append(this.lineSeparator); |
1283 |
isNewLine = false; |
1293 |
if (indentComment) { |
1284 |
|
1294 |
printIndentationIfNecessary(buffer); |
1285 |
StringBuffer buffer = new StringBuffer(); |
1295 |
} |
1286 |
if (onFirstColumn) { |
1296 |
if (formatComment) { |
1287 |
// simply insert indentation if necessary |
1297 |
if (ScannerHelper.isWhitespace((char) currentCharacter)) { |
1288 |
buffer.append(this.lineSeparator); |
1298 |
int previousStartPosition = this.scanner.currentPosition; |
1289 |
if (indentComment) { |
1299 |
while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { |
1290 |
printIndentationIfNecessary(buffer); |
1300 |
previousStart = nextCharacterStart; |
1291 |
} |
1301 |
previousStartPosition = this.scanner.currentPosition; |
1292 |
if (formatComment) { |
1302 |
currentCharacter = this.scanner.getNextChar(); |
|
|
1303 |
nextCharacterStart = this.scanner.currentPosition; |
1304 |
} |
1305 |
if (currentCharacter == '\r' || currentCharacter == '\n') { |
1306 |
nextCharacterStart = previousStartPosition; |
1307 |
} |
1308 |
} |
1309 |
if (currentCharacter != '\r' && currentCharacter != '\n') { |
1310 |
buffer.append(' '); |
1311 |
} |
1312 |
} else { |
1313 |
if (currentCharacter == '*') { |
1314 |
buffer.append(' '); |
1315 |
} |
1316 |
} |
1317 |
} else { |
1293 |
if (ScannerHelper.isWhitespace((char) currentCharacter)) { |
1318 |
if (ScannerHelper.isWhitespace((char) currentCharacter)) { |
1294 |
int previousStartPosition = this.scanner.currentPosition; |
1319 |
int previousStartPosition = this.scanner.currentPosition; |
1295 |
while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { |
1320 |
int count = 0; |
|
|
1321 |
loop: while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { |
1322 |
if (count >= currentCommentOffset) { |
1323 |
break loop; |
1324 |
} |
1296 |
previousStart = nextCharacterStart; |
1325 |
previousStart = nextCharacterStart; |
1297 |
previousStartPosition = this.scanner.currentPosition; |
1326 |
previousStartPosition = this.scanner.currentPosition; |
|
|
1327 |
switch(currentCharacter) { |
1328 |
case '\t' : |
1329 |
count += this.tabLength; |
1330 |
break; |
1331 |
default : |
1332 |
count ++; |
1333 |
} |
1298 |
currentCharacter = this.scanner.getNextChar(); |
1334 |
currentCharacter = this.scanner.getNextChar(); |
1299 |
nextCharacterStart = this.scanner.currentPosition; |
1335 |
nextCharacterStart = this.scanner.currentPosition; |
1300 |
} |
1336 |
} |
Lines 1302-1363
Link Here
|
1302 |
nextCharacterStart = previousStartPosition; |
1338 |
nextCharacterStart = previousStartPosition; |
1303 |
} |
1339 |
} |
1304 |
} |
1340 |
} |
1305 |
if (currentCharacter != '\r' && currentCharacter != '\n') { |
1341 |
buffer.append(this.lineSeparator); |
1306 |
buffer.append(' '); |
1342 |
if (indentComment) { |
|
|
1343 |
printIndentationIfNecessary(buffer); |
1307 |
} |
1344 |
} |
1308 |
} |
1345 |
if (formatComment) { |
1309 |
} else { |
1346 |
int previousStartTemp = previousStart; |
1310 |
if (ScannerHelper.isWhitespace((char) currentCharacter)) { |
1347 |
int nextCharacterStartTemp = nextCharacterStart; |
1311 |
int previousStartPosition = this.scanner.currentPosition; |
1348 |
while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { |
1312 |
int count = 0; |
1349 |
previousStart = nextCharacterStart; |
1313 |
loop: while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { |
1350 |
currentCharacter = this.scanner.getNextChar(); |
1314 |
if (count >= currentCommentOffset) { |
1351 |
nextCharacterStart = this.scanner.currentPosition; |
1315 |
break loop; |
|
|
1316 |
} |
1352 |
} |
1317 |
previousStart = nextCharacterStart; |
1353 |
if (currentCharacter == '*') { |
1318 |
previousStartPosition = this.scanner.currentPosition; |
1354 |
buffer.append(' '); |
1319 |
switch(currentCharacter) { |
1355 |
} else { |
1320 |
case '\t' : |
1356 |
previousStart = previousStartTemp; |
1321 |
count += this.tabLength; |
1357 |
nextCharacterStart = nextCharacterStartTemp; |
1322 |
break; |
|
|
1323 |
default : |
1324 |
count ++; |
1325 |
} |
1358 |
} |
1326 |
currentCharacter = this.scanner.getNextChar(); |
1359 |
this.scanner.currentPosition = nextCharacterStart; |
1327 |
nextCharacterStart = this.scanner.currentPosition; |
|
|
1328 |
} |
1329 |
if (currentCharacter == '\r' || currentCharacter == '\n') { |
1330 |
nextCharacterStart = previousStartPosition; |
1331 |
} |
1332 |
} |
1333 |
buffer.append(this.lineSeparator); |
1334 |
if (indentComment) { |
1335 |
printIndentationIfNecessary(buffer); |
1336 |
} |
1337 |
if (formatComment) { |
1338 |
int previousStartTemp = previousStart; |
1339 |
int nextCharacterStartTemp = nextCharacterStart; |
1340 |
while(currentCharacter != -1 && currentCharacter != '\r' && currentCharacter != '\n' && ScannerHelper.isWhitespace((char) currentCharacter)) { |
1341 |
previousStart = nextCharacterStart; |
1342 |
currentCharacter = this.scanner.getNextChar(); |
1343 |
nextCharacterStart = this.scanner.currentPosition; |
1344 |
} |
1345 |
if (currentCharacter == '*') { |
1346 |
buffer.append(' '); |
1347 |
} else { |
1360 |
} else { |
1348 |
previousStart = previousStartTemp; |
1361 |
if (currentCharacter == '*') { |
1349 |
nextCharacterStart = nextCharacterStartTemp; |
1362 |
buffer.append(' '); |
|
|
1363 |
} |
1350 |
} |
1364 |
} |
1351 |
this.scanner.currentPosition = nextCharacterStart; |
|
|
1352 |
} |
1365 |
} |
|
|
1366 |
addReplaceEdit(start, previousStart - 1, String.valueOf(buffer)); |
1367 |
} else { |
1368 |
this.column += (nextCharacterStart - previousStart); |
1353 |
} |
1369 |
} |
1354 |
addReplaceEdit(start, previousStart - 1, String.valueOf(buffer)); |
1370 |
} |
1355 |
} else { |
1371 |
previousStart = nextCharacterStart; |
1356 |
this.column += (nextCharacterStart - previousStart); |
1372 |
this.scanner.currentPosition = nextCharacterStart; |
1357 |
} |
|
|
1358 |
} |
1373 |
} |
1359 |
previousStart = nextCharacterStart; |
1374 |
} finally { |
1360 |
this.scanner.currentPosition = nextCharacterStart; |
1375 |
this.indentationLevel = currentIndentationLevel; |
1361 |
} |
1376 |
} |
1362 |
this.lastNumberOfNewLines = 0; |
1377 |
this.lastNumberOfNewLines = 0; |
1363 |
this.needSpace = false; |
1378 |
this.needSpace = false; |
Lines 1366-1372
Link Here
|
1366 |
|
1381 |
|
1367 |
private boolean printBlockComment(int currentTokenStartPosition, int currentTokenEndPosition) { |
1382 |
private boolean printBlockComment(int currentTokenStartPosition, int currentTokenEndPosition) { |
1368 |
|
1383 |
|
1369 |
|
|
|
1370 |
// Compute indentation |
1384 |
// Compute indentation |
1371 |
int maxColumn = this.formatter.preferences.comment_line_length + 1; |
1385 |
int maxColumn = this.formatter.preferences.comment_line_length + 1; |
1372 |
int indentLevel = this.indentationLevel; |
1386 |
int indentLevel = this.indentationLevel; |