Example usage for org.eclipse.jdt.core.dom TagElement TAG_RETURN

List of usage examples for org.eclipse.jdt.core.dom TagElement TAG_RETURN

Introduction

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

Prototype

String TAG_RETURN

To view the source code for org.eclipse.jdt.core.dom TagElement TAG_RETURN.

Click Source Link

Document

Standard doc tag name (value ).

Usage

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavaDoc2HTMLTextReader.java

License:Open Source License

private void handleTag(String tag, String tagContent) {

    tagContent = tagContent.trim();/*w  w w. j  a  va 2s . c om*/

    if (TagElement.TAG_PARAM.equals(tag))
        fParameters.add(tagContent);
    else if (TagElement.TAG_RETURN.equals(tag))
        fReturn = tagContent;
    else if (TagElement.TAG_EXCEPTION.equals(tag))
        fExceptions.add(tagContent);
    else if (TagElement.TAG_THROWS.equals(tag))
        fExceptions.add(tagContent);
    else if (TagElement.TAG_AUTHOR.equals(tag))
        fAuthors.add(substituteQualification(tagContent));
    else if (TagElement.TAG_SEE.equals(tag))
        fSees.add(substituteQualification(tagContent));
    else if (TagElement.TAG_SINCE.equals(tag))
        fSince.add(substituteQualification(tagContent));
    else if (tagContent != null)
        fRest.add(new Pair(tag, tagContent));
}

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java

License:Open Source License

private void elementToHTML() {
    // After first loop, non-null entries in the following two lists are missing and need to be inherited:
    List<String> typeParameterNames = initTypeParameterNames();
    List<String> parameterNames = initParameterNames();
    List<String> exceptionNames = initExceptionNames();

    TagElement deprecatedTag = null;
    TagElement start = null;/*w ww .j  a va 2 s  .  c  o  m*/
    List<TagElement> typeParameters = new ArrayList<>();
    List<TagElement> parameters = new ArrayList<>();
    TagElement returnTag = null;
    List<TagElement> exceptions = new ArrayList<>();
    List<TagElement> versions = new ArrayList<>();
    List<TagElement> authors = new ArrayList<>();
    List<TagElement> sees = new ArrayList<>();
    List<TagElement> since = new ArrayList<>();
    List<TagElement> rest = new ArrayList<>();

    List<TagElement> tags = fJavadoc.tags();
    for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
        TagElement tag = iter.next();
        String tagName = tag.getTagName();
        if (tagName == null) {
            start = tag;

        } else if (TagElement.TAG_PARAM.equals(tagName)) {
            List<? extends ASTNode> fragments = tag.fragments();
            int size = fragments.size();
            if (size > 0) {
                Object first = fragments.get(0);
                if (first instanceof SimpleName) {
                    String name = ((SimpleName) first).getIdentifier();
                    int paramIndex = parameterNames.indexOf(name);
                    if (paramIndex != -1) {
                        parameterNames.set(paramIndex, null);
                    }
                    parameters.add(tag);
                } else if (size > 2 && first instanceof TextElement) {
                    String firstText = ((TextElement) first).getText();
                    if ("<".equals(firstText)) { //$NON-NLS-1$
                        Object second = fragments.get(1);
                        Object third = fragments.get(2);
                        if (second instanceof SimpleName && third instanceof TextElement) {
                            String name = ((SimpleName) second).getIdentifier();
                            String thirdText = ((TextElement) third).getText();
                            if (">".equals(thirdText)) { //$NON-NLS-1$
                                int paramIndex = typeParameterNames.indexOf(name);
                                if (paramIndex != -1) {
                                    typeParameterNames.set(paramIndex, null);
                                }
                                typeParameters.add(tag);
                            }
                        }
                    }
                }
            }

        } else if (TagElement.TAG_RETURN.equals(tagName)) {
            if (returnTag == null)
                returnTag = tag; // the Javadoc tool only shows the first return tag

        } else if (TagElement.TAG_EXCEPTION.equals(tagName) || TagElement.TAG_THROWS.equals(tagName)) {
            exceptions.add(tag);
            List<? extends ASTNode> fragments = tag.fragments();
            if (fragments.size() > 0) {
                Object first = fragments.get(0);
                if (first instanceof Name) {
                    String name = ASTNodes.getSimpleNameIdentifier((Name) first);
                    int exceptionIndex = exceptionNames.indexOf(name);
                    if (exceptionIndex != -1) {
                        exceptionNames.set(exceptionIndex, null);
                    }
                }
            }

        } else if (TagElement.TAG_SINCE.equals(tagName)) {
            since.add(tag);
        } else if (TagElement.TAG_VERSION.equals(tagName)) {
            versions.add(tag);
        } else if (TagElement.TAG_AUTHOR.equals(tagName)) {
            authors.add(tag);
        } else if (TagElement.TAG_SEE.equals(tagName)) {
            sees.add(tag);
        } else if (TagElement.TAG_DEPRECATED.equals(tagName)) {
            if (deprecatedTag == null)
                deprecatedTag = tag; // the Javadoc tool only shows the first deprecated tag
        } else {
            rest.add(tag);
        }
    }

    //TODO: @Documented annotations before header
    if (deprecatedTag != null)
        handleDeprecatedTag(deprecatedTag);
    if (start != null)
        handleContentElements(start.fragments());
    else if (fMethod != null) {
        CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod);
        // The Javadoc tool adds "Description copied from class: ..." (only for the main description).
        // We don't bother doing that.
        handleInherited(inherited);
    }

    CharSequence[] typeParameterDescriptions = new CharSequence[typeParameterNames.size()];
    boolean hasInheritedTypeParameters = inheritTypeParameterDescriptions(typeParameterNames,
            typeParameterDescriptions);
    boolean hasTypeParameters = typeParameters.size() > 0 || hasInheritedTypeParameters;

    CharSequence[] parameterDescriptions = new CharSequence[parameterNames.size()];
    boolean hasInheritedParameters = inheritParameterDescriptions(parameterNames, parameterDescriptions);
    boolean hasParameters = parameters.size() > 0 || hasInheritedParameters;

    CharSequence returnDescription = null;
    if (returnTag == null && needsReturnTag())
        returnDescription = fJavadocLookup.getInheritedReturnDescription(fMethod);
    boolean hasReturnTag = returnTag != null || returnDescription != null;

    CharSequence[] exceptionDescriptions = new CharSequence[exceptionNames.size()];
    boolean hasInheritedExceptions = inheritExceptionDescriptions(exceptionNames, exceptionDescriptions);
    boolean hasExceptions = exceptions.size() > 0 || hasInheritedExceptions;

    if (hasParameters || hasTypeParameters || hasReturnTag || hasExceptions || versions.size() > 0
            || authors.size() > 0 || since.size() > 0 || sees.size() > 0 || rest.size() > 0
            || (fBuf.length() > 0 && (parameterDescriptions.length > 0 || exceptionDescriptions.length > 0))) {
        handleSuperMethodReferences();
        fBuf.append(BLOCK_TAG_START);
        handleParameterTags(typeParameters, typeParameterNames, typeParameterDescriptions, true);
        handleParameterTags(parameters, parameterNames, parameterDescriptions, false);
        handleReturnTag(returnTag, returnDescription);
        handleExceptionTags(exceptions, exceptionNames, exceptionDescriptions);
        handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_since_section, since);
        handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_version_section, versions);
        handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_author_section, authors);
        handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_see_section, sees);
        handleBlockTags(rest);
        fBuf.append(BLOCK_TAG_END);

    } else if (fBuf.length() > 0) {
        handleSuperMethodReferences();
    }
}

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java

License:Open Source License

CharSequence getReturnDescription() {
    if (fReturnDescription == null) {
        fReturnDescription = new StringBuffer();
        fBuf = fReturnDescription;/*from  w  ww.  jav a 2  s  .  com*/
        fLiteralContent = 0;

        List<TagElement> tags = fJavadoc.tags();
        for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
            TagElement tag = iter.next();
            String tagName = tag.getTagName();
            if (TagElement.TAG_RETURN.equals(tagName)) {
                handleContentElements(tag.fragments());
                break;
            }
        }

        fBuf = null;
    }
    return fReturnDescription.length() > 0 ? fReturnDescription : null;
}

From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java

License:Open Source License

/**
 * Handle {&#64;inheritDoc}.//from  w w  w. j a v  a2s .  c  o  m
 *
 * @param node the node
 * @return <code>true</code> iff the node was an {&#64;inheritDoc} node and has been handled
 */
private boolean handleInheritDoc(TagElement node) {
    if (!TagElement.TAG_INHERITDOC.equals(node.getTagName()))
        return false;
    try {
        if (fMethod == null)
            return false;

        TagElement blockTag = (TagElement) node.getParent();
        String blockTagName = blockTag.getTagName();

        if (blockTagName == null) {
            CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod);
            return handleInherited(inherited);

        } else if (TagElement.TAG_PARAM.equals(blockTagName)) {
            List<? extends ASTNode> fragments = blockTag.fragments();
            int size = fragments.size();
            if (size > 0) {
                Object first = fragments.get(0);
                if (first instanceof SimpleName) {
                    String name = ((SimpleName) first).getIdentifier();
                    String[] parameterNames = fMethod.getParameterNames();
                    for (int i = 0; i < parameterNames.length; i++) {
                        if (name.equals(parameterNames[i])) {
                            CharSequence inherited = fJavadocLookup.getInheritedParamDescription(fMethod, i);
                            return handleInherited(inherited);
                        }
                    }
                } else if (size > 2 && first instanceof TextElement) {
                    String firstText = ((TextElement) first).getText();
                    if ("<".equals(firstText)) { //$NON-NLS-1$
                        Object second = fragments.get(1);
                        Object third = fragments.get(2);
                        if (second instanceof SimpleName && third instanceof TextElement) {
                            String thirdText = ((TextElement) third).getText();
                            if (">".equals(thirdText)) { //$NON-NLS-1$
                                String name = ((SimpleName) second).getIdentifier();
                                ITypeParameter[] typeParameters = fMethod.getTypeParameters();
                                for (int i = 0; i < typeParameters.length; i++) {
                                    ITypeParameter typeParameter = typeParameters[i];
                                    if (name.equals(typeParameter.getElementName())) {
                                        CharSequence inherited = fJavadocLookup
                                                .getInheritedTypeParamDescription(fMethod, i);
                                        return handleInherited(inherited);
                                    }
                                }
                            }
                        }
                    }
                }
            }

        } else if (TagElement.TAG_RETURN.equals(blockTagName)) {
            CharSequence inherited = fJavadocLookup.getInheritedReturnDescription(fMethod);
            return handleInherited(inherited);

        } else if (TagElement.TAG_THROWS.equals(blockTagName)
                || TagElement.TAG_EXCEPTION.equals(blockTagName)) {
            List<? extends ASTNode> fragments = blockTag.fragments();
            if (fragments.size() > 0) {
                Object first = fragments.get(0);
                if (first instanceof Name) {
                    String name = ASTNodes.getSimpleNameIdentifier((Name) first);
                    CharSequence inherited = fJavadocLookup.getInheritedExceptionDescription(fMethod, name);
                    return handleInherited(inherited);
                }
            }
        }
    } catch (JavaModelException e) {
        //TODO
        e.printStackTrace();
    }
    return false;
}

From source file:com.codenvy.ide.ext.java.server.javadoc.JavadocContentAccess2.java

License:Open Source License

private String toHTML() {
    fBuf = new StringBuffer();
    fLiteralContent = 0;/*  w  ww  .j ava  2  s .c om*/

    // After first loop, non-null entries in the following two lists are missing and need to be inherited:
    List<String> parameterNames = initParameterNames();
    List<String> exceptionNames = initExceptionNames();

    TagElement deprecatedTag = null;
    TagElement start = null;
    List<TagElement> parameters = new ArrayList<TagElement>();
    TagElement returnTag = null;
    List<TagElement> exceptions = new ArrayList<TagElement>();
    List<TagElement> versions = new ArrayList<TagElement>();
    List<TagElement> authors = new ArrayList<TagElement>();
    List<TagElement> sees = new ArrayList<TagElement>();
    List<TagElement> since = new ArrayList<TagElement>();
    List<TagElement> rest = new ArrayList<TagElement>();

    List<TagElement> tags = fJavadoc.tags();
    for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext();) {
        TagElement tag = iter.next();
        String tagName = tag.getTagName();
        if (tagName == null) {
            start = tag;

        } else if (TagElement.TAG_PARAM.equals(tagName)) {
            parameters.add(tag);
            List<? extends ASTNode> fragments = tag.fragments();
            if (fragments.size() > 0) {
                Object first = fragments.get(0);
                if (first instanceof SimpleName) {
                    String name = ((SimpleName) first).getIdentifier();
                    int paramIndex = parameterNames.indexOf(name);
                    if (paramIndex != -1) {
                        parameterNames.set(paramIndex, null);
                    }
                }
            }

        } else if (TagElement.TAG_RETURN.equals(tagName)) {
            if (returnTag == null)
                returnTag = tag; // the Javadoc tool only shows the first return tag

        } else if (TagElement.TAG_EXCEPTION.equals(tagName) || TagElement.TAG_THROWS.equals(tagName)) {
            exceptions.add(tag);
            List<? extends ASTNode> fragments = tag.fragments();
            if (fragments.size() > 0) {
                Object first = fragments.get(0);
                if (first instanceof Name) {
                    String name = ASTNodes.getSimpleNameIdentifier((Name) first);
                    int exceptionIndex = exceptionNames.indexOf(name);
                    if (exceptionIndex != -1) {
                        exceptionNames.set(exceptionIndex, null);
                    }
                }
            }

        } else if (TagElement.TAG_SINCE.equals(tagName)) {
            since.add(tag);
        } else if (TagElement.TAG_VERSION.equals(tagName)) {
            versions.add(tag);
        } else if (TagElement.TAG_AUTHOR.equals(tagName)) {
            authors.add(tag);
        } else if (TagElement.TAG_SEE.equals(tagName)) {
            sees.add(tag);
        } else if (TagElement.TAG_DEPRECATED.equals(tagName)) {
            if (deprecatedTag == null)
                deprecatedTag = tag; // the Javadoc tool only shows the first deprecated tag
        } else {
            rest.add(tag);
        }
    }

    //TODO: @Documented annotations before header
    if (deprecatedTag != null)
        handleDeprecatedTag(deprecatedTag);
    if (start != null)
        handleContentElements(start.fragments());
    else if (fMethod != null) {
        CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod);
        // The Javadoc tool adds "Description copied from class: ..." (only for the main description).
        // We don't bother doing that.
        handleInherited(inherited);
    }

    CharSequence[] parameterDescriptions = new CharSequence[parameterNames.size()];
    boolean hasInheritedParameters = inheritParameterDescriptions(parameterNames, parameterDescriptions);
    boolean hasParameters = parameters.size() > 0 || hasInheritedParameters;

    CharSequence returnDescription = null;
    if (returnTag == null && needsReturnTag())
        returnDescription = fJavadocLookup.getInheritedReturnDescription(fMethod);
    boolean hasReturnTag = returnTag != null || returnDescription != null;

    CharSequence[] exceptionDescriptions = new CharSequence[exceptionNames.size()];
    boolean hasInheritedExceptions = inheritExceptionDescriptions(exceptionNames, exceptionDescriptions);
    boolean hasExceptions = exceptions.size() > 0 || hasInheritedExceptions;

    if (hasParameters || hasReturnTag || hasExceptions || versions.size() > 0 || authors.size() > 0
            || since.size() > 0 || sees.size() > 0 || rest.size() > 0
            || (fBuf.length() > 0 && (parameterDescriptions.length > 0 || exceptionDescriptions.length > 0))) {
        handleSuperMethodReferences();
        fBuf.append(BLOCK_TAG_START);
        handleParameterTags(parameters, parameterNames, parameterDescriptions);
        handleReturnTag(returnTag, returnDescription);
        handleExceptionTags(exceptions, exceptionNames, exceptionDescriptions);
        handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_since_section, since);
        handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_version_section, versions);
        handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_author_section, authors);
        handleBlockTags(JavaDocMessages.JavaDoc2HTMLTextReader_see_section, sees);
        handleBlockTags(rest);
        fBuf.append(BLOCK_TAG_END);

    } else if (fBuf.length() > 0) {
        handleSuperMethodReferences();
    }

    String result = fBuf.toString();
    fBuf = null;
    return result;
}

From source file:com.codenvy.ide.ext.java.server.javadoc.JavadocContentAccess2.java

License:Open Source License

/**
 * Handle {&#64;inheritDoc}./*from w  ww  .j a  v  a 2 s. co m*/
 *
 * @param node
 *         the node
 * @return <code>true</code> iff the node was an {&#64;inheritDoc} node and has been handled
 */
private boolean handleInheritDoc(TagElement node) {
    if (!TagElement.TAG_INHERITDOC.equals(node.getTagName()))
        return false;
    try {
        if (fMethod == null)
            return false;

        TagElement blockTag = (TagElement) node.getParent();
        String blockTagName = blockTag.getTagName();

        if (blockTagName == null) {
            CharSequence inherited = fJavadocLookup.getInheritedMainDescription(fMethod);
            return handleInherited(inherited);

        } else if (TagElement.TAG_PARAM.equals(blockTagName)) {
            List<? extends ASTNode> fragments = blockTag.fragments();
            if (fragments.size() > 0) {
                Object first = fragments.get(0);
                if (first instanceof SimpleName) {
                    String name = ((SimpleName) first).getIdentifier();
                    String[] parameterNames = fMethod.getParameterNames();
                    for (int i = 0; i < parameterNames.length; i++) {
                        if (name.equals(parameterNames[i])) {
                            CharSequence inherited = fJavadocLookup.getInheritedParamDescription(fMethod, i);
                            return handleInherited(inherited);
                        }
                    }
                }
            }

        } else if (TagElement.TAG_RETURN.equals(blockTagName)) {
            CharSequence inherited = fJavadocLookup.getInheritedReturnDescription(fMethod);
            return handleInherited(inherited);

        } else if (TagElement.TAG_THROWS.equals(blockTagName)
                || TagElement.TAG_EXCEPTION.equals(blockTagName)) {
            List<? extends ASTNode> fragments = blockTag.fragments();
            if (fragments.size() > 0) {
                Object first = fragments.get(0);
                if (first instanceof Name) {
                    String name = ASTNodes.getSimpleNameIdentifier((Name) first);
                    CharSequence inherited = fJavadocLookup.getInheritedExceptionDescription(fMethod, name);
                    return handleInherited(inherited);
                }
            }
        }
    } catch (JavaModelException e) {
        LOG.error(e.getMessage(), e);
    }
    return false;
}

From source file:com.servoy.eclipse.docgenerator.generators.DocumentationDataDistilled.java

License:Open Source License

public DocumentationDataDistilled(IMemberMetaModel memberMM, TypeMetaModel typeMM, JavadocMetaModel jdoc,
        MetaModelHolder holder) {//from   w w w  . jav  a 2s .c  o m
    Set<DocumentationWarning> warnings = memberMM.getWarnings();
    String location = memberMM.getFullSignature();

    boolean clean = true;

    ClientSupport typeCsp = typeMM.getServoyClientSupport(holder);
    ClientSupport csp = typeCsp == null ? ClientSupport.Default : typeCsp;

    texts = new ArrayList<Pair<ClientSupport, String>>();
    summaries = new ArrayList<Pair<ClientSupport, String>>();

    String descriptionText = ExtractorUtil.grabExactlyOne(JavadocMetaModel.TEXT_TAG, clean, jdoc, warnings,
            location);
    String mobileDescriptionText = ExtractorUtil.grabExactlyOne(TAG_MOBILEDESCRIPTION, clean, jdoc, warnings,
            location);

    List<Pair<ClientSupport, String>> txts = new ArrayList<Pair<ClientSupport, String>>();
    if (mobileDescriptionText != null && mobileDescriptionText.trim().length() > 0) {
        txts.add(new Pair<ClientSupport, String>(ClientSupport.mc, mobileDescriptionText.trim()));
        csp = csp.remove(ClientSupport.mc);
    }
    if (descriptionText != null && descriptionText.trim().length() > 0) {
        txts.add(new Pair<ClientSupport, String>(csp, descriptionText));
    }
    setTexts(txts);

    String sample = ExtractorUtil.grabExactlyOne(TAG_SAMPLE, clean, jdoc, warnings, location);
    String mSample = ExtractorUtil.grabExactlyOne(TAG_MOBILESAMPLE, clean, jdoc, warnings, location);
    ClientSupport aux = typeCsp == null ? ClientSupport.Default : typeCsp;
    if (mSample != null && mSample.trim().length() > 0) {
        // add back the "*/"
        mSample = Pattern.compile("\\*&#47;").matcher(mSample).replaceAll("*/");
        addSample(ClientSupport.mc, mSample);
        aux = aux.remove(ClientSupport.mc);
    }
    if (sample != null && sample.trim().length() > 0) {
        // add back the "*/"
        sample = Pattern.compile("\\*&#47;").matcher(sample).replaceAll("*/");
        addSample(aux, sample);
    }

    deprecatedText = ExtractorUtil.grabExactlyOne(TagElement.TAG_DEPRECATED, clean, jdoc, warnings, location);
    ret = ExtractorUtil.grabExactlyOne(TagElement.TAG_RETURN, clean, jdoc, warnings, location);
    since = ExtractorUtil.grabExactlyOne(TagElement.TAG_SINCE, clean, jdoc, warnings, location);
    until = ExtractorUtil.grabExactlyOne(TAG_UNTIL, clean, jdoc, warnings, location);
    sameAs = ExtractorUtil.grabReference(TAG_SAMEAS, jdoc, warnings, location);
    if (sameAs != null) {
        sameAs.setEnclosingType(typeMM.getName().getQualifiedName());
    }
    cloneSample = ExtractorUtil.grabReference(TAG_SAMPLE_AS, jdoc, warnings, location);
    if (cloneSample != null) {
        cloneSample.setEnclosingType(typeMM.getName().getQualifiedName());
    }
    cloneDescription = ExtractorUtil.grabReference(TAG_CLONEDESC, jdoc, warnings, location);
    if (cloneDescription != null) {
        cloneDescription.setEnclosingType(typeMM.getName().getQualifiedName());
    }

    JavadocTagPart specialTag = ExtractorUtil.grabFirstTag(TAG_SPECIAL, jdoc, true, warnings, location);
    if (specialTag != null) {
        special = true;
    }

    JavadocTagPart simplifiedSignatureTag = ExtractorUtil.grabFirstTag(TAG_SIMPLIFIEDSIGNATURE, jdoc, true,
            warnings, location);
    if (simplifiedSignatureTag != null) {
        simplifiedSignature = true;
    }

    JavadocTagPart staticCallTag = ExtractorUtil.grabFirstTag(TAG_STATICCALL, jdoc, true, warnings, location);
    if (staticCallTag != null) {
        staticCall = true;
    }

    List<JavadocTagPart> paramTags = jdoc.findTags(TagElement.TAG_PARAM);
    for (JavadocTagPart paramTag : paramTags) {
        String paramText = paramTag.getAsString(clean);
        paramText = paramText.trim();

        StringTokenizer st = new StringTokenizer(paramText);
        if (st.hasMoreTokens()) {
            String paramName = st.nextToken();
            boolean isOptional = false;
            String paramDescription = null;
            if (st.hasMoreTokens()) {
                String maybeOptional = st.nextToken();
                if (maybeOptional.equals(FLAG_OPTIONAL)) {
                    isOptional = true;
                    int idx = paramText.indexOf(FLAG_OPTIONAL);
                    paramDescription = paramText.substring(idx + FLAG_OPTIONAL.length()).trim();
                } else {
                    paramDescription = paramText.substring(paramName.length()).trim();
                }
            }
            if (paramDescription == null) {
                paramDescription = "";
                warnings.add(new DocumentationWarning(WarningType.ParamTagWithoutContent, location,
                        TagElement.TAG_PARAM + " tag without text: '" + paramName + "'."));
            }
            DocumentedParameterData parData = new DocumentedParameterData(paramName, isOptional,
                    paramDescription);
            parameters.add(parData);
        } else {
            warnings.add(new DocumentationWarning(WarningType.EmptyTag, location,
                    "Empty " + TagElement.TAG_PARAM + " tag."));
        }
    }

    List<JavadocTagPart> linkTags = jdoc.findTags(TagElement.TAG_LINK);
    for (JavadocTagPart linkTag : linkTags) {
        String linkText = linkTag.getAsString(clean).trim();
        int idx = linkText.indexOf(' ');
        if (idx >= 0) {
            linkText = linkText.substring(0, idx);
        }
        links.add(linkText);
    }
}

From source file:de.akra.idocit.java.services.JavadocGeneratorTest.java

License:Apache License

/**
 * Tests {@link JavadocGenerator#appendDocsToJavadoc(List, String, String, Javadoc)} .
 * /*w w w . j  av a  2s  .c  o m*/
 * @throws IOException
 * @throws FileNotFoundException
 */
@SuppressWarnings("unchecked")
@Test
public void testGenerateJavadoc() throws FileNotFoundException, IOException {
    ParserOutput output = JavaTestUtils
            .createCompilationUnit(AllIDocItJavaTests.SOURCE_DIR + "ParsingService.java");
    CompilationUnit cu = output.getCompilationUnit();

    AbstractTypeDeclaration absTypeDecl = (AbstractTypeDeclaration) cu.types().get(0);
    AST ast = absTypeDecl.getAST();
    Javadoc javadoc = ast.newJavadoc();

    List<Documentation> documentations = createParamDocumentations();

    JavaMethod methodParam = new JavaMethod(SignatureElement.EMPTY_SIGNATURE_ELEMENT, "Method",
            "Searching Operations", Numerus.SINGULAR);

    for (Documentation documentation : documentations) {
        methodParam.addDocpart(documentation);
    }

    JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodParam.getDocumentations(), null, null,
            "Searching Operations", javadoc, new ArrayList<TagElement>(), null);
    JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodParam.getDocumentations(), TagElement.TAG_PARAM,
            "person", "Searching Operations", javadoc, new ArrayList<TagElement>(), null);

    JavaMethod methodReturn = new JavaMethod(SignatureElement.EMPTY_SIGNATURE_ELEMENT, "Method",
            "Searching Operations", Numerus.SINGULAR);

    for (Documentation documentation : createReturnDocumentations()) {
        methodReturn.addDocpart(documentation);
    }

    JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodReturn.getDocumentations(), TagElement.TAG_RETURN, null,
            "Searching Operations", javadoc, new ArrayList<TagElement>(), null);

    TagElement tagElement = ast.newTagElement();
    tagElement.setTagName(JavadocParser.JAVADOC_TAG_THEMATICGRID);

    List<ASTNode> fragments = (List<ASTNode>) tagElement.fragments();
    TextElement textElement = ast.newTextElement();
    textElement.setText(" Searching Operations");
    fragments.add(textElement);

    List<TagElement> tags = javadoc.tags();
    tags.add(tagElement);

    Assert.assertEquals(EXPECTED_JAVADOC, javadoc.toString());
}

From source file:de.akra.idocit.java.services.JavadocGeneratorTest.java

License:Apache License

/**
 * Test for//from w ww.ja  v  a  2 s  .  c  o m
 * {@link JavaInterfaceGenerator#updateJavadocInAST(de.akra.idocit.java.structure.JavaInterfaceArtifact)}
 * . Creates a Javadoc and writes it into a Java source file.
 * 
 * @throws FileNotFoundException
 * @throws IOException
 * @throws ParsingException
 */
@Test
public void testJavaInterfaceGenerator() throws FileNotFoundException, IOException, ParsingException {
    ParserOutput output = JavaTestUtils
            .createCompilationUnit(AllIDocItJavaTests.SOURCE_DIR + "ParsingService.java");
    CompilationUnit cu = output.getCompilationUnit();
    Document document = output.getDocument();

    cu.recordModifications();

    TypeDeclaration typeDecl = (TypeDeclaration) cu.types().get(0);
    AST ast = typeDecl.getAST();

    List<JavadocTagElement> jDocTags = new ArrayList<JavadocTagElement>();
    JavadocTagElement tagElem = new JavadocTagElement(TagElement.TAG_PARAM, "paramName",
            createParamDocumentations(), SignatureElement.EMPTY_SIGNATURE_ELEMENT);
    jDocTags.add(tagElem);

    tagElem = new JavadocTagElement(TagElement.TAG_RETURN, null, createReturnDocumentations(),
            SignatureElement.EMPTY_SIGNATURE_ELEMENT);
    jDocTags.add(tagElem);

    List<TagElement> additionalTags = Collections.emptyList();
    Javadoc javadoc = JavaInterfaceGenerator.createOrUpdateJavadoc(jDocTags, additionalTags,
            typeDecl.getJavadoc(), ast, null, JavadocGenerator.INSTANCE, null);
    typeDecl.setJavadoc(javadoc);

    cu.rewrite(document, null);

    TypeDeclaration newTypeDecl = (TypeDeclaration) cu.types().get(0);

    Assert.assertEquals("The written Javadoc in the CompilationUnit is not the same as the created Javadoc.",
            javadoc, newTypeDecl.getJavadoc());
}

From source file:de.akra.idocit.java.services.JavadocParserTest.java

License:Apache License

/**
 * Test for {@link JavadocParser#parseIDocItJavadoc(Javadoc)}.
 * //from   w ww.j a v  a 2  s  .  c o m
 * @throws ParserConfigurationException
 * @throws IOException
 * @throws SAXException
 * @throws ParsingException 
 * 
 * @throws Exception
 */
@Test
public void testParse() throws SAXException, IOException, ParserConfigurationException, ParsingException {
    {
        AST a = AST.newAST(AST.JLS3);
        Javadoc javadoc = a.newJavadoc();

        List<Documentation> paramDocumentations = createParamDocumentations();
        List<Documentation> returnDocumentations = createReturnDocumentations();

        JavaMethod methodWithParams = new JavaMethod(SignatureElement.EMPTY_SIGNATURE_ELEMENT, "Method",
                "Searching Operations", Numerus.SINGULAR);

        for (Documentation documentation : paramDocumentations) {
            methodWithParams.addDocpart(documentation);
        }

        JavaMethod methodWithReturn = new JavaMethod(SignatureElement.EMPTY_SIGNATURE_ELEMENT, "Method",
                "Searching Operations", Numerus.SINGULAR);

        for (Documentation documentation : returnDocumentations) {
            methodWithReturn.addDocpart(documentation);
        }

        JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodWithParams.getDocumentations(), null, null,
                "Searching Operations", javadoc, new ArrayList<TagElement>(), null);
        JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodWithParams.getDocumentations(),
                TagElement.TAG_PARAM, "person", "Searching Operations", javadoc, new ArrayList<TagElement>(),
                null);
        JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodWithReturn.getDocumentations(),
                TagElement.TAG_RETURN, null, "Searching Operations", javadoc, new ArrayList<TagElement>(),
                null);
        JavadocGenerator.INSTANCE.appendDocsToJavadoc(methodWithParams.getDocumentations(),
                TagElement.TAG_THROWS, "IllegalArgException", "Searching Operations", javadoc,
                new ArrayList<TagElement>(), null);

        // add the number of used documentations to this list, to make an assertion
        List<Documentation> allUsedDocs = new ArrayList<Documentation>(paramDocumentations.size() * 4);
        allUsedDocs.addAll(paramDocumentations);
        allUsedDocs.addAll(paramDocumentations);
        allUsedDocs.addAll(returnDocumentations);
        allUsedDocs.addAll(paramDocumentations);

        logger.log(Level.FINE, javadoc.toString());

        List<Documentation> convertedDocs = JavadocParser.INSTANCE.parseIDocItJavadoc(javadoc,
                TestUtils.createReferenceAddressees(), TestUtils.createReferenceThematicRoles(),
                methodWithParams);

        logger.log(Level.FINE, allUsedDocs.toString());
        logger.log(Level.FINE, convertedDocs.toString());

        Assert.assertEquals(allUsedDocs, convertedDocs);
    }
}