Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarco Stornelli2019-03-10 12:25:45 -0400
committerJonah Graham2019-04-08 12:51:41 -0400
commit280c0190d2e4ff33ed35135a011d934e15cb1c64 (patch)
tree9c9eaab532adaf4aa44cf9cec098759e0eb9d43a /core
parent77592ee87ac41d54f18715892fa8090c7245c53a (diff)
downloadorg.eclipse.cdt-280c0190d2e4ff33ed35135a011d934e15cb1c64.tar.gz
org.eclipse.cdt-280c0190d2e4ff33ed35135a011d934e15cb1c64.tar.xz
org.eclipse.cdt-280c0190d2e4ff33ed35135a011d934e15cb1c64.zip
Bug 453385 - Fix for loop formatting
When "before semicolon" was selected the space was inserted only if the init clause was a declaration. If it was an expression the formatter was skipped. Change-Id: I54605591b9a0829338dadb51e59460064b060697 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java12
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java19
2 files changed, 23 insertions, 8 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 aad171e7f8..20350cc9f6 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
@@ -3255,15 +3255,11 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private int visit(IASTExpressionStatement node) {
Runnable semicolonFormatter = null;
- if (!fHasClauseInitStatement) {
- semicolonFormatter = new TrailingSemicolonFormatter(node);
- scribe.setTailFormatter(semicolonFormatter);
- }
+ semicolonFormatter = new TrailingSemicolonFormatter(node);
+ scribe.setTailFormatter(semicolonFormatter);
node.getExpression().accept(this);
- if (semicolonFormatter != null) {
- semicolonFormatter.run();
- scribe.setTailFormatter(null);
- }
+ semicolonFormatter.run();
+ scribe.setTailFormatter(null);
if (!fHasClauseInitStatement) {
scribe.startNewLine();
}
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 a921e2bff3..b4121dbfc3 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
@@ -3903,4 +3903,23 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testFormmatterWithMacroFuncStyle_Bug475349() throws Exception {
assertFormatterResult();
}
+
+ //int main() {
+ // int i = 0;
+ // for(i = 0;i<3;i++){
+ // }
+ // return 0;
+ //}
+
+ //int main() {
+ // int i = 0;
+ // for (i = 0 ; i < 3 ; i++) {
+ // }
+ // return 0;
+ //}
+ public void testSpaceAfterSemicolonInFor_Bug453385() throws Exception {
+ fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_SEMICOLON_IN_FOR, CCorePlugin.INSERT);
+ fOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_SEMICOLON_IN_FOR, CCorePlugin.INSERT);
+ assertFormatterResult();
+ }
}

Back to the top