mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 20:05:35 +02:00
Bug 290630 - [formatter] More heuristics for if-else in macros
This commit is contained in:
parent
dc18c3165d
commit
e5d01853a5
2 changed files with 90 additions and 4 deletions
|
@ -2494,6 +2494,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
if (elseStatement != null) {
|
if (elseStatement != null) {
|
||||||
scribe.startNewLine();
|
scribe.startNewLine();
|
||||||
}
|
}
|
||||||
|
} else if (thenStatement instanceof IASTCompoundStatement && !enclosedInMacroExpansion(thenStatement)) {
|
||||||
|
thenStatement.accept(this);
|
||||||
} else {
|
} else {
|
||||||
scribe.printTrailingComment();
|
scribe.printTrailingComment();
|
||||||
scribe.startNewLine();
|
scribe.startNewLine();
|
||||||
|
@ -2508,11 +2510,13 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (elseStatement != null) {
|
if (elseStatement != null) {
|
||||||
|
if (!startsWithMacroExpansion(elseStatement)) {
|
||||||
if (thenStatementIsBlock) {
|
if (thenStatementIsBlock) {
|
||||||
scribe.printNextToken(Token.t_else, preferences.insert_space_after_closing_brace_in_block);
|
scribe.printNextToken(Token.t_else, preferences.insert_space_after_closing_brace_in_block);
|
||||||
} else {
|
} else {
|
||||||
scribe.printNextToken(Token.t_else, true);
|
scribe.printNextToken(Token.t_else, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (elseStatement instanceof IASTCompoundStatement) {
|
if (elseStatement instanceof IASTCompoundStatement) {
|
||||||
elseStatement.accept(this);
|
elseStatement.accept(this);
|
||||||
} else if (elseStatement instanceof IASTIfStatement) {
|
} else if (elseStatement instanceof IASTIfStatement) {
|
||||||
|
|
|
@ -1228,4 +1228,86 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
assertFormatterResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#define If if (1 == 1){
|
||||||
|
//#define Else } else {
|
||||||
|
//#define EndElse }
|
||||||
|
//
|
||||||
|
//#define Try try{
|
||||||
|
//#define Catch } catch(...) {
|
||||||
|
//#define EndCatch }
|
||||||
|
//
|
||||||
|
//int main() {
|
||||||
|
// Try
|
||||||
|
// cout << "OK2" << endl;
|
||||||
|
// Catch
|
||||||
|
// cout << "Exception" << endl;
|
||||||
|
// EndCatch
|
||||||
|
// Try
|
||||||
|
// cout << "OK2" << endl;
|
||||||
|
// Catch
|
||||||
|
// cout << "Exception" << endl;
|
||||||
|
// EndCatch
|
||||||
|
//
|
||||||
|
// If
|
||||||
|
// cout << "OK" << endl;
|
||||||
|
// Else
|
||||||
|
// cout << "Strange" << endl;
|
||||||
|
// EndElse
|
||||||
|
//
|
||||||
|
// Try
|
||||||
|
// cout << "OK2" << endl;
|
||||||
|
// Catch
|
||||||
|
// cout << "Exception" << endl;
|
||||||
|
// EndCatch
|
||||||
|
// Try
|
||||||
|
// cout << "OK2" << endl;
|
||||||
|
// Catch
|
||||||
|
// cout << "Exception" << endl;
|
||||||
|
// EndCatch
|
||||||
|
//
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//#define If if (1 == 1){
|
||||||
|
//#define Else } else {
|
||||||
|
//#define EndElse }
|
||||||
|
//
|
||||||
|
//#define Try try{
|
||||||
|
//#define Catch } catch(...) {
|
||||||
|
//#define EndCatch }
|
||||||
|
//
|
||||||
|
//int main() {
|
||||||
|
// Try
|
||||||
|
// cout << "OK2" << endl;
|
||||||
|
// Catch
|
||||||
|
// cout << "Exception" << endl;
|
||||||
|
// EndCatch
|
||||||
|
// Try
|
||||||
|
// cout << "OK2" << endl;
|
||||||
|
// Catch
|
||||||
|
// cout << "Exception" << endl;
|
||||||
|
// EndCatch
|
||||||
|
//
|
||||||
|
// If
|
||||||
|
// cout << "OK" << endl;
|
||||||
|
// Else
|
||||||
|
// cout << "Strange" << endl;
|
||||||
|
// EndElse
|
||||||
|
//
|
||||||
|
// Try
|
||||||
|
// cout << "OK2" << endl;
|
||||||
|
// Catch
|
||||||
|
// cout << "Exception" << endl;
|
||||||
|
// EndCatch
|
||||||
|
// Try
|
||||||
|
// cout << "OK2" << endl;
|
||||||
|
// Catch
|
||||||
|
// cout << "Exception" << endl;
|
||||||
|
// EndCatch
|
||||||
|
//
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
public void testControlStatementsAsMacro_Bug290630() throws Exception {
|
||||||
|
assertFormatterResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue