mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Cosmetics.
Fix mixed indentation Change-Id: Iba3193013c2e6cd5e21e0d61f47b244dfafe0582 Signed-off-by: Jonah Graham <jonah@kichwacoders.com>
This commit is contained in:
parent
30cde08c83
commit
21dacc15fd
1 changed files with 92 additions and 92 deletions
|
@ -239,7 +239,7 @@ public class Scribe {
|
||||||
length -= i;
|
length -= i;
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
replacement = i == replacementLength ?
|
replacement = i == replacementLength ?
|
||||||
EMPTY_STRING : replacement.subSequence(i, replacementLength);
|
EMPTY_STRING : replacement.subSequence(i, replacementLength);
|
||||||
}
|
}
|
||||||
if (length > 0 || replacement.length() > 0) {
|
if (length > 0 || replacement.length() > 0) {
|
||||||
edits[editsIndex++]= new OptimizedReplaceEdit(offset, length, replacement);
|
edits[editsIndex++]= new OptimizedReplaceEdit(offset, length, replacement);
|
||||||
|
@ -1308,24 +1308,24 @@ public class Scribe {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printLineComment() {
|
private void printLineComment() {
|
||||||
int currentTokenStartPosition = scanner.getCurrentTokenStartPosition();
|
int currentTokenStartPosition = scanner.getCurrentTokenStartPosition();
|
||||||
int currentTokenEndPosition = scanner.getCurrentTokenEndPosition() + 1;
|
int currentTokenEndPosition = scanner.getCurrentTokenEndPosition() + 1;
|
||||||
scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition);
|
scanner.resetTo(currentTokenStartPosition, currentTokenEndPosition);
|
||||||
int currentCharacter;
|
int currentCharacter;
|
||||||
int start = currentTokenStartPosition;
|
int start = currentTokenStartPosition;
|
||||||
int nextCharacterStart = currentTokenStartPosition;
|
int nextCharacterStart = currentTokenStartPosition;
|
||||||
|
|
||||||
// Print comment line indentation
|
// Print comment line indentation
|
||||||
int commentIndentationLevel;
|
int commentIndentationLevel;
|
||||||
boolean onFirstColumn = isOnFirstColumn(start);
|
boolean onFirstColumn = isOnFirstColumn(start);
|
||||||
if (indentationLevel == 0) {
|
if (indentationLevel == 0) {
|
||||||
commentIndentationLevel = column - 1;
|
commentIndentationLevel = column - 1;
|
||||||
} else {
|
} else {
|
||||||
if (onFirstColumn && preferences.never_indent_line_comments_on_first_column) {
|
if (onFirstColumn && preferences.never_indent_line_comments_on_first_column) {
|
||||||
commentIndentationLevel = column - 1;
|
commentIndentationLevel = column - 1;
|
||||||
} else {
|
} else {
|
||||||
// Indentation may be specific for contiguous comment
|
// Indentation may be specific for contiguous comment
|
||||||
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300
|
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=293300
|
||||||
if (lastLineComment.contiguous) {
|
if (lastLineComment.contiguous) {
|
||||||
// The leading spaces have been set while looping in the printComment(int) method
|
// The leading spaces have been set while looping in the printComment(int) method
|
||||||
int currentCommentIndentation = computeIndentation(lastLineComment.leadingSpaces, 0);
|
int currentCommentIndentation = computeIndentation(lastLineComment.leadingSpaces, 0);
|
||||||
|
@ -1344,17 +1344,17 @@ public class Scribe {
|
||||||
indentationLevel = lastLineComment.indentation;
|
indentationLevel = lastLineComment.indentation;
|
||||||
printIndentationIfNecessary();
|
printIndentationIfNecessary();
|
||||||
indentationLevel = currentIndentationLevel;
|
indentationLevel = currentIndentationLevel;
|
||||||
commentIndentationLevel = lastLineComment.indentation;
|
commentIndentationLevel = lastLineComment.indentation;
|
||||||
} else {
|
} else {
|
||||||
printIndentationIfNecessary();
|
printIndentationIfNecessary();
|
||||||
commentIndentationLevel = column - 1;
|
commentIndentationLevel = column - 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printIndentationIfNecessary();
|
printIndentationIfNecessary();
|
||||||
commentIndentationLevel = column - 1;
|
commentIndentationLevel = column - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare white space before the comment.
|
// Prepare white space before the comment.
|
||||||
StringBuilder whitespace = null;
|
StringBuilder whitespace = null;
|
||||||
|
@ -1374,9 +1374,9 @@ public class Scribe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store line comment information
|
// Store line comment information
|
||||||
lastLineComment.currentIndentation = getIndentationOfOffset(currentTokenStartPosition);
|
lastLineComment.currentIndentation = getIndentationOfOffset(currentTokenStartPosition);
|
||||||
lastLineComment.contiguous = true;
|
lastLineComment.contiguous = true;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
Location location = new Location(this, scanner.getCurrentPosition());
|
Location location = new Location(this, scanner.getCurrentPosition());
|
||||||
|
@ -1386,35 +1386,35 @@ public class Scribe {
|
||||||
if (whitespace != null) {
|
if (whitespace != null) {
|
||||||
addInsertEdit(currentTokenStartPosition, whitespace);
|
addInsertEdit(currentTokenStartPosition, whitespace);
|
||||||
commentIndent = computeIndentation(whitespace, commentIndentationLevel);
|
commentIndent = computeIndentation(whitespace, commentIndentationLevel);
|
||||||
needSpace = false;
|
needSpace = false;
|
||||||
pendingSpace = false;
|
pendingSpace = false;
|
||||||
}
|
}
|
||||||
lastLineComment.indentation = commentIndent;
|
lastLineComment.indentation = commentIndent;
|
||||||
|
|
||||||
int previousStart = currentTokenStartPosition;
|
int previousStart = currentTokenStartPosition;
|
||||||
|
|
||||||
int indent = commentIndent;
|
int indent = commentIndent;
|
||||||
loop: while (nextCharacterStart <= currentTokenEndPosition &&
|
loop: while (nextCharacterStart <= currentTokenEndPosition &&
|
||||||
(currentCharacter = scanner.getNextChar()) != -1) {
|
(currentCharacter = scanner.getNextChar()) != -1) {
|
||||||
nextCharacterStart = scanner.getCurrentPosition();
|
nextCharacterStart = scanner.getCurrentPosition();
|
||||||
|
|
||||||
switch (currentCharacter) {
|
switch (currentCharacter) {
|
||||||
case '\r':
|
case '\r':
|
||||||
case '\n':
|
case '\n':
|
||||||
start = previousStart;
|
start = previousStart;
|
||||||
break loop;
|
break loop;
|
||||||
}
|
}
|
||||||
indent = computeIndentation((char) currentCharacter, indent);
|
indent = computeIndentation((char) currentCharacter, indent);
|
||||||
previousStart = nextCharacterStart;
|
previousStart = nextCharacterStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start != currentTokenStartPosition) {
|
if (start != currentTokenStartPosition) {
|
||||||
// This means that the line comment doesn't end the file
|
// This means that the line comment doesn't end the file
|
||||||
addReplaceEdit(start, currentTokenEndPosition - 1, lineSeparator);
|
addReplaceEdit(start, currentTokenEndPosition - 1, lineSeparator);
|
||||||
line++;
|
line++;
|
||||||
column = 1;
|
column = 1;
|
||||||
lastNumberOfNewLines = 1;
|
lastNumberOfNewLines = 1;
|
||||||
}
|
}
|
||||||
if (!checkLineWrapping || indent <= pageWidth || whitespace == null ||
|
if (!checkLineWrapping || indent <= pageWidth || whitespace == null ||
|
||||||
commentIndent - commentIndentationLevel <= preferences.comment_min_distance_between_code_and_line_comment) {
|
commentIndent - commentIndentationLevel <= preferences.comment_min_distance_between_code_and_line_comment) {
|
||||||
break;
|
break;
|
||||||
|
@ -1423,44 +1423,44 @@ public class Scribe {
|
||||||
// Maximum line length was exceeded. Try to reduce white space before the comment by
|
// Maximum line length was exceeded. Try to reduce white space before the comment by
|
||||||
// removing the last white space character.
|
// removing the last white space character.
|
||||||
whitespace.deleteCharAt(whitespace.length() - 1);
|
whitespace.deleteCharAt(whitespace.length() - 1);
|
||||||
if (computeIndentation(lastLineComment.leadingSpaces, commentIndentationLevel) - commentIndentationLevel <
|
if (computeIndentation(lastLineComment.leadingSpaces, commentIndentationLevel) - commentIndentationLevel <
|
||||||
preferences.comment_min_distance_between_code_and_line_comment) {
|
preferences.comment_min_distance_between_code_and_line_comment) {
|
||||||
// The white space shrank too much. Rebuild it to satisfy the minimum distance
|
// The white space shrank too much. Rebuild it to satisfy the minimum distance
|
||||||
// requirement.
|
// requirement.
|
||||||
whitespace.delete(0, whitespace.length());
|
whitespace.delete(0, whitespace.length());
|
||||||
for (int i = 0; i < preferences.comment_min_distance_between_code_and_line_comment; i++) {
|
for (int i = 0; i < preferences.comment_min_distance_between_code_and_line_comment; i++) {
|
||||||
whitespace.append(' ');
|
whitespace.append(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resetAt(location);
|
resetAt(location);
|
||||||
scanner.resetTo(location.inputOffset, scanner.eofPosition);
|
scanner.resetTo(location.inputOffset, scanner.eofPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
needSpace = false;
|
needSpace = false;
|
||||||
pendingSpace = false;
|
pendingSpace = false;
|
||||||
// realign to the proper value
|
// realign to the proper value
|
||||||
if (currentAlignment != null) {
|
if (currentAlignment != null) {
|
||||||
if (memberAlignment != null) {
|
if (memberAlignment != null) {
|
||||||
// select the last alignment
|
// select the last alignment
|
||||||
if (currentAlignment.location.inputOffset > memberAlignment.location.inputOffset) {
|
if (currentAlignment.location.inputOffset > memberAlignment.location.inputOffset) {
|
||||||
if (currentAlignment.couldBreak() && currentAlignment.wasSplit) {
|
if (currentAlignment.couldBreak() && currentAlignment.wasSplit) {
|
||||||
currentAlignment.performFragmentEffect();
|
currentAlignment.performFragmentEffect();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
indentationLevel = Math.max(indentationLevel, memberAlignment.breakIndentationLevel);
|
indentationLevel = Math.max(indentationLevel, memberAlignment.breakIndentationLevel);
|
||||||
}
|
}
|
||||||
} else if (currentAlignment.couldBreak() && currentAlignment.wasSplit) {
|
} else if (currentAlignment.couldBreak() && currentAlignment.wasSplit) {
|
||||||
currentAlignment.performFragmentEffect();
|
currentAlignment.performFragmentEffect();
|
||||||
}
|
}
|
||||||
if (currentAlignment.name.equals(Alignment.BINARY_EXPRESSION) &&
|
if (currentAlignment.name.equals(Alignment.BINARY_EXPRESSION) &&
|
||||||
currentAlignment.enclosing != null &&
|
currentAlignment.enclosing != null &&
|
||||||
currentAlignment.enclosing.equals(Alignment.BINARY_EXPRESSION) &&
|
currentAlignment.enclosing.equals(Alignment.BINARY_EXPRESSION) &&
|
||||||
indentationLevel < currentAlignment.breakIndentationLevel) {
|
indentationLevel < currentAlignment.breakIndentationLevel) {
|
||||||
indentationLevel = currentAlignment.breakIndentationLevel;
|
indentationLevel = currentAlignment.breakIndentationLevel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scanner.resetTo(currentTokenEndPosition, scannerEndPosition);
|
scanner.resetTo(currentTokenEndPosition, scannerEndPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printEmptyLines(int linesNumber) {
|
public void printEmptyLines(int linesNumber) {
|
||||||
printEmptyLines(linesNumber, scanner.getCurrentTokenEndPosition() + 1);
|
printEmptyLines(linesNumber, scanner.getCurrentTokenEndPosition() + 1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue