Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-02-15 19:21:26 -0500
committerSergey Prigogin2012-02-15 19:21:26 -0500
commit476364f0a673d4a6245eac39661e0ad6cfdcacbe (patch)
treec0eaad5994efc44180cdad4bb7b4b66942aca2bc /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite
parent3453fa6fcd43800486c8d8c95e429f49d4121459 (diff)
downloadorg.eclipse.cdt-476364f0a673d4a6245eac39661e0ad6cfdcacbe.tar.gz
org.eclipse.cdt-476364f0a673d4a6245eac39661e0ad6cfdcacbe.tar.xz
org.eclipse.cdt-476364f0a673d4a6245eac39661e0ad6cfdcacbe.zip
Fixed handling of trailing comments after compound statements.
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/astwriter/StatementWriter.java32
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTStatementWriter.java6
2 files changed, 15 insertions, 23 deletions
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 a7c9580bec..20ea85f420 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
@@ -8,6 +8,7 @@
*
* Contributors:
* Institute for Software - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
@@ -90,30 +91,24 @@ public class StatementWriter extends NodeWriter {
newLine = false;
} else if (statement instanceof IASTExpressionStatement) {
writeExpressionStatement((IASTExpressionStatement) statement);
- //usually newLine
} else if (statement instanceof IASTDeclarationStatement) {
writeDeclarationStatement((IASTDeclarationStatement) statement);
newLine = false;
} else if (statement instanceof IASTNullStatement) {
writeNullStatement((IASTNullStatement)statement);
-// usually newLine
} else if (statement instanceof IASTReturnStatement) {
writeReturnStatement((IASTReturnStatement)statement);
-// usually newLine
} else if (statement instanceof IASTGotoStatement) {
writeGotoStatement((IASTGotoStatement) statement);
-// usually newLine
} else if (statement instanceof IASTLabelStatement) {
writeLabelStatement((IASTLabelStatement) statement);
newLine = false;
} else if (statement instanceof IASTCaseStatement) {
writeCaseStatement((IASTCaseStatement) statement);
-// usually newLine
} else if (statement instanceof IASTDefaultStatement) {
writeDefaultStatement((IASTDefaultStatement)statement);
} else if (statement instanceof IASTContinueStatement) {
writeContinueStatement((IASTContinueStatement)statement);
-// usually newLine
} else if (statement instanceof IASTCompoundStatement) {
writeCompoundStatement((IASTCompoundStatement) statement);
if (compoundNoNewLine) {
@@ -122,7 +117,6 @@ public class StatementWriter extends NodeWriter {
}
} else if (statement instanceof IASTBreakStatement) {
writeBreakStatement((IASTBreakStatement) statement);
-// usually newLine
} else if (statement instanceof IASTSwitchStatement) {
writeSwitchStatement((IASTSwitchStatement) statement);
newLine = false;
@@ -160,7 +154,7 @@ public class StatementWriter extends NodeWriter {
nextCompoundNoNewLine();
scribe.print(DO);
- writeBodyStatement(doStatement.getBody(), true);
+ writeBodyStatement(doStatement.getBody(), false);
scribe.print(DO_WHILE);
doStatement.getCondition().accept(visitor);
scribe.print(')');
@@ -191,7 +185,7 @@ public class StatementWriter extends NodeWriter {
scribe.print(')');
scribe.newLines();
nextCompoundNoNewLine();
- writeBodyStatement(forStatement.getBody(), false);
+ writeBodyStatement(forStatement.getBody(), true);
}
private void writeForStatement(ICPPASTRangeBasedForStatement forStatment) {
@@ -203,7 +197,7 @@ public class StatementWriter extends NodeWriter {
scribe.print(')');
scribe.newLines();
nextCompoundNoNewLine();
- writeBodyStatement(forStatment.getBody(), false);
+ writeBodyStatement(forStatment.getBody(), true);
}
private void writeIfStatement(IASTIfStatement ifStatement) {
@@ -225,7 +219,7 @@ public class StatementWriter extends NodeWriter {
scribe.newLines();
nextCompoundNoNewLine();
IASTStatement elseClause = ifStatement.getElseClause();
- writeBodyStatement(ifStatement.getThenClause(), elseClause != null);
+ writeBodyStatement(ifStatement.getThenClause(), elseClause == null);
if (elseClause != null) {
scribe.print(ELSE);
@@ -297,7 +291,7 @@ public class StatementWriter extends NodeWriter {
scribe.newLines();
}
scribe.print(')');
- writeBodyStatement(catchStatement.getCatchBody(), true);
+ writeBodyStatement(catchStatement.getCatchBody(), false);
}
private void writeTryBlockStatement(ICPPASTTryBlockStatement tryStatement) {
@@ -324,7 +318,7 @@ public class StatementWriter extends NodeWriter {
scribe.print(')');
scribe.newLines();
nextCompoundNoNewLine();
- writeBodyStatement(whileStatment.getBody(), false);
+ writeBodyStatement(whileStatment.getBody(), true);
}
private void writeCaseStatement(IASTCaseStatement caseStatement) {
@@ -358,7 +352,7 @@ public class StatementWriter extends NodeWriter {
scribe.print(')');
scribe.newLines();
nextCompoundNoNewLine();
- writeBodyStatement(switchStatement.getBody(), false);
+ writeBodyStatement(switchStatement.getBody(), true);
switchIsNew = false;
}
@@ -396,12 +390,10 @@ public class StatementWriter extends NodeWriter {
return compoundStatement.getStatements();
}
- // TODO(sprigogin): Rename second parameter
- protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
+ protected void writeBodyStatement(IASTStatement statement, boolean newLineForCompound) {
if (statement instanceof IASTCompoundStatement) {
- //TODO hsr existiert noch eine methode
- statement.accept(visitor);
- if (!isDoStatement) {
+ writeCompoundStatement((IASTCompoundStatement) statement);
+ if (newLineForCompound) {
scribe.newLine();
}
compoundNoNewLine = false;
@@ -417,7 +409,7 @@ public class StatementWriter extends NodeWriter {
}
/**
- * Write no new Line after the next Compound-Statement
+ * Write no new Line after the next compound statement
*/
protected void nextCompoundNoNewLine() {
compoundNoNewLine = true;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTStatementWriter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTStatementWriter.java
index 9977fbbf7e..067f64d6ef 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTStatementWriter.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ModifiedASTStatementWriter.java
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * Institute for Software - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.rewrite.changegenerator;
@@ -28,9 +28,9 @@ public class ModifiedASTStatementWriter extends StatementWriter {
}
@Override
- protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
+ protected void writeBodyStatement(IASTStatement statement, boolean newLineForCompound) {
IASTStatement replacementNode = modificationHelper.getNodeAfterReplacement(statement);
- super.writeBodyStatement(replacementNode, isDoStatement);
+ super.writeBodyStatement(replacementNode, newLineForCompound);
}
@Override

Back to the top