From 6e17efaddef4867d55639f46c2ffbaa65bd44a86 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 29 Jan 2009 09:16:37 +0000 Subject: [PATCH] Bug 262536 - [formatter] Problems with extern "C" --- .../formatter/CodeFormatterVisitor.java | 41 +++++++++---------- .../cdt/ui/tests/text/CodeFormatterTest.java | 8 ++++ 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 bc00a51b600..3ebfbcb083b 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 @@ -771,11 +771,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) { @@ -799,26 +795,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 f5e41b4d07f..9981f8e9d41 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 @@ -1136,4 +1136,12 @@ 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(); + } + }