src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/links/LinkFactory.java
changeset 48759 ffa68af7da87
parent 47233 5ee94c2e087e
child 50810 0358dad944c7
equal deleted inserted replaced
48758:ba19a21d727d 48759:ffa68af7da87
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    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;
    28 import java.util.ArrayList;
    29 import java.util.List;
    29 import java.util.List;
    30 
    30 
    31 import javax.lang.model.element.AnnotationMirror;
       
    32 import javax.lang.model.element.Element;
    31 import javax.lang.model.element.Element;
    33 import javax.lang.model.element.TypeElement;
    32 import javax.lang.model.element.TypeElement;
    34 import javax.lang.model.element.TypeParameterElement;
    33 import javax.lang.model.element.TypeParameterElement;
    35 import javax.lang.model.type.ArrayType;
    34 import javax.lang.model.type.ArrayType;
    36 import javax.lang.model.type.DeclaredType;
    35 import javax.lang.model.type.DeclaredType;
    37 import javax.lang.model.type.TypeMirror;
    36 import javax.lang.model.type.TypeMirror;
    38 import javax.lang.model.type.TypeVariable;
    37 import javax.lang.model.type.TypeVariable;
    39 import javax.lang.model.type.WildcardType;
    38 import javax.lang.model.type.WildcardType;
    40 import javax.lang.model.util.SimpleTypeVisitor9;
    39 import javax.lang.model.util.SimpleTypeVisitor9;
    41 
    40 
    42 import jdk.javadoc.internal.doclets.formats.html.LinkInfoImpl;
       
    43 import jdk.javadoc.internal.doclets.toolkit.Content;
    41 import jdk.javadoc.internal.doclets.toolkit.Content;
    44 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
    42 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
    45 
    43 
    46 /**
    44 /**
    47  * A factory that constructs links from given link information.
    45  * A factory that constructs links from given link information.
    52  *  deletion without notice.</b>
    50  *  deletion without notice.</b>
    53  *
    51  *
    54  * @author Jamie Ho
    52  * @author Jamie Ho
    55  */
    53  */
    56 public abstract class LinkFactory {
    54 public abstract class LinkFactory {
       
    55     protected final Utils utils;
       
    56 
       
    57     protected LinkFactory(Utils utils) {
       
    58         this.utils = utils;
       
    59     }
    57 
    60 
    58     /**
    61     /**
    59      * Return an empty instance of a content object.
    62      * Return an empty instance of a content object.
    60      *
    63      *
    61      * @return an empty instance of a content object.
    64      * @return an empty instance of a content object.
    67      *
    70      *
    68      * @param linkInfo the information about the link.
    71      * @param linkInfo the information about the link.
    69      * @return the output of the link.
    72      * @return the output of the link.
    70      */
    73      */
    71     public Content getLink(LinkInfo linkInfo) {
    74     public Content getLink(LinkInfo linkInfo) {
    72         Utils utils = ((LinkInfoImpl) linkInfo).configuration.utils;
       
    73         if (linkInfo.type != null) {
    75         if (linkInfo.type != null) {
    74             SimpleTypeVisitor9<Content, LinkInfo> linkVisitor =
    76             SimpleTypeVisitor9<Content, LinkInfo> linkVisitor =
    75                     new SimpleTypeVisitor9<Content, LinkInfo>() {
    77                     new SimpleTypeVisitor9<Content, LinkInfo>() {
    76 
    78 
    77                 TypeMirror componentType = utils.getComponentType(linkInfo.type);
    79                 TypeMirror componentType = utils.getComponentType(linkInfo.type);
   205         linkInfo.label = null;
   207         linkInfo.label = null;
   206         linkInfo.type = bound;
   208         linkInfo.type = bound;
   207     }
   209     }
   208 
   210 
   209     /**
   211     /**
   210      * Return the link to the given class.
   212      * Returns a link to the given class.
   211      *
   213      *
   212      * @param linkInfo the information about the link to construct.
   214      * @param linkInfo the information about the link to construct
   213      *
   215      *
   214      * @return the link for the given class.
   216      * @return the link for the given class.
   215      */
   217      */
   216     protected abstract Content getClassLink(LinkInfo linkInfo);
   218     protected abstract Content getClassLink(LinkInfo linkInfo);
   217 
   219 
   218     /**
   220     /**
   219      * Return the link to the given type parameter.
   221      * Returns a link to the given type parameter.
   220      *
   222      *
   221      * @param linkInfo     the information about the link to construct.
   223      * @param linkInfo     the information about the link to construct
   222      * @param typeParam the type parameter to link to.
   224      * @param typeParam the type parameter to link to
       
   225      * @return the link
   223      */
   226      */
   224     protected abstract Content getTypeParameterLink(LinkInfo linkInfo, TypeMirror typeParam);
   227     protected abstract Content getTypeParameterLink(LinkInfo linkInfo, TypeMirror typeParam);
   225 
   228 
   226     /**
   229     /**
   227      * Return the links to the type parameters.
   230      * Returns links to the type parameters.
   228      *
   231      *
   229      * @param linkInfo     the information about the link to construct.
   232      * @param linkInfo     the information about the link to construct
   230      * @return the links to the type parameters.
   233      * @return the links to the type parameters.
   231      */
   234      */
   232     public Content getTypeParameterLinks(LinkInfo linkInfo) {
   235     public Content getTypeParameterLinks(LinkInfo linkInfo) {
   233         return getTypeParameterLinks(linkInfo, true);
   236         return getTypeParameterLinks(linkInfo, true);
   234     }
   237     }
   235 
   238 
   236     /**
   239     /**
   237      * Return the links to the type parameters.
   240      * Returns links to the type parameters.
   238      *
   241      *
   239      * @param linkInfo     the information about the link to construct.
   242      * @param linkInfo     the information about the link to construct
   240      * @param isClassLabel true if this is a class label.  False if it is
   243      * @param isClassLabel true if this is a class label, or false if it is
   241      *                     the type parameters portion of the link.
   244      *                     the type parameters portion of the link
   242      * @return the links to the type parameters.
   245      * @return the links to the type parameters
   243      */
   246      */
   244     public Content getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) {
   247     public Content getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) {
   245         Utils utils = ((LinkInfoImpl)linkInfo).utils;
       
   246         Content links = newContent();
   248         Content links = newContent();
   247         List<TypeMirror> vars = new ArrayList<>();
   249         List<TypeMirror> vars = new ArrayList<>();
   248         TypeMirror ctype = linkInfo.type != null
   250         TypeMirror ctype = linkInfo.type != null
   249                 ? utils.getComponentType(linkInfo.type)
   251                 ? utils.getComponentType(linkInfo.type)
   250                 : null;
   252                 : null;