mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +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
|
@ -31,7 +31,7 @@ import org.eclipse.text.edits.TextEdit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is responsible for dumping formatted source.
|
* This class is responsible for dumping formatted source.
|
||||||
*
|
*
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
*/
|
*/
|
||||||
public class Scribe {
|
public class Scribe {
|
||||||
|
@ -50,7 +50,7 @@ public class Scribe {
|
||||||
public Alignment currentAlignment;
|
public Alignment currentAlignment;
|
||||||
public Alignment memberAlignment;
|
public Alignment memberAlignment;
|
||||||
public AlignmentException currentAlignmentException;
|
public AlignmentException currentAlignmentException;
|
||||||
|
|
||||||
/** @see Alignment#tailFormatter */
|
/** @see Alignment#tailFormatter */
|
||||||
private Runnable tailFormatter;
|
private Runnable tailFormatter;
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ public class Scribe {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trims redundant prefix from a replacement edit and, if there is anything left, appends
|
* Trims redundant prefix from a replacement edit and, if there is anything left, appends
|
||||||
* the replacement edit to the edits array.
|
* the replacement edit to the edits array.
|
||||||
*/
|
*/
|
||||||
private void appendOptimizedReplaceEdit(int offset, int length, CharSequence replacement) {
|
private void appendOptimizedReplaceEdit(int offset, int length, CharSequence replacement) {
|
||||||
int replacementLength = replacement.length();
|
int replacementLength = replacement.length();
|
||||||
|
@ -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);
|
||||||
|
@ -552,10 +552,10 @@ public class Scribe {
|
||||||
if (currentAlignment != null && !formatBrace) {
|
if (currentAlignment != null && !formatBrace) {
|
||||||
indentationLevel = currentAlignment.breakIndentationLevel;
|
indentationLevel = currentAlignment.breakIndentationLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the flag to indicate that a specific indentation is currently in used
|
// Set the flag to indicate that a specific indentation is currently in used
|
||||||
preserveLineBreakIndentation = true;
|
preserveLineBreakIndentation = true;
|
||||||
|
|
||||||
// Print the computed indentation in the buffer
|
// Print the computed indentation in the buffer
|
||||||
printIndentationIfNecessary(tempBuffer);
|
printIndentationIfNecessary(tempBuffer);
|
||||||
|
|
||||||
|
@ -1063,7 +1063,7 @@ public class Scribe {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints comment at the current position.
|
* Prints comment at the current position.
|
||||||
*
|
*
|
||||||
* @return {@code true} if a writespace character was encountered preceding the next token,
|
* @return {@code true} if a writespace character was encountered preceding the next token,
|
||||||
*/
|
*/
|
||||||
public boolean printComment(int trailing) {
|
public boolean printComment(int trailing) {
|
||||||
|
@ -1178,7 +1178,7 @@ public class Scribe {
|
||||||
}
|
}
|
||||||
scanner.resetTo(currentTokenStartPosition, scannerEndPosition);
|
scanner.resetTo(currentTokenStartPosition, scannerEndPosition);
|
||||||
return hasWhitespace;
|
return hasWhitespace;
|
||||||
}
|
}
|
||||||
// If one or several new lines are consumed, following comments
|
// If one or several new lines are consumed, following comments
|
||||||
// cannot be considered as trailing ones.
|
// cannot be considered as trailing ones.
|
||||||
if (lines >= 1) {
|
if (lines >= 1) {
|
||||||
|
@ -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,18 +1344,18 @@ 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;
|
||||||
if (!lastLineComment.contiguous && commentIndentationLevel != indentationLevel &&
|
if (!lastLineComment.contiguous && commentIndentationLevel != indentationLevel &&
|
||||||
|
@ -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);
|
||||||
|
@ -1598,7 +1598,7 @@ public class Scribe {
|
||||||
// Ensure that the scribe is at the beginning of a new line
|
// Ensure that the scribe is at the beginning of a new line
|
||||||
// only if no specific indentation has been previously set.
|
// only if no specific indentation has been previously set.
|
||||||
if (!preserveLineBreakIndentation) {
|
if (!preserveLineBreakIndentation) {
|
||||||
column = 1;
|
column = 1;
|
||||||
}
|
}
|
||||||
preserveLineBreakIndentation = false;
|
preserveLineBreakIndentation = false;
|
||||||
return;
|
return;
|
||||||
|
@ -1918,7 +1918,7 @@ public class Scribe {
|
||||||
* Skips to the next occurrence of the given token type.
|
* Skips to the next occurrence of the given token type.
|
||||||
* If successful, the next token will be the expected token,
|
* If successful, the next token will be the expected token,
|
||||||
* otherwise the scanner position is left unchanged.
|
* otherwise the scanner position is left unchanged.
|
||||||
*
|
*
|
||||||
* @param expectedTokenType
|
* @param expectedTokenType
|
||||||
* @return <code>true</code> if a matching token was skipped to
|
* @return <code>true</code> if a matching token was skipped to
|
||||||
*/
|
*/
|
||||||
|
@ -1941,7 +1941,7 @@ public class Scribe {
|
||||||
* Searches for the next occurrence of the given token type.
|
* Searches for the next occurrence of the given token type.
|
||||||
* If successful, returns the offset of the found token, otherwise -1.
|
* If successful, returns the offset of the found token, otherwise -1.
|
||||||
* The scanner position is left unchanged.
|
* The scanner position is left unchanged.
|
||||||
*
|
*
|
||||||
* @param tokenType type of the token to look for
|
* @param tokenType type of the token to look for
|
||||||
* @return the position of the matching token, if found, otherwise -1.
|
* @return the position of the matching token, if found, otherwise -1.
|
||||||
*/
|
*/
|
||||||
|
@ -1953,7 +1953,7 @@ public class Scribe {
|
||||||
* Searches for the next occurrence of the given token type.
|
* Searches for the next occurrence of the given token type.
|
||||||
* If successful, returns the offset of the found token, otherwise -1.
|
* If successful, returns the offset of the found token, otherwise -1.
|
||||||
* The scanner position is left unchanged.
|
* The scanner position is left unchanged.
|
||||||
*
|
*
|
||||||
* @param tokenType type of the token to look for
|
* @param tokenType type of the token to look for
|
||||||
* @param endPosition end position limiting the search
|
* @param endPosition end position limiting the search
|
||||||
* @return the position of the matching token, if found, otherwise -1.
|
* @return the position of the matching token, if found, otherwise -1.
|
||||||
|
@ -2023,7 +2023,7 @@ public class Scribe {
|
||||||
* Searches for the next occurrence of the given token type.
|
* Searches for the next occurrence of the given token type.
|
||||||
* If successful, returns the offset of the found token, otherwise -1.
|
* If successful, returns the offset of the found token, otherwise -1.
|
||||||
* The scanner position is left unchanged.
|
* The scanner position is left unchanged.
|
||||||
*
|
*
|
||||||
* @param tokenType type of the token to look for
|
* @param tokenType type of the token to look for
|
||||||
* @param startPosition position where to start the search
|
* @param startPosition position where to start the search
|
||||||
* @param endPosition end position limiting the search
|
* @param endPosition end position limiting the search
|
||||||
|
|
Loading…
Add table
Reference in a new issue