Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 1223-1228
Link Here
|
1223 |
private void printBlockComment(boolean isJavadoc) { |
1223 |
private void printBlockComment(boolean isJavadoc) { |
1224 |
int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition(); |
1224 |
int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition(); |
1225 |
int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1; |
1225 |
int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1; |
|
|
1226 |
boolean includesBlockComments = includesBlockComments(); |
1226 |
|
1227 |
|
1227 |
this.scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition - 1); |
1228 |
this.scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition - 1); |
1228 |
int currentCharacter; |
1229 |
int currentCharacter; |
Lines 1247-1253
Link Here
|
1247 |
this.needSpace = false; |
1248 |
this.needSpace = false; |
1248 |
this.pendingSpace = false; |
1249 |
this.pendingSpace = false; |
1249 |
|
1250 |
|
1250 |
if (includesBlockComments()) { |
1251 |
if (includesBlockComments) { |
1251 |
if (printBlockComment(currentTokenStartPosition, currentTokenEndPosition)) { |
1252 |
if (printBlockComment(currentTokenStartPosition, currentTokenEndPosition)) { |
1252 |
return; |
1253 |
return; |
1253 |
} |
1254 |
} |
Lines 1424-1429
Link Here
|
1424 |
boolean hasMultiLines = false; |
1425 |
boolean hasMultiLines = false; |
1425 |
boolean hasTokens = false; |
1426 |
boolean hasTokens = false; |
1426 |
boolean bufferHasTokens = false; |
1427 |
boolean bufferHasTokens = false; |
|
|
1428 |
boolean lineHasTokens = false; |
1427 |
int hasTextOnFirstLine = 0; |
1429 |
int hasTextOnFirstLine = 0; |
1428 |
boolean firstWord = true; |
1430 |
boolean firstWord = true; |
1429 |
boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_block_comment; |
1431 |
boolean clearBlankLines = this.formatter.preferences.comment_clear_blank_lines_in_block_comment; |
Lines 1445-1450
Link Here
|
1445 |
|
1447 |
|
1446 |
// Look at specific tokens |
1448 |
// Look at specific tokens |
1447 |
boolean insertSpace = (previousToken == TerminalTokens.TokenNameWHITESPACE) && (!firstWord || !hasTokens); |
1449 |
boolean insertSpace = (previousToken == TerminalTokens.TokenNameWHITESPACE) && (!firstWord || !hasTokens); |
|
|
1450 |
boolean isTokenStar = false; |
1448 |
switch (token) { |
1451 |
switch (token) { |
1449 |
case TerminalTokens.TokenNameWHITESPACE: |
1452 |
case TerminalTokens.TokenNameWHITESPACE: |
1450 |
if (tokensBuffer.length() > 0) { |
1453 |
if (tokensBuffer.length() > 0) { |
Lines 1463-1469
Link Here
|
1463 |
} else { |
1466 |
} else { |
1464 |
previousToken = token; |
1467 |
previousToken = token; |
1465 |
} |
1468 |
} |
1466 |
lineNumber = Util.getLineNumber(this.scanner.getCurrentTokenEndPosition(), this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1469 |
lineNumber = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1467 |
if (lineNumber > scannerLine) { |
1470 |
if (lineNumber > scannerLine) { |
1468 |
hasMultiLines = true; |
1471 |
hasMultiLines = true; |
1469 |
newLine = true; |
1472 |
newLine = true; |
Lines 1471-1478
Link Here
|
1471 |
scannerLine = lineNumber; |
1474 |
scannerLine = lineNumber; |
1472 |
continue; |
1475 |
continue; |
1473 |
case TerminalTokens.TokenNameMULTIPLY: |
1476 |
case TerminalTokens.TokenNameMULTIPLY: |
|
|
1477 |
isTokenStar = true; |
1478 |
lineNumber = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1479 |
if (lineNumber == firstLine && previousToken == SKIP_FIRST_WHITESPACE_TOKEN) { |
1480 |
editStart = this.scanner.getCurrentTokenStartPosition(); |
1481 |
} |
1474 |
previousToken = token; |
1482 |
previousToken = token; |
1475 |
lineNumber = Util.getLineNumber(this.scanner.getCurrentTokenEndPosition(), this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
|
|
1476 |
if (this.scanner.currentCharacter == '/') { |
1483 |
if (this.scanner.currentCharacter == '/') { |
1477 |
editEnd = this.scanner.startPosition - 1; |
1484 |
editEnd = this.scanner.startPosition - 1; |
1478 |
// Add remaining buffered tokens |
1485 |
// Add remaining buffered tokens |
Lines 1491-1504
Link Here
|
1491 |
this.scanner.getNextChar(); // reach the end of scanner |
1498 |
this.scanner.getNextChar(); // reach the end of scanner |
1492 |
continue; |
1499 |
continue; |
1493 |
} |
1500 |
} |
1494 |
scannerLine = lineNumber; |
1501 |
if (newLine) { |
1495 |
continue; |
1502 |
scannerLine = lineNumber; |
|
|
1503 |
newLine = false; |
1504 |
continue; |
1505 |
} |
1506 |
break; |
1496 |
case TerminalTokens.TokenNameMULTIPLY_EQUAL: |
1507 |
case TerminalTokens.TokenNameMULTIPLY_EQUAL: |
1497 |
if (newLine) { |
1508 |
if (newLine) { |
1498 |
this.scanner.resetTo(this.scanner.startPosition, currentTokenEndPosition-1); |
1509 |
this.scanner.resetTo(this.scanner.startPosition, currentTokenEndPosition-1); |
1499 |
this.scanner.getNextChar(); // consume the multiply |
1510 |
this.scanner.getNextChar(); // consume the multiply |
1500 |
previousToken = TerminalTokens.TokenNameMULTIPLY; |
1511 |
previousToken = TerminalTokens.TokenNameMULTIPLY; |
1501 |
scannerLine = Util.getLineNumber(this.scanner.getCurrentTokenEndPosition(), this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1512 |
scannerLine = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1502 |
continue; |
1513 |
continue; |
1503 |
} |
1514 |
} |
1504 |
break; |
1515 |
break; |
Lines 1524-1530
Link Here
|
1524 |
// Look at gap and insert corresponding lines if necessary |
1535 |
// Look at gap and insert corresponding lines if necessary |
1525 |
int linesGap; |
1536 |
int linesGap; |
1526 |
int max; |
1537 |
int max; |
1527 |
lineNumber = Util.getLineNumber(this.scanner.getCurrentTokenEndPosition(), this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1538 |
lineNumber = Util.getLineNumber(this.scanner.currentPosition, this.lineEnds, scannerLine>1 ? scannerLine-2 : 0, this.maxLines); |
1528 |
if (lastTextLine == -1) { |
1539 |
if (lastTextLine == -1) { |
1529 |
linesGap = lineNumber - firstLine; |
1540 |
linesGap = lineNumber - firstLine; |
1530 |
max = 0; |
1541 |
max = 0; |
Lines 1534-1540
Link Here
|
1534 |
// insert one blank line before root tags |
1545 |
// insert one blank line before root tags |
1535 |
linesGap = 2; |
1546 |
linesGap = 2; |
1536 |
} |
1547 |
} |
1537 |
max = joinLines ? 1 : 0; |
1548 |
max = joinLines && lineHasTokens ? 1 : 0; |
1538 |
} |
1549 |
} |
1539 |
if (linesGap > max) { |
1550 |
if (linesGap > max) { |
1540 |
if (clearBlankLines) { |
1551 |
if (clearBlankLines) { |
Lines 1566-1577
Link Here
|
1566 |
} |
1577 |
} |
1567 |
insertSpace = insertSpace && linesGap == 0; |
1578 |
insertSpace = insertSpace && linesGap == 0; |
1568 |
} |
1579 |
} |
|
|
1580 |
if (newLine) lineHasTokens = false; |
1569 |
|
1581 |
|
1570 |
// Increment column |
1582 |
// Increment column |
1571 |
int tokenStart = this.scanner.getCurrentTokenStartPosition(); |
1583 |
int tokenStart = this.scanner.getCurrentTokenStartPosition(); |
1572 |
int tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - tokenStart; |
1584 |
int tokenLength = (this.scanner.atEnd() ? this.scanner.eofPosition : this.scanner.currentPosition) - tokenStart; |
1573 |
hasTokens = true; |
1585 |
hasTokens = true; |
1574 |
if (hasTextOnFirstLine == 0) { |
1586 |
if (!isTokenStar) lineHasTokens = true; |
|
|
1587 |
if (hasTextOnFirstLine == 0 && !isTokenStar) { |
1575 |
if (firstLine == lineNumber) { |
1588 |
if (firstLine == lineNumber) { |
1576 |
hasTextOnFirstLine = 1; |
1589 |
hasTextOnFirstLine = 1; |
1577 |
this.column++; // include first space |
1590 |
this.column++; // include first space |
Lines 1583-1589
Link Here
|
1583 |
if (insertSpace) lastColumn++; |
1596 |
if (insertSpace) lastColumn++; |
1584 |
|
1597 |
|
1585 |
// Append next token inserting a new line if max line is reached |
1598 |
// Append next token inserting a new line if max line is reached |
1586 |
if (!firstWord && lastColumn > maxColumn) { |
1599 |
if (lineHasTokens && !firstWord && lastColumn > maxColumn) { |
1587 |
String tokensString = tokensBuffer.toString().trim(); |
1600 |
String tokensString = tokensBuffer.toString().trim(); |
1588 |
// not enough space on the line |
1601 |
// not enough space on the line |
1589 |
if (hasTextOnFirstLine == 1) { |
1602 |
if (hasTextOnFirstLine == 1) { |
Lines 2045-2050
Link Here
|
2045 |
private void printLineComment() { |
2058 |
private void printLineComment() { |
2046 |
int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition(); |
2059 |
int currentTokenStartPosition = this.scanner.getCurrentTokenStartPosition(); |
2047 |
int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1; |
2060 |
int currentTokenEndPosition = this.scanner.getCurrentTokenEndPosition() + 1; |
|
|
2061 |
boolean includesLineComments = includesLineComments(); |
2048 |
boolean isNlsTag = false; |
2062 |
boolean isNlsTag = false; |
2049 |
if (CharOperation.indexOf(Scanner.TAG_PREFIX, this.scanner.source, true, currentTokenStartPosition, currentTokenEndPosition) != -1) { |
2063 |
if (CharOperation.indexOf(Scanner.TAG_PREFIX, this.scanner.source, true, currentTokenStartPosition, currentTokenEndPosition) != -1) { |
2050 |
this.nlsTagCounter = 0; |
2064 |
this.nlsTagCounter = 0; |
Lines 2068-2074
Link Here
|
2068 |
this.pendingSpace = false; |
2082 |
this.pendingSpace = false; |
2069 |
int previousStart = currentTokenStartPosition; |
2083 |
int previousStart = currentTokenStartPosition; |
2070 |
|
2084 |
|
2071 |
if (!isNlsTag && includesLineComments()) { |
2085 |
if (!isNlsTag && includesLineComments) { |
2072 |
printLineComment(currentTokenStartPosition, currentTokenEndPosition-1); |
2086 |
printLineComment(currentTokenStartPosition, currentTokenEndPosition-1); |
2073 |
} else { |
2087 |
} else { |
2074 |
// do nothing!? |
2088 |
// do nothing!? |