final List<ASTModification> modifications = getModifications(node, ModificationKind.APPEND_CHILD);
if (modifications.isEmpty()) {
return;
}
IASTNode prevNode = null;
final IASTDeclaration[] declarations = node.getDeclarations();
if (declarations.length != 0) {
prevNode = declarations[declarations.length - 1];
} else {
final IASTPreprocessorStatement[] preprocessorStatements = node.getAllPreprocessorStatements();
if (preprocessorStatements.length != 0) {
prevNode = preprocessorStatements[preprocessorStatements.length - 1];
}
}
final int offset = prevNode != null ? getEndOffsetIncludingComments(prevNode) : 0;
final String source = node.getRawSignature();
final int endOffset = skipTrailingBlankLines(source, offset);
addToRootEdit(node);
final ChangeGeneratorWriterVisitor writer = new ChangeGeneratorWriterVisitor(modificationStore, commentMap);
IASTNode newNode = null;
for (final ASTModification modification : modifications) {
final boolean first = newNode == null;
newNode = modification.getNewNode();
if (first) {
if (prevNode != null) {
writer.newLine();
if (ASTWriter.requireBlankLineInBetween(prevNode, newNode)) {
writer.newLine();
}
}
}
newNode.accept(writer);
// TODO(sprigogin): Temporary workaround for invalid handling of line breaks in
// StatementWriter
if (!writer.toString().endsWith("\n")) {
writer.newLine();
}
}
if (prevNode != null) {
final IASTNode nextNode = getNextSiblingOrPreprocessorNode(prevNode);
if ((nextNode != null) && ASTWriter.requireBlankLineInBetween(newNode, nextNode)) {
writer.newLine();
}
}