mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 359658 - code formatter does not work as expected when complicate macro precedes formatted code
This commit is contained in:
parent
c617df3475
commit
e7f50acc25
2 changed files with 40 additions and 14 deletions
|
@ -3033,22 +3033,24 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
final IASTStatement action = node.getBody();
|
||||
formatAction(line, action, preferences.brace_position_for_block);
|
||||
|
||||
if (peekNextToken() == Token.t_while) {
|
||||
if (preferences.insert_new_line_before_while_in_do_statement) {
|
||||
scribe.startNewLine();
|
||||
if (scribe.scanner.getCurrentPosition() < getNodeEndLocation(node)) {
|
||||
if (peekNextToken() == Token.t_while) {
|
||||
if (preferences.insert_new_line_before_while_in_do_statement) {
|
||||
scribe.startNewLine();
|
||||
}
|
||||
scribe.printNextToken(Token.t_while, preferences.insert_space_after_closing_brace_in_block);
|
||||
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_while);
|
||||
|
||||
if (preferences.insert_space_after_opening_paren_in_while) {
|
||||
scribe.space();
|
||||
}
|
||||
|
||||
node.getCondition().accept(this);
|
||||
|
||||
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_while);
|
||||
}
|
||||
scribe.printNextToken(Token.t_while, preferences.insert_space_after_closing_brace_in_block);
|
||||
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_while);
|
||||
|
||||
if (preferences.insert_space_after_opening_paren_in_while) {
|
||||
scribe.space();
|
||||
}
|
||||
|
||||
node.getCondition().accept(this);
|
||||
|
||||
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_while);
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||
}
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||
scribe.printTrailingComment();
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
@ -4021,6 +4023,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
return node1.getFileLocation().getNodeOffset() == node2.getFileLocation().getNodeOffset();
|
||||
}
|
||||
|
||||
private static int getNodeEndLocation(IASTNode node) {
|
||||
IASTFileLocation loc = node.getFileLocation();
|
||||
return loc.getNodeOffset() + loc.getNodeLength();
|
||||
}
|
||||
|
||||
private void formatBlock(IASTCompoundStatement block, String block_brace_position,
|
||||
boolean insertSpaceBeforeOpeningBrace, boolean indentStatements) {
|
||||
formatBlockOpening(block, block_brace_position, insertSpaceBeforeOpeningBrace);
|
||||
|
|
|
@ -2758,4 +2758,23 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_COMMENT_MIN_DISTANCE_BETWEEN_CODE_AND_LINE_COMMENT, "2");
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//#define TESTING(m) ;do{}while(0)
|
||||
//void f() {
|
||||
// TESTING(1);
|
||||
// if(Test(a) != 1) {
|
||||
// status = ERROR;
|
||||
// }
|
||||
//}
|
||||
|
||||
//#define TESTING(m) ;do{}while(0)
|
||||
//void f() {
|
||||
// TESTING(1);
|
||||
// if (Test(a) != 1) {
|
||||
// status = ERROR;
|
||||
// }
|
||||
//}
|
||||
public void testDoWhileInMacro_Bug359658() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue