Search in sources :

Example 61 with TagElement

use of org.eclipse.jdt.core.dom.TagElement in project eclipse-cs by checkstyle.

the class MethodLimitQuickfix method handleGetCorrectingASTVisitor.

/**
 * {@inheritDoc}
 */
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) {
    return new ASTVisitor() {

        @SuppressWarnings("unchecked")
        public boolean visit(MethodDeclaration node) {
            Javadoc doc = node.getJavadoc();
            if (doc == null) {
                doc = node.getAST().newJavadoc();
                node.setJavadoc(doc);
            }
            TagElement newTag = node.getAST().newTagElement();
            newTag.setTagName("TODO Added by MethodLimit Sample quickfix");
            doc.tags().add(0, newTag);
            return true;
        }
    };
}
Also used : MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) Javadoc(org.eclipse.jdt.core.dom.Javadoc) TagElement(org.eclipse.jdt.core.dom.TagElement) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

Example 62 with TagElement

use of org.eclipse.jdt.core.dom.TagElement in project eclipse.jdt.ls by eclipse.

the class JavadocTagsSubProcessor method findTag.

public static TagElement findTag(Javadoc javadoc, String name, String arg) {
    List<TagElement> tags = javadoc.tags();
    int nTags = tags.size();
    for (int i = 0; i < nTags; i++) {
        TagElement curr = tags.get(i);
        if (name.equals(curr.getTagName())) {
            if (arg != null) {
                String argument = getArgument(curr);
                if (arg.equals(argument)) {
                    return curr;
                }
            } else {
                return curr;
            }
        }
    }
    return null;
}
Also used : TagElement(org.eclipse.jdt.core.dom.TagElement)

Example 63 with TagElement

use of org.eclipse.jdt.core.dom.TagElement in project eclipse.jdt.ls by eclipse.

the class JavadocTagsSubProcessor method insertTag.

public static void insertTag(ListRewrite rewriter, TagElement newElement, Set<String> sameKindLeadingNames, TextEditGroup groupDescription) {
    List<? extends ASTNode> tags = rewriter.getRewrittenList();
    String insertedTagName = newElement.getTagName();
    ASTNode after = null;
    int tagRanking = getTagRanking(insertedTagName);
    for (int i = tags.size() - 1; i >= 0; i--) {
        TagElement curr = (TagElement) tags.get(i);
        String tagName = curr.getTagName();
        if (tagName == null || tagRanking > getTagRanking(tagName)) {
            after = curr;
            break;
        }
        if (sameKindLeadingNames != null && isSameTag(insertedTagName, tagName)) {
            String arg = getArgument(curr);
            if (arg != null && sameKindLeadingNames.contains(arg)) {
                after = curr;
                break;
            }
        }
    }
    if (after != null) {
        rewriter.insertAfter(newElement, after, groupDescription);
    } else {
        rewriter.insertFirst(newElement, groupDescription);
    }
}
Also used : ASTNode(org.eclipse.jdt.core.dom.ASTNode) TagElement(org.eclipse.jdt.core.dom.TagElement)

Example 64 with TagElement

use of org.eclipse.jdt.core.dom.TagElement in project eclipse.jdt.ls by eclipse.

the class JavadocTagsSubProcessor method findParamTag.

public static TagElement findParamTag(Javadoc javadoc, String arg) {
    List<TagElement> tags = javadoc.tags();
    int nTags = tags.size();
    for (int i = 0; i < nTags; i++) {
        TagElement curr = tags.get(i);
        String currName = curr.getTagName();
        if (TagElement.TAG_PARAM.equals(currName)) {
            String argument = getArgument(curr);
            if (arg.equals(argument)) {
                return curr;
            }
        }
    }
    return null;
}
Also used : TagElement(org.eclipse.jdt.core.dom.TagElement)

Example 65 with TagElement

use of org.eclipse.jdt.core.dom.TagElement in project eclipse.jdt.ls by eclipse.

the class JavadocTagsSubProcessor method getRemoveJavadocTagProposals.

public static void getRemoveJavadocTagProposals(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) {
    ASTNode node = problem.getCoveringNode(context.getASTRoot());
    while (node != null && !(node instanceof TagElement)) {
        node = node.getParent();
    }
    if (node == null) {
        return;
    }
    ASTRewrite rewrite = ASTRewrite.create(node.getAST());
    rewrite.remove(node, null);
    String label = CorrectionMessages.JavadocTagsSubProcessor_removetag_description;
    proposals.add(new ASTRewriteCorrectionProposal(label, CodeActionKind.QuickFix, context.getCompilationUnit(), rewrite, IProposalRelevance.REMOVE_TAG));
}
Also used : ASTNode(org.eclipse.jdt.core.dom.ASTNode) TagElement(org.eclipse.jdt.core.dom.TagElement) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite)

Aggregations

TagElement (org.eclipse.jdt.core.dom.TagElement)76 ASTNode (org.eclipse.jdt.core.dom.ASTNode)36 Javadoc (org.eclipse.jdt.core.dom.Javadoc)28 TextElement (org.eclipse.jdt.core.dom.TextElement)23 AST (org.eclipse.jdt.core.dom.AST)20 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)19 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)18 SimpleName (org.eclipse.jdt.core.dom.SimpleName)17 Type (org.eclipse.jdt.core.dom.Type)17 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 ImportRewriteContext (org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext)16 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)14 ImportRewrite (org.eclipse.jdt.core.dom.rewrite.ImportRewrite)14 ContextSensitiveImportRewriteContext (org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext)14 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)11 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)11 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)11 ArrayList (java.util.ArrayList)10 List (java.util.List)9 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)8