Search in sources :

Example 71 with TagElement

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

the class JavadocContentAccess2 method handleInheritDoc.

/**
 * Handle {@inheritDoc}.
 *
 * @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) {
    }
    return false;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) SimpleName(org.eclipse.jdt.core.dom.SimpleName) ITypeParameter(org.eclipse.jdt.core.ITypeParameter) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name) TextElement(org.eclipse.jdt.core.dom.TextElement) ASTNode(org.eclipse.jdt.core.dom.ASTNode) TagElement(org.eclipse.jdt.core.dom.TagElement) List(java.util.List) ArrayList(java.util.ArrayList)

Example 72 with TagElement

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

the class JavadocContentAccess2 method getExceptionDescription.

CharSequence getExceptionDescription(String simpleName) {
    if (fMethod != null) {
        if (fExceptionDescriptions == null) {
            fExceptionDescriptions = new HashMap<>();
        } else {
            StringBuffer description = fExceptionDescriptions.get(simpleName);
            if (description != null) {
                return description.length() > 0 ? description : null;
            }
        }
        StringBuffer description = new StringBuffer();
        fExceptionDescriptions.put(simpleName, description);
        fBuf = description;
        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_THROWS.equals(tagName) || TagElement.TAG_EXCEPTION.equals(tagName)) {
                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);
                        if (name.equals(simpleName)) {
                            if (fragments.size() > 1) {
                                handleContentElements(fragments.subList(1, fragments.size()));
                            }
                            break;
                        }
                    }
                }
            }
        }
        fBuf = null;
        return description.length() > 0 ? description : null;
    }
    return null;
}
Also used : TagElement(org.eclipse.jdt.core.dom.TagElement) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name)

Example 73 with TagElement

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

the class JavadocContentAccess2 method handleParameterTags.

private void handleParameterTags(List<TagElement> tags, List<String> parameterNames, CharSequence[] parameterDescriptions, boolean isTypeParameters) {
    if (tags.size() == 0 && containsOnlyNull(parameterNames)) {
        return;
    }
    String tagTitle = isTypeParameters ? JavaDoc2HTMLTextReader_type_parameters_section : JavaDoc2HTMLTextReader_parameters_section;
    handleBlockTagTitle(tagTitle);
    for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext(); ) {
        TagElement tag = iter.next();
        fBuf.append(BLOCK_TAG_START);
        fBuf.append(BlOCK_TAG_ENTRY_START);
        handleParamTag(tag);
        fBuf.append(BlOCK_TAG_ENTRY_END);
        fBuf.append(BLOCK_TAG_END);
    }
    for (int i = 0; i < parameterDescriptions.length; i++) {
        CharSequence description = parameterDescriptions[i];
        String name = parameterNames.get(i);
        if (name != null) {
            fBuf.append(BLOCK_TAG_START);
            fBuf.append(BlOCK_TAG_ENTRY_START);
            fBuf.append(PARAM_NAME_START);
            if (isTypeParameters) {
                // $NON-NLS-1$
                fBuf.append("&lt;");
            }
            fBuf.append(name);
            if (isTypeParameters) {
                // $NON-NLS-1$
                fBuf.append("&gt;");
            }
            fBuf.append(PARAM_NAME_END);
            if (description != null) {
                fBuf.append(description);
            }
            fBuf.append(BlOCK_TAG_ENTRY_END);
            fBuf.append(BLOCK_TAG_END);
        }
    }
    fBuf.append(BlOCK_TAG_ENTRY_END);
}
Also used : TagElement(org.eclipse.jdt.core.dom.TagElement)

Example 74 with TagElement

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

the class JavadocContentAccess2 method getInheritedParamDescription.

CharSequence getInheritedParamDescription(int paramIndex) throws JavaModelException {
    if (fMethod != null) {
        String[] parameterNames = fMethod.getParameterNames();
        if (fParamDescriptions == null) {
            fParamDescriptions = new StringBuffer[parameterNames.length];
        } else {
            StringBuffer description = fParamDescriptions[paramIndex];
            if (description != null) {
                return description.length() > 0 ? description : null;
            }
        }
        StringBuffer description = new StringBuffer();
        fParamDescriptions[paramIndex] = description;
        fBuf = description;
        fLiteralContent = 0;
        String paramName = parameterNames[paramIndex];
        List<TagElement> tags = fJavadoc.tags();
        for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext(); ) {
            TagElement tag = iter.next();
            String tagName = tag.getTagName();
            if (TagElement.TAG_PARAM.equals(tagName)) {
                List<? extends ASTNode> fragments = tag.fragments();
                if (fragments.size() > 0) {
                    Object first = fragments.get(0);
                    if (first instanceof SimpleName) {
                        String name = ((SimpleName) first).getIdentifier();
                        if (name.equals(paramName)) {
                            handleContentElements(fragments.subList(1, fragments.size()));
                            break;
                        }
                    }
                }
            }
        }
        fBuf = null;
        return description.length() > 0 ? description : null;
    }
    return null;
}
Also used : SimpleName(org.eclipse.jdt.core.dom.SimpleName) TagElement(org.eclipse.jdt.core.dom.TagElement)

Example 75 with TagElement

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

the class JavadocContentAccess2 method handleExceptionTags.

private void handleExceptionTags(List<TagElement> tags, List<String> exceptionNames, CharSequence[] exceptionDescriptions) {
    if (tags.size() == 0 && containsOnlyNull(exceptionNames)) {
        return;
    }
    handleBlockTagTitle(JavaDoc2HTMLTextReader_throws_section);
    fBuf.append(BLOCK_TAG_START);
    for (Iterator<TagElement> iter = tags.iterator(); iter.hasNext(); ) {
        TagElement tag = iter.next();
        fBuf.append(BlOCK_TAG_ENTRY_START);
        handleThrowsTag(tag);
        fBuf.append(BlOCK_TAG_ENTRY_END);
    }
    for (int i = 0; i < exceptionDescriptions.length; i++) {
        CharSequence description = exceptionDescriptions[i];
        String name = exceptionNames.get(i);
        if (name != null) {
            fBuf.append(BlOCK_TAG_ENTRY_START);
            handleLink(Collections.singletonList(fJavadoc.getAST().newSimpleName(name)));
            if (description != null) {
                fBuf.append(JavaElementLabels.CONCAT_STRING);
                fBuf.append(description);
            }
            fBuf.append(BlOCK_TAG_ENTRY_END);
        }
    }
    fBuf.append(BLOCK_TAG_END);
    fBuf.append(BlOCK_TAG_ENTRY_END);
}
Also used : TagElement(org.eclipse.jdt.core.dom.TagElement)

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