From 5c77776dcd0bd006d0161cc0d7d6870e738dd8b0 Mon Sep 17 00:00:00 2001 From: Marco Stornelli Date: Sun, 13 Oct 2019 10:14:28 +0200 Subject: [PATCH] Bug 550096 - Fix format function parameters in macro expansion Change-Id: I509e434032a49a853e1794ab2d4b5a6a864eb5da Signed-off-by: Marco Stornelli --- .../cdt/internal/formatter/CodeFormatterVisitor.java | 6 ++++-- .../org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java | 9 +++++++++ 2 files changed, 13 insertions(+), 2 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 05c2f61d5b4..2506888c156 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 @@ -2483,8 +2483,10 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, */ private void formatList(List elements, ListOptions options, boolean encloseInParen, boolean addEllipsis, Runnable tailFormatter, Runnable prefix) { - if (encloseInParen) - scribe.printNextToken(options.leftToken, options.fSpaceBeforeOpeningParen); + if (encloseInParen) { + if (peekNextToken() == options.leftToken) + scribe.printNextToken(options.leftToken, options.fSpaceBeforeOpeningParen); + } final int elementsLength = elements.size(); if (encloseInParen) { 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 f7f52b193ad..c112ca61d88 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 @@ -4699,4 +4699,13 @@ public class CodeFormatterTest extends BaseUITestCase { public void testStructuredBindingInSwitchInitStatement() throws Exception { assertFormatterResult(); } + + //#define PROTO(X) X + //void foo PROTO((char* b)); + + //#define PROTO(X) X + //void foo PROTO((char* b)); + public void testMacroInFunctionParameters_Bug550096() throws Exception { + assertFormatterResult(); + } }