Search in sources :

Example 11 with TagElement

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

the class DelegateCreator method createJavadoc.

/**
	 * Creates the javadoc for the delegate.
	 *
	 * @throws JavaModelException
	 */
private void createJavadoc() throws JavaModelException {
    TagElement tag = getDelegateJavadocTag(fDeclaration);
    Javadoc comment = fDeclaration.getJavadoc();
    if (comment == null) {
        comment = getAst().newJavadoc();
        comment.tags().add(tag);
        fDelegateRewrite.getASTRewrite().set(fDeclaration, getJavaDocProperty(), comment, null);
    } else
        fDelegateRewrite.getASTRewrite().getListRewrite(comment, Javadoc.TAGS_PROPERTY).insertLast(tag, null);
}
Also used : TagElement(org.eclipse.jdt.core.dom.TagElement) Javadoc(org.eclipse.jdt.core.dom.Javadoc)

Example 12 with TagElement

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

the class DelegateCreator method getDelegateJavadocTag.

// ******************* INTERNAL HELPERS ***************************
private TagElement getDelegateJavadocTag(BodyDeclaration declaration) throws JavaModelException {
    Assert.isNotNull(declaration);
    String msg = RefactoringCoreMessages.DelegateCreator_use_member_instead;
    //$NON-NLS-1$
    int firstParam = msg.indexOf("{0}");
    Assert.isTrue(firstParam != -1);
    List<ASTNode> fragments = new ArrayList<ASTNode>();
    TextElement text = getAst().newTextElement();
    text.setText(msg.substring(0, firstParam).trim());
    fragments.add(text);
    fragments.add(createJavadocMemberReferenceTag(declaration, getAst()));
    text = getAst().newTextElement();
    text.setText(msg.substring(firstParam + 3).trim());
    fragments.add(text);
    final TagElement tag = getAst().newTagElement();
    tag.setTagName(TagElement.TAG_DEPRECATED);
    tag.fragments().addAll(fragments);
    return tag;
}
Also used : TextElement(org.eclipse.jdt.core.dom.TextElement) ArrayList(java.util.ArrayList) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TagElement(org.eclipse.jdt.core.dom.TagElement)

Example 13 with TagElement

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

the class ModifierCorrectionSubProcessor method addOverridingDeprecatedMethodProposal.

public static void addOverridingDeprecatedMethodProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
    ICompilationUnit cu = context.getCompilationUnit();
    ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
    if (!(selectedNode instanceof MethodDeclaration)) {
        return;
    }
    boolean is50OrHigher = JavaModelUtil.is50OrHigher(cu.getJavaProject());
    MethodDeclaration methodDecl = (MethodDeclaration) selectedNode;
    AST ast = methodDecl.getAST();
    ASTRewrite rewrite = ASTRewrite.create(ast);
    if (is50OrHigher) {
        Annotation annot = ast.newMarkerAnnotation();
        //$NON-NLS-1$
        annot.setTypeName(ast.newName("Deprecated"));
        rewrite.getListRewrite(methodDecl, methodDecl.getModifiersProperty()).insertFirst(annot, null);
    }
    Javadoc javadoc = methodDecl.getJavadoc();
    if (javadoc != null || !is50OrHigher) {
        if (!is50OrHigher) {
            javadoc = ast.newJavadoc();
            rewrite.set(methodDecl, MethodDeclaration.JAVADOC_PROPERTY, javadoc, null);
        }
        TagElement newTag = ast.newTagElement();
        newTag.setTagName(TagElement.TAG_DEPRECATED);
        JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
    }
    String label = CorrectionMessages.ModifierCorrectionSubProcessor_overrides_deprecated_description;
    Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
    ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, cu, rewrite, IProposalRelevance.OVERRIDES_DEPRECATED, image);
    proposals.add(proposal);
}
Also used : ASTRewriteCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) AST(org.eclipse.jdt.core.dom.AST) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) ASTNode(org.eclipse.jdt.core.dom.ASTNode) ASTRewrite(org.eclipse.jdt.core.dom.rewrite.ASTRewrite) Javadoc(org.eclipse.jdt.core.dom.Javadoc) TagElement(org.eclipse.jdt.core.dom.TagElement) Image(org.eclipse.swt.graphics.Image) Annotation(org.eclipse.jdt.core.dom.Annotation)

Example 14 with TagElement

use of org.eclipse.jdt.core.dom.TagElement in project che 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 15 with TagElement

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

the class JavadocTagsSubProcessor method findThrowsTag.

public static TagElement findThrowsTag(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_THROWS.equals(currName) || TagElement.TAG_EXCEPTION.equals(currName)) {
            String argument = getArgument(curr);
            if (arg.equals(argument)) {
                return curr;
            }
        }
    }
    return null;
}
Also used : TagElement(org.eclipse.jdt.core.dom.TagElement)

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