mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 248041 - Code formatting problem with CPPUNIT - Partial Fix
This commit is contained in:
parent
f8fefa6ec2
commit
04fa1f9ff5
1 changed files with 53 additions and 21 deletions
|
@ -313,12 +313,17 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* @see org.eclipse.cdt.core.dom.ast.ASTVisitor#visit(org.eclipse.cdt.core.dom.ast.IASTDeclaration)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTDeclaration node) {
|
public int visit(IASTDeclaration node) {
|
||||||
if (!startNode(node)) { return PROCESS_SKIP; }
|
if (!startNode(node)) { return PROCESS_SKIP; }
|
||||||
|
try {
|
||||||
|
return formatDeclaration(node);
|
||||||
|
} finally {
|
||||||
|
endOfNode(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int formatDeclaration(IASTDeclaration node) {
|
||||||
int indentLevel= scribe.indentationLevel;
|
int indentLevel= scribe.indentationLevel;
|
||||||
try {
|
try {
|
||||||
if (node instanceof IASTFunctionDefinition) {
|
if (node instanceof IASTFunctionDefinition) {
|
||||||
|
@ -359,8 +364,6 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
scribe.unIndent();
|
scribe.unIndent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
endOfNode(node);
|
|
||||||
}
|
}
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
@ -1249,15 +1252,32 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
formatList(declarators, align, false, false);
|
formatList(declarators, align, false, false);
|
||||||
}
|
}
|
||||||
if (fExpectSemicolonAfterDeclaration) {
|
if (fExpectSemicolonAfterDeclaration) {
|
||||||
if (peekNextToken() != Token.tSEMI) {
|
handleNodeEndingInSemicolon(node);
|
||||||
scribe.skipToToken(Token.tSEMI);
|
if (peekNextToken() == Token.tSEMI) {
|
||||||
|
scribe.printNextToken(Token.tSEMI, fInsideFor ? preferences.insert_space_before_semicolon_in_for : preferences.insert_space_before_semicolon);
|
||||||
|
scribe.printTrailingComment();
|
||||||
}
|
}
|
||||||
scribe.printNextToken(Token.tSEMI, fInsideFor ? preferences.insert_space_before_semicolon_in_for : preferences.insert_space_before_semicolon);
|
|
||||||
scribe.printTrailingComment();
|
|
||||||
}
|
}
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleNodeEndingInSemicolon(IASTSimpleDeclaration node) {
|
||||||
|
if (scribe.skipRange() && peekNextToken(true) == Token.tSEMI) {
|
||||||
|
IASTNodeLocation[] locations= node.getNodeLocations();
|
||||||
|
if (locations.length > 0) {
|
||||||
|
IASTNodeLocation lastLocation = locations[locations.length - 1];
|
||||||
|
if (!(lastLocation instanceof IASTMacroExpansionLocation)) {
|
||||||
|
IASTFileLocation fileLocation= lastLocation.asFileLocation();
|
||||||
|
int startOffset= fileLocation.getNodeOffset();
|
||||||
|
int currentPosition= scribe.scanner.getCurrentPosition();
|
||||||
|
if (currentPosition >= startOffset) {
|
||||||
|
scribe.restartAtOffset(startOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int visit(ICPPASTTemplateDeclaration node) {
|
private int visit(ICPPASTTemplateDeclaration node) {
|
||||||
if (node.isExported()) {
|
if (node.isExported()) {
|
||||||
scribe.printNextToken(Token.t_export);
|
scribe.printNextToken(Token.t_export);
|
||||||
|
@ -1449,27 +1469,35 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
scribe.startNewLine();
|
scribe.startNewLine();
|
||||||
for (int i = 0; i < memberDecls.length; i++) {
|
for (int i = 0; i < memberDecls.length; i++) {
|
||||||
IASTDeclaration declaration = memberDecls[i];
|
IASTDeclaration declaration = memberDecls[i];
|
||||||
|
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
||||||
|
scribe.indent();
|
||||||
|
}
|
||||||
|
scribe.printComment();
|
||||||
if (declaration instanceof ICPPASTVisibilityLabel) {
|
if (declaration instanceof ICPPASTVisibilityLabel) {
|
||||||
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
|
||||||
scribe.indent();
|
|
||||||
}
|
|
||||||
scribe.printComment();
|
|
||||||
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
||||||
scribe.unIndent();
|
scribe.unIndent();
|
||||||
}
|
}
|
||||||
visit((ICPPASTVisibilityLabel)declaration);
|
startNode(declaration);
|
||||||
} else {
|
try {
|
||||||
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
scribe.startNewLine();
|
||||||
scribe.indent();
|
visit((ICPPASTVisibilityLabel)declaration);
|
||||||
|
} finally {
|
||||||
|
endOfNode(declaration);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
startNode(declaration);
|
||||||
|
try {
|
||||||
|
scribe.startNewLine();
|
||||||
|
formatDeclaration(declaration);
|
||||||
|
} finally {
|
||||||
|
endOfNode(declaration);
|
||||||
}
|
}
|
||||||
declaration.accept(this);
|
|
||||||
scribe.printComment();
|
|
||||||
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
||||||
scribe.unIndent();
|
scribe.unIndent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scribe.startNewLine();
|
|
||||||
}
|
}
|
||||||
|
scribe.startNewLine();
|
||||||
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
if (preferences.indent_body_declarations_compare_to_access_specifier) {
|
||||||
scribe.indent();
|
scribe.indent();
|
||||||
}
|
}
|
||||||
|
@ -2809,6 +2837,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
int endOffset= startOffset + expansionLocation.getNodeLength();
|
int endOffset= startOffset + expansionLocation.getNodeLength();
|
||||||
scribe.skipRange(startOffset, endOffset);
|
scribe.skipRange(startOffset, endOffset);
|
||||||
if (locations.length == 1 && endOffset <= scribe.scanner.getCurrentPosition()) {
|
if (locations.length == 1 && endOffset <= scribe.scanner.getCurrentPosition()) {
|
||||||
|
endOfNode(node);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -3122,7 +3151,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int peekNextToken() {
|
private int peekNextToken() {
|
||||||
if (scribe.shouldSkip(scribe.scanner.getCurrentPosition())) {
|
return peekNextToken(false);
|
||||||
|
}
|
||||||
|
private int peekNextToken(boolean ignoreSkip) {
|
||||||
|
if (!ignoreSkip && scribe.shouldSkip(scribe.scanner.getCurrentPosition())) {
|
||||||
return Token.tBADCHAR;
|
return Token.tBADCHAR;
|
||||||
}
|
}
|
||||||
localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition - 1);
|
localScanner.resetTo(scribe.scanner.getCurrentPosition(), scribe.scannerEndPosition - 1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue