mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 03:53:21 +02:00
Fixed handling of trailing comments after compound statements.
This commit is contained in:
parent
3453fa6fcd
commit
476364f0a6
3 changed files with 21 additions and 31 deletions
|
@ -8,6 +8,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
package org.eclipse.cdt.internal.core.dom.rewrite.astwriter;
|
||||||
|
|
||||||
|
@ -90,30 +91,24 @@ public class StatementWriter extends NodeWriter {
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTExpressionStatement) {
|
} else if (statement instanceof IASTExpressionStatement) {
|
||||||
writeExpressionStatement((IASTExpressionStatement) statement);
|
writeExpressionStatement((IASTExpressionStatement) statement);
|
||||||
//usually newLine
|
|
||||||
} else if (statement instanceof IASTDeclarationStatement) {
|
} else if (statement instanceof IASTDeclarationStatement) {
|
||||||
writeDeclarationStatement((IASTDeclarationStatement) statement);
|
writeDeclarationStatement((IASTDeclarationStatement) statement);
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTNullStatement) {
|
} else if (statement instanceof IASTNullStatement) {
|
||||||
writeNullStatement((IASTNullStatement)statement);
|
writeNullStatement((IASTNullStatement)statement);
|
||||||
// usually newLine
|
|
||||||
} else if (statement instanceof IASTReturnStatement) {
|
} else if (statement instanceof IASTReturnStatement) {
|
||||||
writeReturnStatement((IASTReturnStatement)statement);
|
writeReturnStatement((IASTReturnStatement)statement);
|
||||||
// usually newLine
|
|
||||||
} else if (statement instanceof IASTGotoStatement) {
|
} else if (statement instanceof IASTGotoStatement) {
|
||||||
writeGotoStatement((IASTGotoStatement) statement);
|
writeGotoStatement((IASTGotoStatement) statement);
|
||||||
// usually newLine
|
|
||||||
} else if (statement instanceof IASTLabelStatement) {
|
} else if (statement instanceof IASTLabelStatement) {
|
||||||
writeLabelStatement((IASTLabelStatement) statement);
|
writeLabelStatement((IASTLabelStatement) statement);
|
||||||
newLine = false;
|
newLine = false;
|
||||||
} else if (statement instanceof IASTCaseStatement) {
|
} else if (statement instanceof IASTCaseStatement) {
|
||||||
writeCaseStatement((IASTCaseStatement) statement);
|
writeCaseStatement((IASTCaseStatement) statement);
|
||||||
// usually newLine
|
|
||||||
} else if (statement instanceof IASTDefaultStatement) {
|
} else if (statement instanceof IASTDefaultStatement) {
|
||||||
writeDefaultStatement((IASTDefaultStatement)statement);
|
writeDefaultStatement((IASTDefaultStatement)statement);
|
||||||
} else if (statement instanceof IASTContinueStatement) {
|
} else if (statement instanceof IASTContinueStatement) {
|
||||||
writeContinueStatement((IASTContinueStatement)statement);
|
writeContinueStatement((IASTContinueStatement)statement);
|
||||||
// usually newLine
|
|
||||||
} else if (statement instanceof IASTCompoundStatement) {
|
} else if (statement instanceof IASTCompoundStatement) {
|
||||||
writeCompoundStatement((IASTCompoundStatement) statement);
|
writeCompoundStatement((IASTCompoundStatement) statement);
|
||||||
if (compoundNoNewLine) {
|
if (compoundNoNewLine) {
|
||||||
|
@ -122,7 +117,6 @@ public class StatementWriter extends NodeWriter {
|
||||||
}
|
}
|
||||||
} else if (statement instanceof IASTBreakStatement) {
|
} else if (statement instanceof IASTBreakStatement) {
|
||||||
writeBreakStatement((IASTBreakStatement) statement);
|
writeBreakStatement((IASTBreakStatement) statement);
|
||||||
// usually newLine
|
|
||||||
} else if (statement instanceof IASTSwitchStatement) {
|
} else if (statement instanceof IASTSwitchStatement) {
|
||||||
writeSwitchStatement((IASTSwitchStatement) statement);
|
writeSwitchStatement((IASTSwitchStatement) statement);
|
||||||
newLine = false;
|
newLine = false;
|
||||||
|
@ -160,7 +154,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
|
|
||||||
scribe.print(DO);
|
scribe.print(DO);
|
||||||
writeBodyStatement(doStatement.getBody(), true);
|
writeBodyStatement(doStatement.getBody(), false);
|
||||||
scribe.print(DO_WHILE);
|
scribe.print(DO_WHILE);
|
||||||
doStatement.getCondition().accept(visitor);
|
doStatement.getCondition().accept(visitor);
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
|
@ -191,7 +185,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
writeBodyStatement(forStatement.getBody(), false);
|
writeBodyStatement(forStatement.getBody(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeForStatement(ICPPASTRangeBasedForStatement forStatment) {
|
private void writeForStatement(ICPPASTRangeBasedForStatement forStatment) {
|
||||||
|
@ -203,7 +197,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
writeBodyStatement(forStatment.getBody(), false);
|
writeBodyStatement(forStatment.getBody(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeIfStatement(IASTIfStatement ifStatement) {
|
private void writeIfStatement(IASTIfStatement ifStatement) {
|
||||||
|
@ -225,7 +219,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
IASTStatement elseClause = ifStatement.getElseClause();
|
IASTStatement elseClause = ifStatement.getElseClause();
|
||||||
writeBodyStatement(ifStatement.getThenClause(), elseClause != null);
|
writeBodyStatement(ifStatement.getThenClause(), elseClause == null);
|
||||||
|
|
||||||
if (elseClause != null) {
|
if (elseClause != null) {
|
||||||
scribe.print(ELSE);
|
scribe.print(ELSE);
|
||||||
|
@ -297,7 +291,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
}
|
}
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
writeBodyStatement(catchStatement.getCatchBody(), true);
|
writeBodyStatement(catchStatement.getCatchBody(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeTryBlockStatement(ICPPASTTryBlockStatement tryStatement) {
|
private void writeTryBlockStatement(ICPPASTTryBlockStatement tryStatement) {
|
||||||
|
@ -324,7 +318,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
writeBodyStatement(whileStatment.getBody(), false);
|
writeBodyStatement(whileStatment.getBody(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeCaseStatement(IASTCaseStatement caseStatement) {
|
private void writeCaseStatement(IASTCaseStatement caseStatement) {
|
||||||
|
@ -358,7 +352,7 @@ public class StatementWriter extends NodeWriter {
|
||||||
scribe.print(')');
|
scribe.print(')');
|
||||||
scribe.newLines();
|
scribe.newLines();
|
||||||
nextCompoundNoNewLine();
|
nextCompoundNoNewLine();
|
||||||
writeBodyStatement(switchStatement.getBody(), false);
|
writeBodyStatement(switchStatement.getBody(), true);
|
||||||
|
|
||||||
switchIsNew = false;
|
switchIsNew = false;
|
||||||
}
|
}
|
||||||
|
@ -396,12 +390,10 @@ public class StatementWriter extends NodeWriter {
|
||||||
return compoundStatement.getStatements();
|
return compoundStatement.getStatements();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(sprigogin): Rename second parameter
|
protected void writeBodyStatement(IASTStatement statement, boolean newLineForCompound) {
|
||||||
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
|
|
||||||
if (statement instanceof IASTCompoundStatement) {
|
if (statement instanceof IASTCompoundStatement) {
|
||||||
//TODO hsr existiert noch eine methode
|
writeCompoundStatement((IASTCompoundStatement) statement);
|
||||||
statement.accept(visitor);
|
if (newLineForCompound) {
|
||||||
if (!isDoStatement) {
|
|
||||||
scribe.newLine();
|
scribe.newLine();
|
||||||
}
|
}
|
||||||
compoundNoNewLine = false;
|
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() {
|
protected void nextCompoundNoNewLine() {
|
||||||
compoundNoNewLine = true;
|
compoundNoNewLine = true;
|
||||||
|
|
|
@ -28,9 +28,9 @@ public class ModifiedASTStatementWriter extends StatementWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeBodyStatement(IASTStatement statement, boolean isDoStatement) {
|
protected void writeBodyStatement(IASTStatement statement, boolean newLineForCompound) {
|
||||||
IASTStatement replacementNode = modificationHelper.getNodeAfterReplacement(statement);
|
IASTStatement replacementNode = modificationHelper.getNodeAfterReplacement(statement);
|
||||||
super.writeBodyStatement(replacementNode, isDoStatement);
|
super.writeBodyStatement(replacementNode, newLineForCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2446,8 +2446,7 @@ public class ToogleRefactoringTest extends RefactoringTestBase {
|
||||||
// return;
|
// return;
|
||||||
//}
|
//}
|
||||||
//catch (int e) {
|
//catch (int e) {
|
||||||
//}
|
//} // Trailing comment
|
||||||
//// Trailing comment
|
|
||||||
public void testClassToHeaderTrailingCommentWithTryBlock() throws Exception {
|
public void testClassToHeaderTrailingCommentWithTryBlock() throws Exception {
|
||||||
assertRefactoringSuccess();
|
assertRefactoringSuccess();
|
||||||
}
|
}
|
||||||
|
@ -2474,11 +2473,10 @@ public class ToogleRefactoringTest extends RefactoringTestBase {
|
||||||
//} /* one */
|
//} /* one */
|
||||||
//catch (int i) {
|
//catch (int i) {
|
||||||
// // zwaa
|
// // zwaa
|
||||||
//}
|
//} /* two */
|
||||||
///* two */catch (int j) {
|
//catch (int j) {
|
||||||
// // draa
|
// // draa
|
||||||
//}
|
//} /* three */
|
||||||
///* three */
|
|
||||||
public void testClassToHeaderTrailingMultipleCommentsInTryBlock() throws Exception {
|
public void testClassToHeaderTrailingMultipleCommentsInTryBlock() throws Exception {
|
||||||
assertRefactoringSuccess();
|
assertRefactoringSuccess();
|
||||||
}
|
}
|
||||||
|
@ -2810,8 +2808,8 @@ public class ToogleRefactoringTest extends RefactoringTestBase {
|
||||||
// } /*1*/
|
// } /*1*/
|
||||||
// catch (int e) {
|
// catch (int e) {
|
||||||
// /*2*/
|
// /*2*/
|
||||||
// }
|
// } /*3*/
|
||||||
// /*3*/catch (int e) {
|
// catch (int e) {
|
||||||
// /*4*/
|
// /*4*/
|
||||||
// }
|
// }
|
||||||
//};
|
//};
|
||||||
|
|
Loading…
Add table
Reference in a new issue