use of org.eclipse.jdt.core.dom.LineComment in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method replaceLineCommentAfterJavaElement.
private void replaceLineCommentAfterJavaElement(List<TextEdit> commentEdits, LineComment lineComment, List<LineComment> lineComments, int i, String source, TreeSet<Integer> lineStarts) {
if (i - 1 < 0) {
throw new NotImplementedException(lineComment, "for a line comment situated after the java elements that it documents," + " and this line comment is not the last line comment to add to the javadoc.");
}
final LineComment previousLineComment = lineComments.get(i - 1);
final int position = getEndPosition(previousLineComment);
final String indent = getIndentForJavadoc(previousLineComment, source, lineStarts).substring(source);
final StringBuilder newJavadoc = new StringBuilder().append(lineSeparator).append(indent).append(" *");
appendCommentTextReplaceEndsOfBlockComment(newJavadoc, lineComment, source);
newJavadoc.append(lineSeparator).append(indent).append(" */");
commentEdits.add(new InsertEdit(position, newJavadoc.toString()));
deleteLineCommentAfterNode(commentEdits, source, lineComment);
}
use of org.eclipse.jdt.core.dom.LineComment 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.LineComment in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method addSingleLineCommentToJavadocEdits.
private void addSingleLineCommentToJavadocEdits(final List<TextEdit> commentEdits, final ASTNode nextNode, final List<LineComment> lineComments, final String source, final TreeSet<Integer> lineStarts) {
int nodeStart = nextNode.getStartPosition();
LineComment lineComment = lineComments.get(0);
// TODO JNR how to obey configured indentation?
// TODO JNR how to obey configured line length?
int commentStart = lineComment.getStartPosition();
if (commentStart < nodeStart) {
// Assume comment is situated exactly before target node for javadoc
String spaceAtStart = getSpaceAtStart(source, lineComment);
// $NON-NLS-1$ //$NON-NLS-2$
commentEdits.add(new ReplaceEdit(commentStart, "//".length(), "/**" + spaceAtStart));
// $NON-NLS-1$
commentEdits.add(new InsertEdit(SourceLocation.getEndPosition(lineComment), getSpaceAtEnd(source, lineComment) + "*/"));
replaceEndsOfBlockCommentFromCommentText(commentEdits, lineComment, source);
} else {
// Assume comment is situated exactly after target node for javadoc
// $NON-NLS-1$
StringBuilder newJavadoc = new StringBuilder("/**").append(getSpaceAtStart(source, lineComment));
appendCommentTextReplaceEndsOfBlockComment(newJavadoc, lineComment, source);
SourceLocation indent = getIndent(nextNode, lineStarts);
// $NON-NLS-1$
newJavadoc.append(getSpaceAtEnd(source, lineComment)).append("*/").append(lineSeparator).append(// $NON-NLS-1$
source, indent.getStartPosition(), indent.getEndPosition());
commentEdits.add(new InsertEdit(nodeStart, newJavadoc.toString()));
deleteLineCommentAfterNode(commentEdits, source, lineComment);
}
}
use of org.eclipse.jdt.core.dom.LineComment in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method replaceLineCommentAfterJavaElement.
private void replaceLineCommentAfterJavaElement(final List<TextEdit> commentEdits, final LineComment lineComment, final List<LineComment> lineComments, final int i, final String source, final TreeSet<Integer> lineStarts) {
if (i - 1 < 0) {
throw new NotImplementedException(lineComment, // $NON-NLS-1$
"for a line comment situated after the java elements that it documents," + // $NON-NLS-1$
" and this line comment is not the last line comment to add to the javadoc.");
}
LineComment previousLineComment = lineComments.get(i - 1);
int position = SourceLocation.getEndPosition(previousLineComment);
String indent = getIndentForJavadoc(previousLineComment, source, lineStarts).substring(source);
// $NON-NLS-1$
StringBuilder newJavadoc = new StringBuilder(lineSeparator).append(indent).append(" *");
appendCommentTextReplaceEndsOfBlockComment(newJavadoc, lineComment, source);
// $NON-NLS-1$
newJavadoc.append(lineSeparator).append(indent).append(" */");
commentEdits.add(new InsertEdit(position, newJavadoc.toString()));
deleteLineCommentAfterNode(commentEdits, source, lineComment);
}
use of org.eclipse.jdt.core.dom.LineComment 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;
}
Aggregations