mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
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>
This commit is contained in:
parent
77592ee87a
commit
280c0190d2
2 changed files with 23 additions and 8 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue