Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-04-14 19:57:35 -0400
committerSergey Prigogin2012-04-14 19:57:35 -0400
commit9d10668c5ef9fd41dfb454c35a7558629860b27f (patch)
tree6c0cb150cc99a1bd8df3b28b9978fe3a55100743
parentb6cf5bbc413fa151104526aa3affd20aef971782 (diff)
downloadorg.eclipse.cdt-9d10668c5ef9fd41dfb454c35a7558629860b27f.tar.gz
org.eclipse.cdt-9d10668c5ef9fd41dfb454c35a7558629860b27f.tar.xz
org.eclipse.cdt-9d10668c5ef9fd41dfb454c35a7558629860b27f.zip
Fixed a bug in formatting of declarations contained in macro expansion.
-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 efe43cb593..b1665f27f7 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 dac004425f..8b832972a3 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