mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-08 08:45:44 +02:00
Bug 353022 - Fix format switch without parenthesis
Change-Id: I8d8a6498abe5c08c65c03f86b563563910f01098 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
parent
6452688c18
commit
1cd5180642
2 changed files with 23 additions and 1 deletions
|
@ -3998,11 +3998,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
}
|
}
|
||||||
// switch body
|
// switch body
|
||||||
String brace_position = preferences.brace_position_for_switch;
|
String brace_position = preferences.brace_position_for_switch;
|
||||||
|
boolean hasOpenBrace = false;
|
||||||
int braceIndent = -1;
|
int braceIndent = -1;
|
||||||
IASTStatement bodyStmt = node.getBody();
|
IASTStatement bodyStmt = node.getBody();
|
||||||
if (!startsWithMacroExpansion(bodyStmt)) {
|
if (!startsWithMacroExpansion(bodyStmt)) {
|
||||||
boolean insertSpaceBeforeOpeningBrace = preferences.insert_space_before_opening_brace_in_switch;
|
boolean insertSpaceBeforeOpeningBrace = preferences.insert_space_before_opening_brace_in_switch;
|
||||||
formatAttributes(bodyStmt, insertSpaceBeforeOpeningBrace, false);
|
formatAttributes(bodyStmt, insertSpaceBeforeOpeningBrace, false);
|
||||||
|
hasOpenBrace = peekNextToken() == Token.tLBRACE;
|
||||||
formatOpeningBrace(brace_position, insertSpaceBeforeOpeningBrace);
|
formatOpeningBrace(brace_position, insertSpaceBeforeOpeningBrace);
|
||||||
scribe.startNewLine();
|
scribe.startNewLine();
|
||||||
braceIndent = scribe.numberOfIndentations;
|
braceIndent = scribe.numberOfIndentations;
|
||||||
|
@ -4142,7 +4144,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
}
|
}
|
||||||
scribe.startNewLine();
|
scribe.startNewLine();
|
||||||
|
|
||||||
formatClosingBrace(brace_position);
|
if (hasOpenBrace)
|
||||||
|
formatClosingBrace(brace_position);
|
||||||
}
|
}
|
||||||
exitNode(bodyStmt);
|
exitNode(bodyStmt);
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
|
|
|
@ -4223,4 +4223,23 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
public void testAlignmentOfLambda3_Bug500000() throws Exception {
|
public void testAlignmentOfLambda3_Bug500000() throws Exception {
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
// int a;
|
||||||
|
// switch (a)
|
||||||
|
// default: {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//void foo() {
|
||||||
|
// int a;
|
||||||
|
// switch (a)
|
||||||
|
// default: {
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
public void testSwitchNoParen_Bug353022() throws Exception {
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue