Example usage for org.eclipse.jdt.core.dom BodyDeclaration getJavadocProperty

List of usage examples for org.eclipse.jdt.core.dom BodyDeclaration getJavadocProperty

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom BodyDeclaration getJavadocProperty.

Prototype

public final ChildPropertyDescriptor getJavadocProperty() 

Source Link

Document

Returns structural property descriptor for the "javadoc" property of this node (child type: Javadoc ).

Usage

From source file:com.google.currysrc.api.process.JavadocUtils.java

License:Apache License

public static void addJavadocTag(ASTRewrite rewrite, BodyDeclaration node, String tagText) {
    Javadoc javadoc = node.getJavadoc();
    if (javadoc == null) {
        AST ast = node.getAST();/*from ww w . j  a v a 2s  .  c  o m*/
        javadoc = (Javadoc) ast.createInstance(Javadoc.class);
        rewrite.set(node, node.getJavadocProperty(), javadoc, null /* editGroup */);
    }
    addJavadocTag(rewrite, javadoc, tagText);
}

From source file:net.atos.optimus.m2t.merger.java.core.JavaCodeMerger.java

License:Open Source License

/**
 * Merge javadoc comment from existingFragment and generatedFragment to an
 * AST Rewrite object instance. This method is call only when
 * {@code existingFragment} is marked as generated and
 * {@code generatedFragment} exist./*  ww w.  j a  v  a2s  . c  o m*/
 * 
 * @param existingFragment
 *            The existing fragment
 * @param generatedFragment
 *            The generated fragment
 * @param astr
 *            The ASTRewrite object instance containing the merge result
 */
protected void mergeJavadoc(BodyDeclaration existingFragment, BodyDeclaration generatedFragment,
        ASTRewrite astr) {
    boolean existingCommentIsGenerated = false;
    boolean generatedCommentIsGenerated = false;
    boolean existingCommentFound = true;
    boolean generatedCommentFound = true;

    try {
        existingCommentIsGenerated = isJavadocCommentGenerated(existingFragment.getJavadoc());
    } catch (IllegalArgumentException iae) {
        existingCommentFound = false;
    }

    try {
        generatedCommentIsGenerated = isJavadocCommentGenerated(generatedFragment.getJavadoc());
    } catch (IllegalArgumentException iae) {
        generatedCommentFound = false;
    }

    if (existingCommentIsGenerated) {
        if (!generatedCommentFound) {
            if (MergerLogger.enabled())
                MergerLogger.log(MergerLoggerMessages.MERGER_REMOVE_JAVADOC.value(
                        JavaCodeHelper.getName(existingFragment),
                        JavaCodeHelper.getDescription(existingFragment)));

            astr.remove(existingFragment.getJavadoc(), null);
        } else if (generatedCommentIsGenerated) {
            if (MergerLogger.enabled())
                MergerLogger.log(MergerLoggerMessages.MERGER_REPLACE_JAVADOC.value(
                        JavaCodeHelper.getName(existingFragment), JavaCodeHelper.getName(generatedFragment)));

            astr.replace(existingFragment.getJavadoc(), generatedFragment.getJavadoc(), null);
        }
    } else if (!existingCommentFound && generatedCommentIsGenerated) {
        if (MergerLogger.enabled())
            MergerLogger.log(
                    MergerLoggerMessages.MERGER_ADD_JAVADOC.value(JavaCodeHelper.getName(existingFragment)));
        astr.set(existingFragment, existingFragment.getJavadocProperty(), generatedFragment.getJavadoc(), null);
    }
}

From source file:org.eclipse.pde.api.tools.ui.internal.markers.UpdateSinceTagOperation.java

License:Open Source License

public void run(IProgressMonitor monitor) {
    if (monitor != null && monitor.isCanceled()) {
        return;/*from   w w w .j  av  a 2  s.  c o  m*/
    }
    if (monitor != null) {
        monitor.beginTask(MarkerMessages.UpdateSinceTagOperation_title, 3);
    }
    // retrieve the AST node compilation unit
    try {
        Integer charStartAttribute = (Integer) this.fMarker.getAttribute(IMarker.CHAR_START);
        int intValue = charStartAttribute.intValue();
        IJavaElement javaElement = null;
        IJavaElement handleElement = null;
        if (intValue > 0) {
            IResource resource = this.fMarker.getResource();
            javaElement = JavaCore.create(resource);
        } else {
            // this is a case where the marker is reported against the
            // MANIFEST.MF file
            String handle = (String) fMarker.getAttribute(IApiMarkerConstants.MARKER_ATTR_HANDLE_ID);
            if (handle != null) {
                handleElement = JavaCore.create(handle);
            }
            if (handleElement != null && handleElement.exists()) {
                javaElement = handleElement.getAncestor(IJavaElement.COMPILATION_UNIT);
            }
        }
        if (javaElement != null && javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
            ICompilationUnit compilationUnit = (ICompilationUnit) javaElement;
            if (!compilationUnit.isWorkingCopy()) {
                // open an editor of the corresponding unit to "show" the
                // quickfix change
                JavaUI.openInEditor(compilationUnit);
            }
            ASTParser parser = ASTParser.newParser(AST.JLS8);
            parser.setSource(compilationUnit);
            if (intValue <= 0) {
                // try to use the name range of the corresponding element
                if (handleElement instanceof IMember) {
                    IMember member = (IMember) handleElement;
                    ISourceRange range = member.getNameRange();
                    if (range != null) {
                        intValue = range.getOffset();
                    } else {
                        range = member.getSourceRange();
                        if (range != null && range.getOffset() > 0) {
                            intValue = range.getOffset();
                        } else {
                            return;
                        }
                    }
                } else {
                    return;
                }
            }
            parser.setFocalPosition(intValue);
            parser.setResolveBindings(true);
            Map<String, String> options = compilationUnit.getJavaProject().getOptions(true);
            options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
            parser.setCompilerOptions(options);
            final CompilationUnit unit = (CompilationUnit) parser.createAST(new NullProgressMonitor());
            BodyDeclaration node = null;
            NodeFinder nodeFinder = new NodeFinder(intValue);
            unit.accept(nodeFinder);
            if (monitor != null) {
                monitor.worked(1);
            }
            node = nodeFinder.getNode();
            if (node != null) {
                unit.recordModifications();
                AST ast = unit.getAST();
                ASTRewrite rewrite = ASTRewrite.create(ast);
                if (IApiProblem.SINCE_TAG_MISSING == this.sinceTagType) {
                    Javadoc docnode = node.getJavadoc();
                    if (docnode == null) {
                        docnode = ast.newJavadoc();
                        // we do not want to create a new empty Javadoc node
                        // in
                        // the AST if there are no missing tags
                        rewrite.set(node, node.getJavadocProperty(), docnode, null);
                    } else {
                        List<TagElement> tags = docnode.tags();
                        boolean found = false;
                        loop: for (Iterator<TagElement> iterator = tags.iterator(); iterator.hasNext();) {
                            TagElement element = iterator.next();
                            String tagName = element.getTagName();
                            if (TagElement.TAG_SINCE.equals(tagName)) {
                                found = true;
                                break loop;
                            }
                        }
                        if (found) {
                            return;
                        }
                    }
                    ListRewrite lrewrite = rewrite.getListRewrite(docnode, Javadoc.TAGS_PROPERTY);
                    // check the existing tags list
                    TagElement newtag = ast.newTagElement();
                    newtag.setTagName(TagElement.TAG_SINCE);
                    TextElement textElement = ast.newTextElement();
                    textElement.setText(this.sinceTagVersion);
                    newtag.fragments().add(textElement);
                    lrewrite.insertLast(newtag, null);
                } else {
                    Javadoc docnode = node.getJavadoc();
                    List<TagElement> tags = docnode.tags();
                    TagElement sinceTag = null;
                    for (Iterator<TagElement> iterator = tags.iterator(); iterator.hasNext();) {
                        TagElement tagElement = iterator.next();
                        if (TagElement.TAG_SINCE.equals(tagElement.getTagName())) {
                            sinceTag = tagElement;
                            break;
                        }
                    }
                    if (sinceTag != null) {
                        List<TextElement> fragments = sinceTag.fragments();
                        if (fragments.size() >= 1) {
                            TextElement textElement = fragments.get(0);
                            StringBuffer buffer = new StringBuffer();
                            buffer.append(' ').append(this.sinceTagVersion);
                            rewrite.set(textElement, TextElement.TEXT_PROPERTY, String.valueOf(buffer), null);
                        } else {
                            ListRewrite lrewrite = rewrite.getListRewrite(docnode, Javadoc.TAGS_PROPERTY);
                            // check the existing tags list
                            TagElement newtag = ast.newTagElement();
                            newtag.setTagName(TagElement.TAG_SINCE);
                            TextElement textElement = ast.newTextElement();
                            textElement.setText(this.sinceTagVersion);
                            newtag.fragments().add(textElement);
                            lrewrite.replace(sinceTag, newtag, null);
                        }
                    }
                }
                try {
                    if (monitor != null) {
                        monitor.worked(1);
                    }
                    TextEdit edit = rewrite.rewriteAST();
                    compilationUnit.applyTextEdit(edit, monitor);
                    if (monitor != null) {
                        monitor.worked(1);
                    }
                } finally {
                    compilationUnit.reconcile(ICompilationUnit.NO_AST, false /*
                                                                             * don
                                                                             * 't
                                                                             * force
                                                                             * problem
                                                                             * detection
                                                                             */, null /*
                                                                                       * use
                                                                                       * primary
                                                                                       * owner
                                                                                       */, null /*
                                                                                                 * no
                                                                                                 * progress
                                                                                                 * monitor
                                                                                                 */);
                }
            }
        }
    } catch (CoreException e) {
        ApiUIPlugin.log(e);
    } finally {
        if (monitor != null) {
            monitor.done();
        }
    }
}

From source file:org.eclipseguru.gwt.core.internal.codegen.AsyncServiceCodeGenerator.java

License:Open Source License

private Javadoc createJavadocIfNecessary(final ASTRewrite cuRewrite, final BodyDeclaration bd,
        final TextEditGroup textEditGroup) {
    Javadoc javadoc = bd.getJavadoc();//from w  w w.ja  va2s  . c o  m
    if (null == javadoc) {
        javadoc = cuRewrite.getAST().newJavadoc();
        cuRewrite.set(bd, bd.getJavadocProperty(), javadoc, textEditGroup);
    }
    return javadoc;
}