diff --git a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterAttributeTestSource.awts b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterAttributeTestSource.awts index ad49798b308..d23f8a3891e 100644 --- a/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterAttributeTestSource.awts +++ b/core/org.eclipse.cdt.core.tests/resources/rewrite/ASTWriterAttributeTestSource.awts @@ -199,6 +199,84 @@ void bar() [[attr]] int i; } +//!Attributed Do-while Statement 514684 +//%CPP +void foo() +{ + [[attr]] do{ + } while (true); +} + +//!Attributed For Statement 514684 +//%CPP +void foo() +{ + [[attr]] for (int i = 0;i < 10;i++){ + } +} + +//!Attributed Range-Based For Statement 514684 +//%CPP +void foo() +{ + int a[] = {0, 1, 2}; + [[attr]] for (int n: a){ + } +} + +//!Attributed Break Statement 514684 +//%CPP +void foo() +{ + while (true){ + [[attr]] break; + } +} + +//!Attributed Continue Statement 514684 +//%CPP +void foo() +{ + while (true){ + [[attr]] continue; + } +} + +//!Attributed Goto Statement 514684 +//%CPP +void foo() +{ + [[attr]] goto label; + label: + ; +} + +//!Attributed GNU Goto Statement 514684 +//%CPP GNU +void foo() +{ + label2: + ; + void* ptr = &&label2; + [[attr]] goto *ptr; +} + +//!Attributed Null Statement 514684 +//%CPP +void foo() +{ + [[attr]]; +} + +//!Attributed Switch Statement 514684 +//%CPP +void foo() +{ + [[attr]] switch (1){ + default: + } +} + //!Empty Attribute //%CPP [[]] int i; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java index a11ec90d526..54b117d1364 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java @@ -163,6 +163,7 @@ public class StatementWriter extends NodeWriter { } private void writeDoStatement(IASTDoStatement doStatement) { + writeAttributes(doStatement, EnumSet.of(SpaceLocation.AFTER)); nextCompoundNoNewLine(); scribe.print(DO); @@ -174,6 +175,7 @@ public class StatementWriter extends NodeWriter { } private void writeForStatement(IASTForStatement forStatement) { + writeAttributes(forStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.noNewLines(); scribe.print(FOR); writeStatement(forStatement.getInitializerStatement(),false); @@ -201,6 +203,7 @@ public class StatementWriter extends NodeWriter { } private void writeForStatement(ICPPASTRangeBasedForStatement forStatment) { + writeAttributes(forStatment, EnumSet.of(SpaceLocation.AFTER)); scribe.noNewLines(); scribe.print(FOR); writeDeclarationWithoutSemicolon(forStatment.getDeclaration()); @@ -246,11 +249,13 @@ public class StatementWriter extends NodeWriter { } private void writeBreakStatement(IASTBreakStatement statement) { + writeAttributes(statement, EnumSet.of(SpaceLocation.AFTER)); scribe.print(BREAK); scribe.printSemicolon(); } private void writeContinueStatement(IASTContinueStatement statement) { + writeAttributes(statement, EnumSet.of(SpaceLocation.AFTER)); scribe.print(CONTINUE); scribe.printSemicolon(); } @@ -264,12 +269,14 @@ public class StatementWriter extends NodeWriter { } private void writeGotoStatement(IASTGotoStatement gotoStatement) { + writeAttributes(gotoStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.print(GOTO); gotoStatement.getName().accept(visitor); scribe.printSemicolon(); } private void writeGNUASTGotoStatement(IGNUASTGotoStatement gotoStatement) { + writeAttributes(gotoStatement, EnumSet.of(SpaceLocation.AFTER)); scribe.print(GOTO); gotoStatement.getLabelNameExpression().accept(visitor); scribe.printSemicolon(); @@ -289,6 +296,7 @@ public class StatementWriter extends NodeWriter { } private void writeNullStatement(IASTNullStatement nullStmt) { + writeAttributes(nullStmt, EnumSet.noneOf(SpaceLocation.class)); scribe.printSemicolon(); } @@ -360,6 +368,7 @@ public class StatementWriter extends NodeWriter { } private void writeSwitchStatement(IASTSwitchStatement switchStatement) { + writeAttributes(switchStatement, EnumSet.of(SpaceLocation.AFTER)); switchIsNew = true; scribe.print(SWITCH_BRACKET);