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.java29
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java15
2 files changed, 33 insertions, 11 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 307faf27359..e71e9c5a828 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
@@ -2003,7 +2003,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.startNewLine();
IASTDeclaration[] memberDecls = node.getMembers();
- for (IASTDeclaration declaration : memberDecls) {
+ for (int i = 0; i < memberDecls.length; i++) {
+ IASTDeclaration declaration = memberDecls[i];
if (preferences.indent_body_declarations_compare_to_access_specifier) {
scribe.indent();
}
@@ -2012,18 +2013,24 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
if (preferences.indent_body_declarations_compare_to_access_specifier) {
scribe.unIndent();
}
- if (enterNode(declaration)) {
- scribe.startNewLine();
- visit((ICPPASTVisibilityLabel) declaration);
- scribe.startNewLine();
- exitNode(declaration);
- }
- } else {
- if (enterNode(declaration)) {
+ IASTDeclaration next = null;
+ if (i < memberDecls.length - 1 && !(memberDecls[i + 1] instanceof IASTProblemHolder))
+ next = memberDecls[i + 1];
+ if (i == memberDecls.length - 1 || next == null || !doNodeLocationsOverlap(declaration, next)) {
if (getCurrentPosition() <= nodeOffset(declaration))
scribe.startNewLine();
- formatDeclaration(declaration);
- exitNode(declaration);
+ }
+ declaration.accept(this);
+ } else {
+ if (!(declaration instanceof IASTProblemHolder)) {
+ IASTDeclaration next = null;
+ if (i < memberDecls.length - 1 && !(memberDecls[i + 1] instanceof IASTProblemHolder))
+ next = memberDecls[i + 1];
+ if (i == memberDecls.length - 1 || next == null || !doNodeLocationsOverlap(declaration, next)) {
+ if (getCurrentPosition() <= nodeOffset(declaration))
+ scribe.startNewLine();
+ }
+ declaration.accept(this);
} else {
skipNode(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 bd8d67485c5..021b5a813ef 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
@@ -4003,4 +4003,19 @@ public class CodeFormatterTest extends BaseUITestCase {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_SEMICOLON_IN_FOR, CCorePlugin.INSERT);
assertFormatterResult();
}
+
+ //#define bool bool
+ //struct ARGS {
+ // bool _unprune;
+ // bool _distributed_timing;
+ //};
+
+ //#define bool bool
+ //struct ARGS {
+ // bool _unprune;
+ // bool _distributed_timing;
+ //};
+ public void testBoolInStructWithMacro_Bug397710() throws Exception {
+ assertFormatterResult();
+ }
}

Back to the top