mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +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) {
|
||||
scribe.startNewLine();
|
||||
}
|
||||
} else if (thenStatement instanceof IASTCompoundStatement && !enclosedInMacroExpansion(thenStatement)) {
|
||||
thenStatement.accept(this);
|
||||
} else {
|
||||
scribe.printTrailingComment();
|
||||
scribe.startNewLine();
|
||||
|
@ -2508,10 +2510,12 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
|
|||
}
|
||||
|
||||
if (elseStatement != null) {
|
||||
if (thenStatementIsBlock) {
|
||||
scribe.printNextToken(Token.t_else, preferences.insert_space_after_closing_brace_in_block);
|
||||
} else {
|
||||
scribe.printNextToken(Token.t_else, true);
|
||||
if (!startsWithMacroExpansion(elseStatement)) {
|
||||
if (thenStatementIsBlock) {
|
||||
scribe.printNextToken(Token.t_else, preferences.insert_space_after_closing_brace_in_block);
|
||||
} else {
|
||||
scribe.printNextToken(Token.t_else, true);
|
||||
}
|
||||
}
|
||||
if (elseStatement instanceof IASTCompoundStatement) {
|
||||
elseStatement.accept(this);
|
||||
|
|
|
@ -1228,4 +1228,86 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
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