Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java6
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java14
2 files changed, 17 insertions, 3 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 efe43cb5934..b1665f27f75 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
@@ -928,8 +928,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
*/
@Override
public int visit(IASTStatement node) {
- if (getCurrentPosition() <= nodeOffset(node) &&
- startsWithMacroExpansion(node)) {
+ if (getCurrentPosition() <= nodeOffset(node) && startsWithMacroExpansion(node)) {
scribe.printCommentPreservingNewLines();
}
if (!startNode(node)) { return PROCESS_SKIP; }
@@ -1916,7 +1915,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
} else {
if (startNode(declaration)) {
try {
- scribe.startNewLine();
+ if (getCurrentPosition() <= nodeOffset(declaration))
+ scribe.startNewLine();
formatDeclaration(declaration);
} finally {
finishNode(declaration);
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 dac004425f9..8b832972a30 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
@@ -1865,6 +1865,20 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult();
}
+ //#define MACRO(a) a(const a&); void operator=(const a&)
+ //
+ //class Test{MACRO(Test);};
+
+ //#define MACRO(a) a(const a&); void operator=(const a&)
+ //
+ //class Test {
+ // MACRO(Test);
+ //};
+ public void testMacroDeclaration() throws Exception {
+ fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
+ assertFormatterResult();
+ }
+
//bool member __attribute__ ((__unused__)) = false;
//bool member __attribute__ ((__unused__)) = false;

Back to the top