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
|
// probably a macro with empty expansion
|
||||||
skipToNode(node);
|
skipToNode(node);
|
||||||
}
|
}
|
||||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
if (!fInsideFor) {
|
||||||
scribe.printTrailingComment();
|
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||||
|
scribe.printTrailingComment();
|
||||||
|
}
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1605,31 +1607,35 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
final int line = scribe.line;
|
final int line = scribe.line;
|
||||||
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_for);
|
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_for);
|
||||||
fInsideFor= true;
|
fInsideFor= true;
|
||||||
|
try {
|
||||||
if (preferences.insert_space_after_opening_paren_in_for) {
|
if (preferences.insert_space_after_opening_paren_in_for) {
|
||||||
scribe.space();
|
|
||||||
}
|
|
||||||
IASTStatement initializerStmt= node.getInitializerStatement();
|
|
||||||
initializerStmt.accept(this);
|
|
||||||
if (peekNextToken() == Token.tSEMI) {
|
|
||||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for);
|
|
||||||
}
|
|
||||||
final IASTExpression condition = node.getConditionExpression();
|
|
||||||
if (condition != null) {
|
|
||||||
if (preferences.insert_space_after_semicolon_in_for) {
|
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
condition.accept(this);
|
IASTStatement initializerStmt= node.getInitializerStatement();
|
||||||
}
|
initializerStmt.accept(this);
|
||||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for);
|
if (peekNextToken() == Token.tSEMI) {
|
||||||
IASTExpression iterationExpr= node.getIterationExpression();
|
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon_in_for);
|
||||||
if (iterationExpr != null) {
|
|
||||||
if (preferences.insert_space_after_semicolon_in_for) {
|
|
||||||
scribe.space();
|
|
||||||
}
|
}
|
||||||
iterationExpr.accept(this);
|
final IASTExpression condition = node.getConditionExpression();
|
||||||
|
if (condition != null) {
|
||||||
|
if (preferences.insert_space_after_semicolon_in_for) {
|
||||||
|
scribe.space();
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
scribe.space();
|
||||||
|
}
|
||||||
|
iterationExpr.accept(this);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
fInsideFor= false;
|
||||||
}
|
}
|
||||||
fInsideFor= false;
|
|
||||||
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_for);
|
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);
|
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();
|
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