src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/links/LinkFactory.java
changeset 50810 0358dad944c7
parent 48759 ffa68af7da87
child 54060 53a95878619f
equal deleted inserted replaced
50809:6ff774d73176 50810:0358dad944c7
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package jdk.javadoc.internal.doclets.toolkit.util.links;
    26 package jdk.javadoc.internal.doclets.toolkit.util.links;
    27 
    27 
    28 import java.util.ArrayList;
       
    29 import java.util.List;
    28 import java.util.List;
    30 
    29 
    31 import javax.lang.model.element.Element;
    30 import javax.lang.model.element.Element;
    32 import javax.lang.model.element.TypeElement;
    31 import javax.lang.model.element.TypeElement;
    33 import javax.lang.model.element.TypeParameterElement;
    32 import javax.lang.model.element.TypeParameterElement;
   216      * @return the link for the given class.
   215      * @return the link for the given class.
   217      */
   216      */
   218     protected abstract Content getClassLink(LinkInfo linkInfo);
   217     protected abstract Content getClassLink(LinkInfo linkInfo);
   219 
   218 
   220     /**
   219     /**
   221      * Returns a link to the given type parameter.
       
   222      *
       
   223      * @param linkInfo     the information about the link to construct
       
   224      * @param typeParam the type parameter to link to
       
   225      * @return the link
       
   226      */
       
   227     protected abstract Content getTypeParameterLink(LinkInfo linkInfo, TypeMirror typeParam);
       
   228 
       
   229     /**
       
   230      * Returns links to the type parameters.
       
   231      *
       
   232      * @param linkInfo     the information about the link to construct
       
   233      * @return the links to the type parameters.
       
   234      */
       
   235     public Content getTypeParameterLinks(LinkInfo linkInfo) {
       
   236         return getTypeParameterLinks(linkInfo, true);
       
   237     }
       
   238 
       
   239     /**
       
   240      * Returns links to the type parameters.
   220      * Returns links to the type parameters.
   241      *
   221      *
   242      * @param linkInfo     the information about the link to construct
   222      * @param linkInfo     the information about the link to construct
   243      * @param isClassLabel true if this is a class label, or false if it is
   223      * @param isClassLabel true if this is a class label, or false if it is
   244      *                     the type parameters portion of the link
   224      *                     the type parameters portion of the link
   245      * @return the links to the type parameters
   225      * @return the links to the type parameters
   246      */
   226      */
   247     public Content getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) {
   227     protected abstract Content getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel);
   248         Content links = newContent();
   228 
   249         List<TypeMirror> vars = new ArrayList<>();
   229     /**
   250         TypeMirror ctype = linkInfo.type != null
   230      * Returns links to the type parameters.
   251                 ? utils.getComponentType(linkInfo.type)
   231      *
   252                 : null;
   232      * @param linkInfo     the information about the link to construct
   253         if (linkInfo.executableElement != null) {
   233      * @return the links to the type parameters.
   254             linkInfo.executableElement.getTypeParameters().stream().forEach((t) -> {
   234      */
   255                 vars.add(t.asType());
   235     public Content getTypeParameterLinks(LinkInfo linkInfo) {
   256             });
   236         return getTypeParameterLinks(linkInfo, true);
   257         } else if (linkInfo.type != null && utils.isDeclaredType(linkInfo.type)) {
       
   258             ((DeclaredType)linkInfo.type).getTypeArguments().stream().forEach(vars::add);
       
   259         } else if (ctype != null && utils.isDeclaredType(ctype)) {
       
   260             ((DeclaredType)ctype).getTypeArguments().stream().forEach(vars::add);
       
   261         } else if (linkInfo.typeElement != null) {
       
   262             linkInfo.typeElement.getTypeParameters().stream().forEach((t) -> {
       
   263                 vars.add(t.asType());
       
   264             });
       
   265         } else {
       
   266             // Nothing to document.
       
   267             return links;
       
   268         }
       
   269         if (((linkInfo.includeTypeInClassLinkLabel && isClassLabel)
       
   270                 || (linkInfo.includeTypeAsSepLink && !isClassLabel)) && !vars.isEmpty()) {
       
   271             links.addContent("<");
       
   272             boolean many = false;
       
   273             for (TypeMirror t : vars) {
       
   274                 if (many) {
       
   275                     links.addContent(",");
       
   276                 }
       
   277                 links.addContent(getTypeParameterLink(linkInfo, t));
       
   278                 many = true;
       
   279             }
       
   280             links.addContent(">");
       
   281         }
       
   282         return links;
       
   283     }
   237     }
   284 
   238 
   285     public abstract Content getTypeAnnotationLinks(LinkInfo linkInfo);
   239     public abstract Content getTypeAnnotationLinks(LinkInfo linkInfo);
   286 }
   240 }