Search in sources :

Example 11 with LineComment

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);
    }
}
Also used : SourceLocation(org.autorefactor.refactoring.SourceLocation) InsertEdit(org.eclipse.text.edits.InsertEdit) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) LineComment(org.eclipse.jdt.core.dom.LineComment)

Aggregations

LineComment (org.eclipse.jdt.core.dom.LineComment)11 Comment (org.eclipse.jdt.core.dom.Comment)6 BlockComment (org.eclipse.jdt.core.dom.BlockComment)5 NotImplementedException (org.autorefactor.util.NotImplementedException)4 InsertEdit (org.eclipse.text.edits.InsertEdit)4 ArrayList (java.util.ArrayList)3 SourceLocation (org.autorefactor.refactoring.SourceLocation)3 GvComment (com.randomnoun.build.javaToGraphviz.comment.GvComment)2 GvGraphComment (com.randomnoun.build.javaToGraphviz.comment.GvGraphComment)2 GvSubgraphComment (com.randomnoun.build.javaToGraphviz.comment.GvSubgraphComment)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 SourceLocation (org.autorefactor.jdt.internal.corext.dom.SourceLocation)2 Pair (org.autorefactor.util.Pair)2 Javadoc (org.eclipse.jdt.core.dom.Javadoc)2 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)2 CommentText (com.randomnoun.build.javaToGraphviz.comment.CommentText)1 GvEndGraphComment (com.randomnoun.build.javaToGraphviz.comment.GvEndGraphComment)1 GvEndSubgraphComment (com.randomnoun.build.javaToGraphviz.comment.GvEndSubgraphComment)1 GvKeepNodeComment (com.randomnoun.build.javaToGraphviz.comment.GvKeepNodeComment)1