Search in sources :

Example 6 with BlockComment

use of org.eclipse.jdt.core.dom.BlockComment in project AutoRefactor by JnRouvignac.

the class CommentsCleanUp method betterCommentExist.

private boolean betterCommentExist(final Comment comment, final ASTNode nodeWhereToAddJavadoc) {
    if (hasJavadoc(nodeWhereToAddJavadoc)) {
        return true;
    }
    SourceLocation nodeLoc = new SourceLocation(nodeWhereToAddJavadoc);
    SourceLocation bestLoc = new SourceLocation(comment);
    Comment bestComment = comment;
    for (Iterator<Pair<SourceLocation, Comment>> iter = this.comments.iterator(); iter.hasNext(); ) {
        Pair<SourceLocation, Comment> pair = iter.next();
        SourceLocation newLoc = pair.getFirst();
        Comment newComment = pair.getSecond();
        if (newLoc.compareTo(bestLoc) < 0) {
            // Since comments are visited in ascending order,
            // we can forget this comment.
            iter.remove();
            continue;
        }
        if (nodeLoc.compareTo(newLoc) < 0) {
            break;
        }
        if (bestLoc.compareTo(newLoc) < 0 && (!(newComment instanceof LineComment) || !(bestComment instanceof LineComment))) {
            // New comment is a BlockComment or a Javadoc
            bestLoc = newLoc;
            bestComment = newComment;
            continue;
        }
    }
    return bestComment != null && bestComment != comment;
}
Also used : SourceLocation(org.autorefactor.jdt.internal.corext.dom.SourceLocation) LineComment(org.eclipse.jdt.core.dom.LineComment) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) LineComment(org.eclipse.jdt.core.dom.LineComment) Pair(org.autorefactor.util.Pair)

Aggregations

BlockComment (org.eclipse.jdt.core.dom.BlockComment)6 Comment (org.eclipse.jdt.core.dom.Comment)4 LineComment (org.eclipse.jdt.core.dom.LineComment)4 SourceLocation (org.autorefactor.jdt.internal.corext.dom.SourceLocation)2 SourceLocation (org.autorefactor.refactoring.SourceLocation)2 NotImplementedException (org.autorefactor.util.NotImplementedException)2 Pair (org.autorefactor.util.Pair)2 Javadoc (org.eclipse.jdt.core.dom.Javadoc)2 InsertEdit (org.eclipse.text.edits.InsertEdit)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1