Search in sources :

Example 51 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, IProblemLocation problem, Collection<CUCorrectionProposal> 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, 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)

Example 52 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 53 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 54 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 55 with TagElement

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

the class ReturnTypeSubProcessor method addMissingReturnStatementProposals.

public static void addMissingReturnStatementProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
    ICompilationUnit cu = context.getCompilationUnit();
    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (selectedNode == null) {
        return;
    }
    ReturnStatement existingStatement = (selectedNode instanceof ReturnStatement) ? (ReturnStatement) selectedNode : null;
    // Lambda Expression can be in a MethodDeclaration or a Field Declaration
    if (selectedNode instanceof LambdaExpression) {
        MissingReturnTypeInLambdaCorrectionProposal proposal = new MissingReturnTypeInLambdaCorrectionProposal(cu, (LambdaExpression) selectedNode, existingStatement, IProposalRelevance.MISSING_RETURN_TYPE);
        proposals.add(proposal);
    } else {
        BodyDeclaration decl = ASTResolving.findParentBodyDeclaration(selectedNode);
        if (decl instanceof MethodDeclaration) {
            MethodDeclaration methodDecl = (MethodDeclaration) decl;
            Block block = methodDecl.getBody();
            if (block == null) {
                return;
            }
            proposals.add(new MissingReturnTypeCorrectionProposal(cu, methodDecl, existingStatement, IProposalRelevance.MISSING_RETURN_TYPE));
            Type returnType = methodDecl.getReturnType2();
            if (returnType != null && !"void".equals(ASTNodes.asString(returnType))) {
                // $NON-NLS-1$
                AST ast = methodDecl.getAST();
                ASTRewrite rewrite = ASTRewrite.create(ast);
                rewrite.replace(returnType, ast.newPrimitiveType(PrimitiveType.VOID), null);
                Javadoc javadoc = methodDecl.getJavadoc();
                if (javadoc != null) {
                    TagElement tagElement = JavadocTagsSubProcessor.findTag(javadoc, TagElement.TAG_RETURN, null);
                    if (tagElement != null) {
                        rewrite.remove(tagElement, null);
                    }
                }
                String label = CorrectionMessages.ReturnTypeSubProcessor_changetovoid_description;
                ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.CHANGE_RETURN_TYPE_TO_VOID);
                proposals.add(proposal);
            }
        }
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) AST(org.eclipse.jdt.core.dom.AST) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) MissingReturnTypeInLambdaCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.MissingReturnTypeInLambdaCorrectionProposal) Javadoc(org.eclipse.jdt.core.dom.Javadoc) ASTRewriteCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.ASTRewriteCorrectionProposal) Type(org.eclipse.jdt.core.dom.Type) PrimitiveType(org.eclipse.jdt.core.dom.PrimitiveType) MissingReturnTypeCorrectionProposal(org.eclipse.jdt.ls.core.internal.corrections.proposals.MissingReturnTypeCorrectionProposal) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ReturnStatement(org.eclipse.jdt.core.dom.ReturnStatement) Block(org.eclipse.jdt.core.dom.Block) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) TagElement(org.eclipse.jdt.core.dom.TagElement) BodyDeclaration(org.eclipse.jdt.core.dom.BodyDeclaration) LambdaExpression(org.eclipse.jdt.core.dom.LambdaExpression)

Aggregations

TagElement (org.eclipse.jdt.core.dom.TagElement)59 ASTNode (org.eclipse.jdt.core.dom.ASTNode)29 Javadoc (org.eclipse.jdt.core.dom.Javadoc)25 AST (org.eclipse.jdt.core.dom.AST)17 TextElement (org.eclipse.jdt.core.dom.TextElement)16 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)15 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)15 Type (org.eclipse.jdt.core.dom.Type)14 ImportRewriteContext (org.eclipse.jdt.core.dom.rewrite.ImportRewrite.ImportRewriteContext)14 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)13 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)12 ImportRewrite (org.eclipse.jdt.core.dom.rewrite.ImportRewrite)12 SimpleName (org.eclipse.jdt.core.dom.SimpleName)11 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)11 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)8 PrimitiveType (org.eclipse.jdt.core.dom.PrimitiveType)8 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)7 ContextSensitiveImportRewriteContext (org.eclipse.jdt.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext)7 ContextSensitiveImportRewriteContext (org.eclipse.jdt.ls.core.internal.corext.codemanipulation.ContextSensitiveImportRewriteContext)7 ArrayList (java.util.ArrayList)6