use of org.eclipse.jdt.core.dom.LineComment in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method addSingleLineCommentToJavadocEdits.
private void addSingleLineCommentToJavadocEdits(List<TextEdit> commentEdits, ASTNode nextNode, List<LineComment> lineComments, String source, TreeSet<Integer> lineStarts) {
final int nodeStart = nextNode.getStartPosition();
final LineComment lineComment = lineComments.get(0);
// TODO JNR how to obey configured indentation?
// TODO JNR how to obey configured line length?
final int commentStart = lineComment.getStartPosition();
if (commentStart < nodeStart) {
// assume comment is situated exactly before target node for javadoc
final String spaceAtStart = getSpaceAtStart(source, lineComment);
commentEdits.add(new ReplaceEdit(commentStart, "//".length(), "/**" + spaceAtStart));
commentEdits.add(new InsertEdit(getEndPosition(lineComment), getSpaceAtEnd(source, lineComment) + "*/"));
replaceEndsOfBlockCommentFromCommentText(commentEdits, lineComment, source);
} else {
// assume comment is situated exactly after target node for javadoc
final StringBuilder newJavadoc = new StringBuilder().append("/**").append(getSpaceAtStart(source, lineComment));
appendCommentTextReplaceEndsOfBlockComment(newJavadoc, lineComment, source);
SourceLocation indent = getIndent(nextNode, lineStarts);
newJavadoc.append(getSpaceAtEnd(source, lineComment)).append("*/").append(lineSeparator).append(source, indent.getStartPosition(), indent.getEndPosition());
commentEdits.add(new InsertEdit(nodeStart, newJavadoc.toString()));
deleteLineCommentAfterNode(commentEdits, source, lineComment);
}
}
Aggregations