Search in sources :

Example 6 with Comment

use of org.eclipse.jdt.core.dom.Comment in project xtext-xtend by eclipse.

the class JavaASTFlattener method visit.

@Override
public boolean visit(final TypeDeclaration it) {
    boolean _isDummyType = this._aSTFlattenerUtils.isDummyType(it);
    if (_isDummyType) {
        this.visitAll(it.bodyDeclarations(), this.nl());
        return false;
    }
    boolean _isNotSupportedInnerType = this._aSTFlattenerUtils.isNotSupportedInnerType(it);
    if (_isNotSupportedInnerType) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("/* FIXME Non-static inner classes are not supported.*/");
        this.appendToBuffer(_builder.toString());
        this.addProblem(it, "Non-static inner classes are not supported.");
    }
    Javadoc _javadoc = it.getJavadoc();
    boolean _tripleNotEquals = (_javadoc != null);
    if (_tripleNotEquals) {
        it.getJavadoc().accept(this);
    }
    this.appendModifiers(it, it.modifiers());
    boolean _isInterface = it.isInterface();
    if (_isInterface) {
        this.appendToBuffer("interface ");
    } else {
        boolean _isPackageVisibility = this._aSTFlattenerUtils.isPackageVisibility(Iterables.<Modifier>filter(it.modifiers(), Modifier.class));
        if (_isPackageVisibility) {
            this.appendToBuffer("package ");
        }
        this.appendToBuffer("class ");
    }
    it.getName().accept(this);
    boolean _isEmpty = it.typeParameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        this.appendTypeParameters(it.typeParameters());
    }
    this.appendSpaceToBuffer();
    Type _superclassType = it.getSuperclassType();
    boolean _tripleNotEquals_1 = (_superclassType != null);
    if (_tripleNotEquals_1) {
        this.appendToBuffer("extends ");
        it.getSuperclassType().accept(this);
        this.appendSpaceToBuffer();
    }
    boolean _isEmpty_1 = it.superInterfaceTypes().isEmpty();
    boolean _not_1 = (!_isEmpty_1);
    if (_not_1) {
        boolean _isInterface_1 = it.isInterface();
        if (_isInterface_1) {
            this.appendToBuffer("extends ");
        } else {
            this.appendToBuffer("implements ");
        }
        this.visitAllSeparatedByComma(it.superInterfaceTypes());
    }
    this.appendToBuffer("{");
    this.increaseIndent();
    BodyDeclaration prev = null;
    List _bodyDeclarations = it.bodyDeclarations();
    for (final BodyDeclaration body : ((Iterable<BodyDeclaration>) _bodyDeclarations)) {
        {
            if ((prev instanceof EnumConstantDeclaration)) {
                if ((body instanceof EnumConstantDeclaration)) {
                    this.appendToBuffer(", ");
                } else {
                    this.appendToBuffer("; ");
                }
            }
            this.appendLineWrapToBuffer();
            body.accept(this);
            prev = body;
        }
    }
    ASTNode _root = it.getRoot();
    if ((_root instanceof CompilationUnit)) {
        ASTNode _root_1 = it.getRoot();
        final CompilationUnit cu = ((CompilationUnit) _root_1);
        final Consumer<Comment> _function = (Comment it_1) -> {
            it_1.accept(this);
            this.assignedComments.add(it_1);
        };
        this.unAssignedComments(cu).forEach(_function);
    }
    this.decreaseIndent();
    this.appendLineWrapToBuffer();
    this.appendToBuffer("}");
    return false;
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) EnumConstantDeclaration(org.eclipse.jdt.core.dom.EnumConstantDeclaration) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) LineComment(org.eclipse.jdt.core.dom.LineComment) ParameterizedType(org.eclipse.jdt.core.dom.ParameterizedType) WildcardType(org.eclipse.jdt.core.dom.WildcardType) QualifiedType(org.eclipse.jdt.core.dom.QualifiedType) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) ArrayType(org.eclipse.jdt.core.dom.ArrayType) SimpleType(org.eclipse.jdt.core.dom.SimpleType) Type(org.eclipse.jdt.core.dom.Type) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Javadoc(org.eclipse.jdt.core.dom.Javadoc) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) ArrayList(java.util.ArrayList) List(java.util.List) Modifier(org.eclipse.jdt.core.dom.Modifier) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Example 7 with Comment

use of org.eclipse.jdt.core.dom.Comment in project xtext-xtend by eclipse.

the class JavaASTFlattener method visit.

@Override
public boolean visit(final Block node) {
    this.appendToBuffer("{");
    this.increaseIndent();
    boolean _isEmpty = node.statements().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        final Procedure2<ASTNode, Integer> _function = (ASTNode child, Integer counter) -> {
            this.appendLineWrapToBuffer();
            child.accept(this);
        };
        IterableExtensions.<ASTNode>forEach(node.statements(), _function);
    }
    ASTNode _root = node.getRoot();
    if ((_root instanceof CompilationUnit)) {
        ASTNode _root_1 = node.getRoot();
        final CompilationUnit cu = ((CompilationUnit) _root_1);
        final Function1<Comment, Boolean> _function_1 = (Comment it) -> {
            int _startPosition = it.getStartPosition();
            int _startPosition_1 = node.getStartPosition();
            int _length = node.getLength();
            int _plus = (_startPosition_1 + _length);
            return Boolean.valueOf((_startPosition < _plus));
        };
        final Consumer<Comment> _function_2 = (Comment it) -> {
            if ((!(it instanceof LineComment))) {
                this.appendLineWrapToBuffer();
            }
            it.accept(this);
            this.assignedComments.add(it);
        };
        IterableExtensions.<Comment>filter(this.unAssignedComments(cu), _function_1).forEach(_function_2);
    }
    this.decreaseIndent();
    this.appendLineWrapToBuffer();
    this.appendToBuffer("}");
    return false;
}
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) ASTNode(org.eclipse.jdt.core.dom.ASTNode) LineComment(org.eclipse.jdt.core.dom.LineComment)

Example 8 with Comment

use of org.eclipse.jdt.core.dom.Comment 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;
}
Also used : SourceLocation(org.autorefactor.refactoring.SourceLocation) LineComment(org.eclipse.jdt.core.dom.LineComment) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) NotImplementedException(org.autorefactor.util.NotImplementedException) Javadoc(org.eclipse.jdt.core.dom.Javadoc) LineComment(org.eclipse.jdt.core.dom.LineComment)

Example 9 with Comment

use of org.eclipse.jdt.core.dom.Comment 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;
}
Also used : SourceLocation(org.autorefactor.refactoring.SourceLocation) LineComment(org.eclipse.jdt.core.dom.LineComment) Comment(org.eclipse.jdt.core.dom.Comment) BlockComment(org.eclipse.jdt.core.dom.BlockComment) LineComment(org.eclipse.jdt.core.dom.LineComment) Pair(org.autorefactor.util.Pair)

Example 10 with Comment

use of org.eclipse.jdt.core.dom.Comment in project AutoRefactor by JnRouvignac.

the class ASTCommentRewriter method addReplacementEdits.

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

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