Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2009-01-29 09:16:23 +0000
committerAnton Leherbauer2009-01-29 09:16:23 +0000
commit12f1a7fe645223607aba47d78ba7bc08eaa8b3eb (patch)
tree1b9852040ad85b37479205b4dade7a9011ade2dc
parent7a755fc52729035d53557360ad11e0e0cc9c4e00 (diff)
downloadorg.eclipse.cdt-12f1a7fe645223607aba47d78ba7bc08eaa8b3eb.tar.gz
org.eclipse.cdt-12f1a7fe645223607aba47d78ba7bc08eaa8b3eb.tar.xz
org.eclipse.cdt-12f1a7fe645223607aba47d78ba7bc08eaa8b3eb.zip
Bug 262536 - [formatter] Problems with extern "C"
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java41
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java8
2 files changed, 27 insertions, 22 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
index 77dcf3a726c..a0aa7fef18c 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
@@ -772,11 +772,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
scribe.startNewLine();
for (int i = 0; i < memberDecls.length; i++) {
IASTDeclaration declaration = memberDecls[i];
- if (declaration instanceof ICPPASTVisibilityLabel) {
- visit((ICPPASTVisibilityLabel)declaration);
- } else {
- declaration.accept(this);
- }
+ declaration.accept(this);
scribe.startNewLine();
}
if (preferences.indent_body_declarations_compare_to_namespace_header) {
@@ -800,26 +796,27 @@ public class CodeFormatterVisitor extends CPPASTVisitor {
// member declarations
IASTDeclaration[] memberDecls= node.getDeclarations();
- // TLETODO [formatter] need options for linkage specification
- formatLeftCurlyBrace(line, preferences.brace_position_for_namespace_declaration);
- formatOpeningBrace(preferences.brace_position_for_namespace_declaration, preferences.insert_space_before_opening_brace_in_namespace_declaration);
- if (preferences.indent_body_declarations_compare_to_namespace_header) {
- scribe.indent();
- }
- scribe.startNewLine();
- for (int i = 0; i < memberDecls.length; i++) {
- IASTDeclaration declaration = memberDecls[i];
- if (declaration instanceof ICPPASTVisibilityLabel) {
- visit((ICPPASTVisibilityLabel)declaration);
- } else {
- declaration.accept(this);
+ if (memberDecls.length == 1 && peekNextToken() != Token.tLBRACE) {
+ scribe.space();
+ memberDecls[0].accept(this);
+ } else {
+ // TLETODO [formatter] need options for linkage specification
+ formatLeftCurlyBrace(line, preferences.brace_position_for_namespace_declaration);
+ formatOpeningBrace(preferences.brace_position_for_namespace_declaration, preferences.insert_space_before_opening_brace_in_namespace_declaration);
+ if (preferences.indent_body_declarations_compare_to_namespace_header) {
+ scribe.indent();
}
scribe.startNewLine();
+ for (int i = 0; i < memberDecls.length; i++) {
+ IASTDeclaration declaration = memberDecls[i];
+ declaration.accept(this);
+ scribe.startNewLine();
+ }
+ if (preferences.indent_body_declarations_compare_to_namespace_header) {
+ scribe.unIndent();
+ }
+ formatClosingBrace(preferences.brace_position_for_namespace_declaration);
}
- if (preferences.indent_body_declarations_compare_to_namespace_header) {
- scribe.unIndent();
- }
- formatClosingBrace(preferences.brace_position_for_namespace_declaration);
return PROCESS_SKIP;
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
index 5f84019ebe9..ba8450da56b 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
@@ -1091,5 +1091,13 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testPreserveSpaceBetweenNameAnd__attribute__Bug261967() throws Exception {
assertFormatterResult();
}
+
+ //extern "C" void f(int i, char c, float x);
+
+ //extern "C" void f(int i, char c, float x);
+ public void testPreserveSpaceInExternCDeclaration() throws Exception {
+ assertFormatterResult();
+ }
+
}

Back to the top