mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Fix for 195942: [Formatter] for with empty expression causes confusion
This commit is contained in:
parent
805b73fcc9
commit
39b2ea6eb4
2 changed files with 67 additions and 23 deletions
|
@ -1578,8 +1578,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
// probably a macro with empty expansion
|
||||
skipToNode(node);
|
||||
}
|
||||
if (!fInsideFor) {
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||
scribe.printTrailingComment();
|
||||
}
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
@ -1605,7 +1607,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
final int line = scribe.line;
|
||||
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_for);
|
||||
fInsideFor= true;
|
||||
|
||||
try {
|
||||
if (preferences.insert_space_after_opening_paren_in_for) {
|
||||
scribe.space();
|
||||
}
|
||||
|
@ -1621,7 +1623,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
}
|
||||
condition.accept(this);
|
||||
}
|
||||
if (peekNextToken() == Token.tSEMI) {
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for);
|
||||
}
|
||||
IASTExpression iterationExpr= node.getIterationExpression();
|
||||
if (iterationExpr != null) {
|
||||
if (preferences.insert_space_after_semicolon_in_for) {
|
||||
|
@ -1629,7 +1633,9 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
}
|
||||
iterationExpr.accept(this);
|
||||
}
|
||||
} finally {
|
||||
fInsideFor= false;
|
||||
}
|
||||
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_for);
|
||||
|
||||
formatAction(line, node.getBody(), preferences.brace_position_for_block, preferences.insert_space_before_opening_brace_in_block);
|
||||
|
|
|
@ -141,4 +141,42 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//void foo(){
|
||||
//for(;;){
|
||||
//int a=0;
|
||||
//switch(a){
|
||||
//case 0:
|
||||
//++a;
|
||||
//break;
|
||||
//case 1:
|
||||
//--a;
|
||||
//break;
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
//int main(void){
|
||||
//foo();
|
||||
//return 1;
|
||||
//}
|
||||
|
||||
//void foo() {
|
||||
// for (;;) {
|
||||
// int a=0;
|
||||
// switch (a) {
|
||||
// case 0:
|
||||
// ++a;
|
||||
// break;
|
||||
// case 1:
|
||||
// --a;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//int main(void) {
|
||||
// foo();
|
||||
// return 1;
|
||||
//}
|
||||
public void testForWithEmptyExpression_Bug195942() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue