Search in sources :

Example 1 with BlockComment

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

the class CommentsCleanUp method visit.

@Override
public boolean visit(final CompilationUnit visited) {
    comments.clear();
    this.astRoot = visited;
    for (Comment comment : (List<Comment>) astRoot.getCommentList()) {
        comments.add(Pair.of(new SourceLocation(comment), comment));
    }
    for (Comment comment : (List<Comment>) astRoot.getCommentList()) {
        if (comment.isBlockComment()) {
            BlockComment bc = (BlockComment) comment;
            bc.accept(this);
        } else if (comment.isLineComment()) {
            LineComment lc = (LineComment) comment;
            lc.accept(this);
        } else if (comment.isDocComment()) {
            Javadoc jc = (Javadoc) comment;
            jc.accept(this);
        } else {
            throw new NotImplementedException(comment);
        }
    }
    return true;
}
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) BlockComment(org.eclipse.jdt.core.dom.BlockComment) NotImplementedException(org.autorefactor.util.NotImplementedException) Javadoc(org.eclipse.jdt.core.dom.Javadoc) ArrayList(java.util.ArrayList) List(java.util.List) LineComment(org.eclipse.jdt.core.dom.LineComment)

Example 2 with BlockComment

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

the class ASTCommentRewriter method addBlockCommentToJavadocEdits.

private void addBlockCommentToJavadocEdits(final List<TextEdit> commentEdits) {
    for (BlockComment blockComment : this.blockCommentToJavadoc) {
        // $NON-NLS-1$
        int offset = blockComment.getStartPosition() + "/*".length();
        // $NON-NLS-1$
        commentEdits.add(new InsertEdit(offset, "*"));
    }
}
Also used : BlockComment(org.eclipse.jdt.core.dom.BlockComment) InsertEdit(org.eclipse.text.edits.InsertEdit)

Example 3 with BlockComment

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

the class CommentsRefactoring method visit.

@Override
public boolean visit(CompilationUnit node) {
    this.astRoot = node;
    for (Comment comment : getCommentList(astRoot)) {
        comments.add(Pair.of(new SourceLocation(comment), comment));
    }
    for (Comment comment : getCommentList(astRoot)) {
        if (comment.isBlockComment()) {
            final BlockComment bc = (BlockComment) comment;
            bc.accept(this);
        } else if (comment.isLineComment()) {
            final LineComment lc = (LineComment) comment;
            lc.accept(this);
        } else if (comment.isDocComment()) {
            final Javadoc jc = (Javadoc) comment;
            jc.accept(this);
        } else {
            throw new NotImplementedException(comment);
        }
    }
    return VISIT_SUBTREE;
}
Also used : SourceLocation(org.autorefactor.refactoring.SourceLocation) LineComment(org.eclipse.jdt.core.dom.LineComment) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) NotImplementedException(org.autorefactor.util.NotImplementedException) Javadoc(org.eclipse.jdt.core.dom.Javadoc) LineComment(org.eclipse.jdt.core.dom.LineComment)

Example 4 with BlockComment

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

the class CommentsRefactoring method betterCommentExist.

private boolean betterCommentExist(Comment comment, ASTNode nodeWhereToAddJavadoc) {
    if (hasJavadoc(nodeWhereToAddJavadoc)) {
        return true;
    }
    final SourceLocation nodeLoc = new SourceLocation(nodeWhereToAddJavadoc);
    SourceLocation bestLoc = new SourceLocation(comment);
    Comment bestComment = comment;
    for (Iterator<Pair<SourceLocation, Comment>> iter = this.comments.iterator(); iter.hasNext(); ) {
        final Pair<SourceLocation, Comment> pair = iter.next();
        final SourceLocation newLoc = pair.getFirst();
        final 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) {
            if (!(newComment instanceof LineComment)) {
                // new comment is a BlockComment or a Javadoc
                bestLoc = newLoc;
                bestComment = newComment;
                continue;
            } else if (!(bestComment instanceof LineComment)) {
                // new comment is a line comment and best comment is not
                bestLoc = newLoc;
                bestComment = newComment;
                continue;
            }
        }
    }
    return bestComment != null && bestComment != comment;
}
Also used : SourceLocation(org.autorefactor.refactoring.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)

Example 5 with BlockComment

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

the class ASTCommentRewriter method addBlockCommentToJavadocEdits.

private void addBlockCommentToJavadocEdits(List<TextEdit> commentEdits) {
    for (BlockComment blockComment : this.blockCommentToJavadoc) {
        final int offset = blockComment.getStartPosition() + "/*".length();
        commentEdits.add(new InsertEdit(offset, "*"));
    }
}
Also used : BlockComment(org.eclipse.jdt.core.dom.BlockComment) InsertEdit(org.eclipse.text.edits.InsertEdit)

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