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 a3690dacfa1..0ac31c35f2a 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 @@ -1241,9 +1241,15 @@ public class CodeFormatterVisitor extends CPPASTVisitor { IASTDeclSpecifier declSpec= node.getDeclSpecifier(); declSpec.accept(this); final List declarators= Arrays.asList(node.getDeclarators()); - if (declarators.size() >= 1) { - if (scribe.printComment()) { - scribe.space(); + if (!declarators.isEmpty()) { + if (declarators.size() == 1 && declarators.get(0) instanceof IASTFunctionDeclarator) { + if (scribe.preserveNewLine()) { + scribe.space(); + } + } else { + if (scribe.printComment()) { + scribe.space(); + } } final ListAlignment align= new ListAlignment(preferences.alignment_for_declarator_list); align.fSpaceAfterComma= preferences.insert_space_after_comma_in_declarator_list; @@ -1309,7 +1315,7 @@ public class CodeFormatterVisitor extends CPPASTVisitor { scribe.indent(); } } else { - // preserve newline if not explicitely requested + // preserve newline if not explicitly requested scribe.preserveNewLine(); } 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 ef7f6570662..e439be50179 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 @@ -1167,4 +1167,17 @@ public class CodeFormatterTest extends BaseUITestCase { public void testFormatterProblemsWithTypename_Bug269590() throws Exception { assertFormatterResult(); } + + //void + //foo(); + //int* + //bar(); + + //void + //foo(); + //int* + //bar(); + public void testPreserveNewlineBetweenTypeAndFunctionDeclarator() throws Exception { + assertFormatterResult(); + } }