From 4a4c5fca4dee26c5655b01b526d44eac66863b58 Mon Sep 17 00:00:00 2001 From: Marco Stornelli Date: Sun, 29 Mar 2020 16:23:48 +0200 Subject: [PATCH] Bug 561559 - Fix formatting def capture lambda expressions We missed a space before the closing brackets if the proper option was selected. Change-Id: Ibbb09c3c961dc1b5e22aaa65ffb5d9878c2bb08b --- .../formatter/CodeFormatterVisitor.java | 5 +++-- .../cdt/ui/tests/text/CodeFormatterTest.java | 19 +++++++++++++++++++ 2 files changed, 22 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 70fbedd4890..08f8b002805 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 @@ -2515,8 +2515,9 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, final int elementsLength = elements.size(); if (encloseInParen) { - boolean spaceBeforeClosingParen = elements.isEmpty() && !addEllipsis ? options.fSpaceBetweenEmptyParen - : options.fSpaceBeforeClosingParen; + boolean spaceBeforeClosingParen = elements.isEmpty() && !addEllipsis + && options.captureDefault == CaptureDefault.UNSPECIFIED ? options.fSpaceBetweenEmptyParen + : options.fSpaceBeforeClosingParen; tailFormatter = new ClosingParensesisTailFormatter(spaceBeforeClosingParen, tailFormatter, options.rightToken); } 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 74997c84ac7..c72f0b79fa0 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 @@ -4771,4 +4771,23 @@ public class CodeFormatterTest extends BaseUITestCase { public void testDeductionGuideExplicit() throws Exception { assertFormatterResult(); } + + //int main() { + // auto f = [&](){ + // }; + // return 0; + //} + + //int main() { + // auto f = [ & ]() { + // }; + // return 0; + //} + public void testLambdaExpressionOnlyDefCapture_Bug561559() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_PAREN_IN_METHOD_DECLARATION, + CCorePlugin.INSERT); + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_CLOSING_PAREN_IN_METHOD_DECLARATION, + CCorePlugin.INSERT); + assertFormatterResult(); + } }