mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Code simplification.
This commit is contained in:
parent
b921093240
commit
304ce2dac3
3 changed files with 37 additions and 37 deletions
|
@ -3867,7 +3867,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
|
||||
private int getNextTokenOffset() {
|
||||
localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition - 1);
|
||||
localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition);
|
||||
localScanner.getNextToken();
|
||||
return localScanner.getCurrentTokenStartPosition();
|
||||
}
|
||||
|
@ -4030,12 +4030,12 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
if (fileLocation == null)
|
||||
return false;
|
||||
int pos = fileLocation.getNodeOffset() + fileLocation.getNodeLength();
|
||||
localScanner.resetTo(pos, scribe.scannerEndPosition - 1);
|
||||
localScanner.resetTo(pos, scribe.scannerEndPosition);
|
||||
Token token= localScanner.nextToken();
|
||||
if (token == null || token.getType() != Token.tSEMI)
|
||||
return false;
|
||||
// Check if the semicolon is on the same line.
|
||||
localScanner.resetTo(pos, token.getOffset() - 1);
|
||||
localScanner.resetTo(pos, token.getOffset());
|
||||
int c;
|
||||
while ((c = localScanner.getNextChar()) != -1) {
|
||||
if (c == '\n')
|
||||
|
@ -4238,7 +4238,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
|
||||
private int peekTokenAtPosition(int pos) {
|
||||
localScanner.resetTo(pos, scribe.scannerEndPosition - 1);
|
||||
localScanner.resetTo(pos, scribe.scannerEndPosition);
|
||||
int token = localScanner.getNextToken();
|
||||
while (token == Token.tBLOCKCOMMENT || token == Token.tLINECOMMENT) {
|
||||
token = localScanner.getNextToken();
|
||||
|
@ -4254,7 +4254,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
if (!ignoreSkip && scribe.shouldSkip(scribe.scanner.getCurrentPosition())) {
|
||||
return Token.tBADCHAR;
|
||||
}
|
||||
localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition - 1);
|
||||
localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition);
|
||||
int token = localScanner.getNextToken();
|
||||
while (token == Token.tBLOCKCOMMENT || token == Token.tLINECOMMENT) {
|
||||
token = localScanner.getNextToken();
|
||||
|
|
|
@ -786,7 +786,7 @@ public class Scribe {
|
|||
skipOverInactive= false;
|
||||
scannerEndPosition= startOffset + length;
|
||||
try {
|
||||
scanner.resetTo(Math.max(startOffset, currentPosition), startOffset + length - 1);
|
||||
scanner.resetTo(Math.max(startOffset, currentPosition), startOffset + length);
|
||||
int parenLevel= 0;
|
||||
while (true) {
|
||||
boolean hasWhitespace= printComment();
|
||||
|
@ -804,7 +804,7 @@ public class Scribe {
|
|||
}
|
||||
switch (currentToken.type) {
|
||||
case Token.tLBRACE: {
|
||||
scanner.resetTo(scanner.getCurrentTokenStartPosition(), scannerEndPosition - 1);
|
||||
scanner.resetTo(scanner.getCurrentTokenStartPosition(), scannerEndPosition);
|
||||
formatOpeningBrace(preferences.brace_position_for_block,
|
||||
preferences.insert_space_before_opening_brace_in_block);
|
||||
if (preferences.indent_statements_compare_to_block) {
|
||||
|
@ -813,7 +813,7 @@ public class Scribe {
|
|||
break;
|
||||
}
|
||||
case Token.tRBRACE: {
|
||||
scanner.resetTo(scanner.getCurrentTokenStartPosition(), scannerEndPosition - 1);
|
||||
scanner.resetTo(scanner.getCurrentTokenStartPosition(), scannerEndPosition);
|
||||
if (preferences.indent_statements_compare_to_block) {
|
||||
unIndent();
|
||||
}
|
||||
|
@ -868,7 +868,7 @@ public class Scribe {
|
|||
}
|
||||
} finally {
|
||||
scannerEndPosition= savedScannerEndPos;
|
||||
scanner.resetTo(startOffset + length, scannerEndPosition - 1);
|
||||
scanner.resetTo(startOffset + length, scannerEndPosition);
|
||||
skipOverInactive= savedSkipOverInactive;
|
||||
preserveNewLines= savedPreserveNL;
|
||||
}
|
||||
|
@ -932,7 +932,7 @@ public class Scribe {
|
|||
int currentTokenStartPosition= scanner.getCurrentTokenStartPosition();
|
||||
int currentTokenEndPosition= scanner.getCurrentTokenEndPosition() + 1;
|
||||
|
||||
scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition - 1);
|
||||
scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition);
|
||||
int currentCharacter;
|
||||
boolean isNewLine= false;
|
||||
int start= currentTokenStartPosition;
|
||||
|
@ -1002,7 +1002,7 @@ public class Scribe {
|
|||
}
|
||||
lastNumberOfNewLines= 0;
|
||||
needSpace= false;
|
||||
scanner.resetTo(currentTokenEndPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(currentTokenEndPosition, scannerEndPosition);
|
||||
if (forceNewLine) {
|
||||
startNewLine();
|
||||
}
|
||||
|
@ -1012,7 +1012,7 @@ public class Scribe {
|
|||
int currentTokenStartPosition= scanner.getCurrentTokenStartPosition();
|
||||
int currentTokenEndPosition= scanner.getCurrentTokenEndPosition() + 1;
|
||||
|
||||
scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition - 1);
|
||||
scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition);
|
||||
int currentCharacter;
|
||||
boolean isNewLine= false;
|
||||
int nextCharacterStart= currentTokenStartPosition;
|
||||
|
@ -1052,7 +1052,7 @@ public class Scribe {
|
|||
if (currentAlignment != null) {
|
||||
indentationLevel= currentAlignment.breakIndentationLevel;
|
||||
}
|
||||
scanner.resetTo(currentTokenEndPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(currentTokenEndPosition, scannerEndPosition);
|
||||
}
|
||||
|
||||
public void printEndOfTranslationUnit() {
|
||||
|
@ -1093,7 +1093,7 @@ public class Scribe {
|
|||
inactivePos.getOffset() + inactivePos.getLength());
|
||||
if (startOffset < endOffset) {
|
||||
int savedIndentLevel= indentationLevel;
|
||||
scanner.resetTo(scanner.getCurrentTokenStartPosition(), scanner.eofPosition - 1);
|
||||
scanner.resetTo(scanner.getCurrentTokenStartPosition(), scanner.eofPosition);
|
||||
printRaw(startOffset, endOffset - startOffset);
|
||||
while (indentationLevel > savedIndentLevel) {
|
||||
unIndent();
|
||||
|
@ -1101,7 +1101,7 @@ public class Scribe {
|
|||
while (indentationLevel < savedIndentLevel) {
|
||||
indent();
|
||||
}
|
||||
scanner.resetTo(endOffset, scanner.eofPosition - 1);
|
||||
scanner.resetTo(endOffset, scanner.eofPosition);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -1165,7 +1165,7 @@ public class Scribe {
|
|||
break;
|
||||
}
|
||||
}
|
||||
scanner.resetTo(currentTokenPosition, scanner.eofPosition - 1);
|
||||
scanner.resetTo(currentTokenPosition, scanner.eofPosition);
|
||||
scanner.getNextToken(); // Get current token again to restore the scanner state.
|
||||
}
|
||||
}
|
||||
|
@ -1178,10 +1178,10 @@ public class Scribe {
|
|||
currentTokenStartPosition = tokenStartPosition;
|
||||
preserveEmptyLines(lines, currentTokenStartPosition);
|
||||
addDeleteEdit(currentTokenStartPosition, whitespacesEndPosition);
|
||||
scanner.resetTo(scanner.getCurrentPosition(), scannerEndPosition - 1);
|
||||
scanner.resetTo(scanner.getCurrentPosition(), scannerEndPosition);
|
||||
return hasWhitespace;
|
||||
}
|
||||
scanner.resetTo(currentTokenStartPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(currentTokenStartPosition, scannerEndPosition);
|
||||
return hasWhitespace;
|
||||
}
|
||||
// If one or several new lines are consumed, following comments
|
||||
|
@ -1190,7 +1190,7 @@ public class Scribe {
|
|||
if (hasComment) {
|
||||
printNewLine(tokenStartPosition);
|
||||
}
|
||||
scanner.resetTo(currentTokenStartPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(currentTokenStartPosition, scannerEndPosition);
|
||||
return hasWhitespace;
|
||||
}
|
||||
// Delete consumed white spaces
|
||||
|
@ -1290,7 +1290,7 @@ public class Scribe {
|
|||
break;
|
||||
default:
|
||||
// step back one token
|
||||
scanner.resetTo(currentTokenStartPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(currentTokenStartPosition, scannerEndPosition);
|
||||
return hasWhitespace;
|
||||
}
|
||||
}
|
||||
|
@ -1314,7 +1314,7 @@ public class Scribe {
|
|||
private void printLineComment() {
|
||||
int currentTokenStartPosition = scanner.getCurrentTokenStartPosition();
|
||||
int currentTokenEndPosition = scanner.getCurrentTokenEndPosition() + 1;
|
||||
scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition - 1);
|
||||
scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition);
|
||||
int currentCharacter;
|
||||
int start = currentTokenStartPosition;
|
||||
int nextCharacterStart = currentTokenStartPosition;
|
||||
|
@ -1437,7 +1437,7 @@ public class Scribe {
|
|||
}
|
||||
}
|
||||
resetAt(location);
|
||||
scanner.resetTo(location.inputOffset, scanner.eofPosition - 1);
|
||||
scanner.resetTo(location.inputOffset, scanner.eofPosition);
|
||||
}
|
||||
|
||||
needSpace = false;
|
||||
|
@ -1463,7 +1463,7 @@ public class Scribe {
|
|||
indentationLevel = currentAlignment.breakIndentationLevel;
|
||||
}
|
||||
}
|
||||
scanner.resetTo(currentTokenEndPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(currentTokenEndPosition, scannerEndPosition);
|
||||
}
|
||||
|
||||
public void printEmptyLines(int linesNumber) {
|
||||
|
@ -1721,7 +1721,7 @@ public class Scribe {
|
|||
}
|
||||
// Reset scribe/scanner to restart at this given location
|
||||
resetAt(currentAlignment.location);
|
||||
scanner.resetTo(currentAlignment.location.inputOffset, scanner.eofPosition - 1);
|
||||
scanner.resetTo(currentAlignment.location.inputOffset, scanner.eofPosition);
|
||||
// Clean alignment chunkKind so it will think it is a new chunk again
|
||||
currentAlignment.chunkKind= 0;
|
||||
currentAlignmentException= null;
|
||||
|
@ -1730,7 +1730,7 @@ public class Scribe {
|
|||
void redoMemberAlignment(AlignmentException e) {
|
||||
// Reset scribe/scanner to restart at this given location
|
||||
resetAt(memberAlignment.location);
|
||||
scanner.resetTo(memberAlignment.location.inputOffset, scanner.eofPosition - 1);
|
||||
scanner.resetTo(memberAlignment.location.inputOffset, scanner.eofPosition);
|
||||
// Clean alignment chunkKind so it will think it is a new chunk again
|
||||
memberAlignment.chunkKind= 0;
|
||||
currentAlignmentException= null;
|
||||
|
@ -1911,7 +1911,7 @@ public class Scribe {
|
|||
}
|
||||
}
|
||||
// Step back one token
|
||||
scanner.resetTo(currentTokenStartPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(currentTokenStartPosition, scannerEndPosition);
|
||||
return !isFirstModifier;
|
||||
}
|
||||
}
|
||||
|
@ -1937,7 +1937,7 @@ public class Scribe {
|
|||
}
|
||||
printRaw(skipStart, tokenStart - skipStart);
|
||||
currentToken= scanner.nextToken();
|
||||
scanner.resetTo(tokenStart, scannerEndPosition - 1);
|
||||
scanner.resetTo(tokenStart, scannerEndPosition);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2018,7 +2018,7 @@ public class Scribe {
|
|||
}
|
||||
}
|
||||
} finally {
|
||||
scanner.resetTo(startPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(startPosition, scannerEndPosition);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -2036,10 +2036,10 @@ public class Scribe {
|
|||
public int findToken(int tokenType, int startPosition, int endPosition) {
|
||||
int currentPosition= scanner.getCurrentPosition();
|
||||
try {
|
||||
scanner.resetTo(startPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(startPosition, scannerEndPosition);
|
||||
return findToken(tokenType, endPosition);
|
||||
} finally {
|
||||
scanner.resetTo(currentPosition, scannerEndPosition - 1);
|
||||
scanner.resetTo(currentPosition, scannerEndPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2084,7 +2084,7 @@ public class Scribe {
|
|||
}
|
||||
if (offset > currentPosition) {
|
||||
printRaw(currentPosition, offset - currentPosition);
|
||||
scanner.resetTo(offset, scannerEndPosition - 1);
|
||||
scanner.resetTo(offset, scannerEndPosition);
|
||||
}
|
||||
while (fSkippedIndentations > 0) {
|
||||
indent();
|
||||
|
@ -2098,7 +2098,7 @@ public class Scribe {
|
|||
space();
|
||||
}
|
||||
printRaw(nextPosition, offset - nextPosition);
|
||||
scanner.resetTo(offset, scannerEndPosition - 1);
|
||||
scanner.resetTo(offset, scannerEndPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,21 +55,21 @@ public class Scanner extends SimpleScanner {
|
|||
/**
|
||||
* Reset scanner to given inclusive start and end offsets
|
||||
* @param start inclusive start offset
|
||||
* @param end inclusive end offset
|
||||
* @param end exclusive end offset
|
||||
*/
|
||||
public void resetTo(int start, int end) {
|
||||
Reader reader;
|
||||
if (end >= source.length - 1) {
|
||||
if (end >= source.length) {
|
||||
reader= new CharArrayReader(source);
|
||||
} else {
|
||||
reader= new CharArrayReader(source, 0, Math.min(source.length, end + 1));
|
||||
reader= new CharArrayReader(source, 0, Math.min(source.length, end));
|
||||
}
|
||||
fContext= new ScannerContext().initialize(reader, start);
|
||||
startPosition= start;
|
||||
if (source != null && source.length < end) {
|
||||
eofPosition = source.length;
|
||||
} else {
|
||||
eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
|
||||
eofPosition = end;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ public class Scanner extends SimpleScanner {
|
|||
} else if (diff == 0) {
|
||||
// no-op
|
||||
} else if (diff > fTokenBuffer.length()) {
|
||||
resetTo(nextCharacterStart, source.length - 1);
|
||||
resetTo(nextCharacterStart, source.length);
|
||||
} else /* if (diff <= fTokenBuffer.length()) */ {
|
||||
while (diff > 0) {
|
||||
if (fTokenBuffer.length() > 0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue