public int compare(Object o1, Object o2) { return ((Comment) o1).getStartPosition() - ((Comment) o2).getStartPosition(); } });
public int compare(Object o1, Object o2) { return ((Comment) o1).getStartPosition() - ((Comment) o2).getStartPosition(); } });
private String commentContent(final Comment comment) { int _startPosition = comment.getStartPosition(); int _startPosition_1 = comment.getStartPosition(); int _length = comment.getLength(); int _plus = (_startPosition_1 + _length); return this.javaSources.substring(_startPosition, _plus); }
boolean isInComment(int position) { for (Comment comment : getCommentList(astRoot)) { if (comment.getStartPosition() <= position && position <= getEndPosition(comment)) { return true; } else if (position < comment.getStartPosition()) { // since comment list is "arranged in order of increasing source position" // it is impossible for this position to be surrounded by a comment return false; } } return false; }
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; }
/** * Returns the extended start position of the given node. Unlike * {@link ASTNode#getStartPosition()} and {@link ASTNode#getLength()}, * the extended source range may include comments and whitespace * immediately before or after the normal source range for the node. * * @param node the node * @return the 0-based character index, or <code>-1</code> * if no source position information is recorded for this node * @see #getExtendedLength(ASTNode) * @since 3.0 */ public int getExtendedStartPosition(ASTNode node) { if (this.leadingPtr >= 0) { long range = -1; for (int i=0; range<0 && i<=this.leadingPtr; i++) { if (this.leadingNodes[i] == node) range = this.leadingIndexes[i]; } if (range >= 0) { return this.comments[(int)(range>>32)].getStartPosition() ; } } return node.getStartPosition(); }
/** * Returns the extended start position of the given node. Unlike * {@link ASTNode#getStartPosition()} and {@link ASTNode#getLength()}, * the extended source range may include comments and whitespace * immediately before or after the normal source range for the node. * * @param node the node * @return the 0-based character index, or <code>-1</code> * if no source position information is recorded for this node * @see #getExtendedLength(ASTNode) * @since 3.0 */ public int getExtendedStartPosition(ASTNode node) { if (this.leadingPtr >= 0) { long range = -1; for (int i=0; range<0 && i<=this.leadingPtr; i++) { if (this.leadingNodes[i] == node) range = this.leadingIndexes[i]; } if (range >= 0) { return this.comments[(int)(range>>32)].getStartPosition() ; } } return node.getStartPosition(); }
private String getComment(Comment node) { final String source = this.ctx.getSource(node); final int start = node.getStartPosition(); return source.substring(start, start + node.getLength()); } }
private void addReplacementEdits(List<TextEdit> commentEdits) { if (this.replacements.isEmpty()) { return; } for (Pair<Comment, String> pair : this.replacements) { final Comment node = pair.getFirst(); final int start = node.getStartPosition(); final int length = node.getLength(); commentEdits.add(new ReplaceEdit(start, length, pair.getSecond())); } }
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)); } }
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; }
private ASTNode getCoveringNode(Comment node) { final int start = node.getStartPosition(); final int length = node.getLength(); final ASTNode coveringNode = getCoveringNode(start, length); if (coveringNode != node) { return coveringNode; } return getCoveringNode(start, length + 1); }
public int getExtendedEnd(ASTNode node) { int end = node.getStartPosition() + node.getLength(); if (this.trailingPtr >= 0) { long range = -1; for (int i=0; range<0 && i<=this.trailingPtr; i++) { if (this.trailingNodes[i] == node) range = this.trailingIndexes[i]; } if (range >= 0) { Comment lastComment = this.comments[(int) range]; end = lastComment.getStartPosition() + lastComment.getLength(); } } return end-1; }
public int getExtendedEnd(ASTNode node) { int end = node.getStartPosition() + node.getLength(); if (this.trailingPtr >= 0) { long range = -1; for (int i=0; range<0 && i<=this.trailingPtr; i++) { if (this.trailingNodes[i] == node) range = this.trailingIndexes[i]; } if (range >= 0) { Comment lastComment = this.comments[(int) range]; end = lastComment.getStartPosition() + lastComment.getLength(); } } return end-1; }
public int getExtendedEnd(ASTNode node) { int end = node.getStartPosition() + node.getLength(); if (this.trailingPtr >= 0) { long range = -1; for (int i=0; range<0 && i<=this.trailingPtr; i++) { if (this.trailingNodes[i] == node) range = this.trailingIndexes[i]; } if (range >= 0) { Comment lastComment = this.comments[(int) range]; end = lastComment.getStartPosition() + lastComment.getLength(); } } return end-1; }
public int getExtendedEnd(ASTNode node) { int end = node.getStartPosition() + node.getLength(); if (this.trailingPtr >= 0) { long range = -1; for (int i=0; range<0 && i<=this.trailingPtr; i++) { if (this.trailingNodes[i] == node) range = this.trailingIndexes[i]; } if (range >= 0) { Comment lastComment = this.comments[(int) range]; end = lastComment.getStartPosition() + lastComment.getLength(); } } return end-1; }
public int getExtendedEnd(ASTNode node) { int end = node.getStartPosition() + node.getLength(); if (this.trailingPtr >= 0) { long range = -1; for (int i=0; range<0 && i<=this.trailingPtr; i++) { if (this.trailingNodes[i] == node) range = this.trailingIndexes[i]; } if (range >= 0) { Comment lastComment = this.comments[(int) range]; end = lastComment.getStartPosition() + lastComment.getLength(); } } return end-1; }
public int getExtendedEnd(ASTNode node) { int end = node.getStartPosition() + node.getLength(); if (this.trailingPtr >= 0) { long range = -1; for (int i=0; range<0 && i<=this.trailingPtr; i++) { if (this.trailingNodes[i] == node) range = this.trailingIndexes[i]; } if (range >= 0) { Comment lastComment = this.comments[(int) range]; end = lastComment.getStartPosition() + lastComment.getLength(); } } return end-1; }
@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); } }
private ASTNode getNextNode(Comment node) { final int nodeEndPosition = node.getStartPosition() + node.getLength(); final ASTNode coveringNode = getCoveringNode(node); final int parentNodeEndPosition = coveringNode.getStartPosition() + coveringNode.getLength(); final NodeFinder finder = new NodeFinder(coveringNode, nodeEndPosition, parentNodeEndPosition - nodeEndPosition); if (node instanceof Javadoc) { return finder.getCoveringNode(); } return finder.getCoveredNode(); }