From ce60ebbbf6ce252c4acd2408cee70ac57f42b424 Mon Sep 17 00:00:00 2001 From: Marco Stornelli Date: Sat, 6 Apr 2019 10:42:44 +0200 Subject: [PATCH] Bug 397710 - Fix bool macro used in struct/class Change-Id: Ifc900b4b5f522ce778c49072eb9ceac7be9234ed Signed-off-by: Marco Stornelli --- .../formatter/CodeFormatterVisitor.java | 29 ++++++++++++------- .../cdt/ui/tests/text/CodeFormatterTest.java | 15 ++++++++++ 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(); + } }