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;
}
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, "*"));
}
}
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;
}
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;
}
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, "*"));
}
}
Aggregations