Bug 550096 - Fix format function parameters in macro expansion
Change-Id: I509e434032a49a853e1794ab2d4b5a6a864eb5da
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
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 05c2f61..2506888 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 @@
*/
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 f7f52b1..c112ca6 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 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();
+ }
}