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:
parent
415f3eda29
commit
44e3ec0cde
2 changed files with 106 additions and 2 deletions
|
@ -3132,11 +3132,18 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
formatLeftCurlyBrace(line, preferences.brace_position_for_block);
|
formatLeftCurlyBrace(line, preferences.brace_position_for_block);
|
||||||
if (startNode(body)) {
|
if (startNode(body)) {
|
||||||
try {
|
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,
|
formatBlockOpening((IASTCompoundStatement) body,
|
||||||
preferences.brace_position_for_block,
|
preferences.brace_position_for_block,
|
||||||
preferences.insert_space_before_opening_brace_in_block);
|
preferences.insert_space_before_opening_brace_in_block);
|
||||||
ok = true;
|
if (braceOnSameLine) {
|
||||||
scribe.exitAlignment(alignment, true);
|
ok = true;
|
||||||
|
scribe.exitAlignment(alignment, true);
|
||||||
|
}
|
||||||
formatOpenedBlock((IASTCompoundStatement) body,
|
formatOpenedBlock((IASTCompoundStatement) body,
|
||||||
preferences.brace_position_for_block,
|
preferences.brace_position_for_block,
|
||||||
preferences.indent_statements_compare_to_block);
|
preferences.indent_statements_compare_to_block);
|
||||||
|
|
|
@ -2383,4 +2383,101 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
public void testDoubleClosingAngleBrackets_Bug333816() throws Exception {
|
public void testDoubleClosingAngleBrackets_Bug333816() throws Exception {
|
||||||
assertFormatterResult();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue