1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 351399 - Formatting C code is broken for certain coding styles

This commit is contained in:
Anton Leherbauer 2011-08-05 10:37:58 +02:00
parent 415f3eda29
commit 44e3ec0cde
2 changed files with 106 additions and 2 deletions

View file

@ -3132,11 +3132,18 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
formatLeftCurlyBrace(line, preferences.brace_position_for_block);
if (startNode(body)) {
try {
final boolean braceOnSameLine = DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_block);
if (!braceOnSameLine) {
ok = true;
scribe.exitAlignment(alignment, true);
}
formatBlockOpening((IASTCompoundStatement) body,
preferences.brace_position_for_block,
preferences.insert_space_before_opening_brace_in_block);
ok = true;
scribe.exitAlignment(alignment, true);
if (braceOnSameLine) {
ok = true;
scribe.exitAlignment(alignment, true);
}
formatOpenedBlock((IASTCompoundStatement) body,
preferences.brace_position_for_block,
preferences.indent_statements_compare_to_block);

View file

@ -2383,4 +2383,101 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testDoubleClosingAngleBrackets_Bug333816() throws Exception {
assertFormatterResult();
}
//void foo() {
// int i;
// for (iiiiiiiiiiiiiiiiii = 0; iiiiiiiiiiiiiiiiii < 10; iiiiiiiiiiiiiiiiii++) {
// }
// foo();
//}
//void foo() {
// int i;
// for (iiiiiiiiiiiiiiiiii = 0; iiiiiiiiiiiiiiiiii < 10;
// iiiiiiiiiiiiiiiiii++) {
// }
// foo();
//}
public void testForLoopWrappingAtOpeningBrace() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT, "80");
assertFormatterResult();
}
//void foo() {
// int i;
// for (i = 0; i < 10; i++) {
// }
// foo();
//}
//void foo() {
// int i;
// for (i = 0; i < 10; i++) {
// }
// foo();
//}
public void testForLoopKnR_Bug351399() throws Exception {
assertFormatterResult();
}
//void foo() {
// int i;
// for (i = 0; i < 10; i++) {
// }
// foo();
//}
//void foo()
// {
// int i;
// for (i = 0; i < 10; i++)
// {
// }
// foo();
// }
public void testForLoopWhitesmiths_Bug351399() throws Exception {
fOptions.putAll(DefaultCodeFormatterOptions.getWhitesmithsSettings().getMap());
assertFormatterResult();
}
//void foo() {
// int i;
// for (i = 0; i < 10; i++) {
// }
// foo();
//}
//void
//foo()
//{
// int i;
// for (i = 0; i < 10; i++)
// {
// }
// foo();
//}
public void testForLoopGNU_Bug351399() throws Exception {
fOptions.putAll(DefaultCodeFormatterOptions.getGNUSettings().getMap());
assertFormatterResult();
}
//void foo() {
// int i;
// for (i = 0; i < 10; i++) {
// }
// foo();
//}
//void foo()
//{
// int i;
// for (i = 0; i < 10; i++)
// {
// }
// foo();
//}
public void testForLoopAllman_Bug351399() throws Exception {
fOptions.putAll(DefaultCodeFormatterOptions.getAllmanSettings().getMap());
assertFormatterResult();
}
}