use of org.eclipse.jdt.core.dom.Comment in project xtext-xtend by eclipse.
the class JavaASTFlattener method preVisit.
@Override
public void preVisit(final ASTNode node) {
if ((((node instanceof Comment) || (node instanceof TagElement)) || (node instanceof TextElement))) {
return;
}
ASTNode _root = node.getRoot();
if ((_root instanceof CompilationUnit)) {
ASTNode _root_1 = node.getRoot();
final CompilationUnit cu = ((CompilationUnit) _root_1);
final Function1<Comment, Boolean> _function = (Comment it) -> {
int _startPosition = it.getStartPosition();
int _startPosition_1 = node.getStartPosition();
return Boolean.valueOf((_startPosition < _startPosition_1));
};
final Consumer<Comment> _function_1 = (Comment it) -> {
it.accept(this);
this.assignedComments.add(it);
};
IterableExtensions.<Comment>filter(this.unAssignedComments(cu), _function).forEach(_function_1);
}
}
use of org.eclipse.jdt.core.dom.Comment in project AutoRefactor by JnRouvignac.
the class ASTCommentRewriter method addRemovalEdits.
private void addRemovalEdits(List<TextEdit> commentEdits, String source) {
if (this.removals.isEmpty()) {
return;
}
for (Comment node : this.removals) {
final int start = node.getStartPosition();
final int length = node.getLength();
// chomp from the end before the start variable gets modified
final int startToRemove = chompWhitespacesBefore(source, start);
final int endToRemove = chompWhitespacesAfter(source, start + length);
final int lengthToRemove = endToRemove - startToRemove;
commentEdits.add(new DeleteEdit(startToRemove, lengthToRemove));
}
}
use of org.eclipse.jdt.core.dom.Comment in project AutoRefactor by JnRouvignac.
the class RemoveSemiColonRefactoring method getNonCommentsStrings.
private Map<String, SourceLocation> getNonCommentsStrings(ASTNode node, int start, int end) {
final List<Comment> comments = filterCommentsInRange(start, end, node.getRoot());
final String source = ctx.getSource(node);
final LinkedHashMap<String, SourceLocation> results = new LinkedHashMap<String, SourceLocation>();
if (comments.isEmpty()) {
putResult(source, start, end, results);
} else {
int nextStart = start;
for (Comment comment : comments) {
if (nextStart < comment.getStartPosition()) {
putResult(source, nextStart, comment.getStartPosition(), results);
}
nextStart = getEndPosition(comment);
}
}
return results;
}
use of org.eclipse.jdt.core.dom.Comment in project AutoRefactor by JnRouvignac.
the class RemoveSemiColonRefactoring method filterCommentsInRange.
private List<Comment> filterCommentsInRange(int start, int end, List<Comment> commentList) {
if (commentList.isEmpty()) {
return Collections.emptyList();
}
final List<Comment> comments = new ArrayList<Comment>(commentList);
Collections.sort(comments, new NodeStartPositionComparator());
final Iterator<Comment> it = comments.iterator();
while (it.hasNext()) {
final Comment comment = it.next();
if (comment.getStartPosition() < start || getEndPosition(comment) > end) {
it.remove();
}
}
return comments;
}
use of org.eclipse.jdt.core.dom.Comment in project compiler by boalang.
the class UglyMathCommentsExtractor method extractCommentItem.
private final CommentItem extractCommentItem(final int index) {
if (commentsVisited[index]) {
return null;
} else {
final Comment comment = (Comment) comments.get(index);
if (comment.isDocComment()) {
/* Interpret DocComment as Line or Block */
comment.delete();
}
final int start = comment.getStartPosition();
final int end = start + comment.getLength();
final String value = this.src.substring(start, end);
return new CommentItem(comment, value);
}
}
Aggregations