mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Bug 535278: Formatter error formatting CF statements with attributes
Fix and tests. Change-Id: I1928d5fe70c02cbc9c147bb305720ad75b4913fc Signed-off-by: Hansruedi Patzen <hansruedi.patzen@hsr.ch> Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
parent
8eefa560ac
commit
66df5ff428
2 changed files with 93 additions and 0 deletions
|
@ -56,6 +56,7 @@ import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
||||
|
@ -984,6 +985,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
visit((IASTCaseStatement) node);
|
||||
} else if (node instanceof IASTDefaultStatement) {
|
||||
visit((IASTDefaultStatement) node);
|
||||
} else if (node instanceof IASTGotoStatement) {
|
||||
visit((IASTGotoStatement) node);
|
||||
} else if (node instanceof IASTLabelStatement) {
|
||||
visit((IASTLabelStatement) node);
|
||||
} else if (node instanceof IASTProblemStatement) {
|
||||
|
@ -2241,6 +2244,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
|
||||
private int visit(IASTBreakStatement node) {
|
||||
formatLeadingAttributes(node);
|
||||
scribe.printNextToken(Token.t_break);
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||
scribe.printTrailingComment();
|
||||
|
@ -3137,6 +3141,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
|
||||
private int visit(IASTContinueStatement node) {
|
||||
formatLeadingAttributes(node);
|
||||
scribe.printNextToken(Token.t_continue);
|
||||
scribe.printNextToken(Token.tSEMI, preferences.insert_space_before_semicolon);
|
||||
scribe.printTrailingComment();
|
||||
|
@ -3583,6 +3588,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
}
|
||||
|
||||
private int visit(IASTReturnStatement node) {
|
||||
formatLeadingAttributes(node);
|
||||
scribe.printNextToken(Token.t_return);
|
||||
final IASTExpression expression = node.getReturnValue();
|
||||
if (expression != null) {
|
||||
|
@ -3602,6 +3608,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
|
||||
private int visit(IASTLabelStatement node) {
|
||||
// TLETODO [formatter] label indentation
|
||||
formatLeadingAttributes(node);
|
||||
node.getName().accept(this);
|
||||
scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_labeled_statement);
|
||||
if (preferences.insert_space_after_colon_in_labeled_statement) {
|
||||
|
@ -3633,6 +3640,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
|||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
|
||||
private int visit(IASTGotoStatement node) {
|
||||
formatLeadingAttributes(node);
|
||||
formatRaw(node);
|
||||
return PROCESS_SKIP;
|
||||
}
|
||||
|
||||
private void beginSwitchClause() {
|
||||
scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_switch);
|
||||
if (preferences.insert_space_after_opening_paren_in_switch) {
|
||||
|
|
|
@ -3446,4 +3446,83 @@ public class CodeFormatterTest extends BaseUITestCase {
|
|||
public void testAttributedSwitchCompoundStatement_Bug535263_2() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// [[foo]]continue;
|
||||
// }
|
||||
//}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// [[foo]] continue;
|
||||
// }
|
||||
//}
|
||||
public void testAttributedContinueStatement_Bug535278_1() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// [[foo]]break;
|
||||
// }
|
||||
//}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// [[foo]] break;
|
||||
// }
|
||||
//}
|
||||
public void testAttributedBreakStatement_Bug535278_2() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// [[foo]]return;
|
||||
// }
|
||||
//}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// [[foo]] return;
|
||||
// }
|
||||
//}
|
||||
public void testAttributedReturnStatement_Bug535278_3() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// [[foo]]goto label;
|
||||
// }
|
||||
// label: ;
|
||||
//}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// [[foo]] goto label;
|
||||
// }
|
||||
// label: ;
|
||||
//}
|
||||
public void testAttributedGotoStatement_Bug535278_4() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// goto label;
|
||||
// }
|
||||
// [[bar]]label: ;
|
||||
//}
|
||||
|
||||
//void f() {
|
||||
// for (;;) {
|
||||
// goto label;
|
||||
// }
|
||||
// [[bar]] label: ;
|
||||
//}
|
||||
public void testAttributedGotoLabel_Bug535278_5() throws Exception {
|
||||
assertFormatterResult();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue