Search in sources :

Example 1 with Comment

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);
    }
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) LineComment(org.eclipse.jdt.core.dom.LineComment) TextElement(org.eclipse.jdt.core.dom.TextElement) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TagElement(org.eclipse.jdt.core.dom.TagElement)

Example 2 with Comment

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));
    }
}
Also used : LineComment(org.eclipse.jdt.core.dom.LineComment) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) DeleteEdit(org.eclipse.text.edits.DeleteEdit)

Example 3 with Comment

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;
}
Also used : SourceLocation(org.autorefactor.refactoring.SourceLocation) Comment(org.eclipse.jdt.core.dom.Comment) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with Comment

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;
}
Also used : Comment(org.eclipse.jdt.core.dom.Comment) ArrayList(java.util.ArrayList) NodeStartPositionComparator(org.autorefactor.refactoring.ASTHelper.NodeStartPositionComparator)

Example 5 with Comment

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);
    }
}
Also used : Comment(org.eclipse.jdt.core.dom.Comment)

Aggregations

Comment (org.eclipse.jdt.core.dom.Comment)10 BlockComment (org.eclipse.jdt.core.dom.BlockComment)7 LineComment (org.eclipse.jdt.core.dom.LineComment)7 SourceLocation (org.autorefactor.refactoring.SourceLocation)3 ASTNode (org.eclipse.jdt.core.dom.ASTNode)3 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)3 ArrayList (java.util.ArrayList)2 Javadoc (org.eclipse.jdt.core.dom.Javadoc)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 NodeStartPositionComparator (org.autorefactor.refactoring.ASTHelper.NodeStartPositionComparator)1 NotImplementedException (org.autorefactor.util.NotImplementedException)1 Pair (org.autorefactor.util.Pair)1 ArrayType (org.eclipse.jdt.core.dom.ArrayType)1 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)1 EnumConstantDeclaration (org.eclipse.jdt.core.dom.EnumConstantDeclaration)1 IExtendedModifier (org.eclipse.jdt.core.dom.IExtendedModifier)1 Modifier (org.eclipse.jdt.core.dom.Modifier)1 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)1 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)1