1 /*
   2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.javadoc.internal.doclets.toolkit.util.links;
  27 
  28 import javax.lang.model.element.ExecutableElement;
  29 import javax.lang.model.element.TypeElement;
  30 import javax.lang.model.type.TypeMirror;
  31 
  32 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
  33 import jdk.javadoc.internal.doclets.toolkit.Content;
  34 
  35 /**
  36  *  Encapsulates information about a link.
  37  *
  38  *  <p><b>This is NOT part of any supported API.
  39  *  If you write code that depends on this, you do so at your own risk.
  40  *  This code and its internal interfaces are subject to change or
  41  *  deletion without notice.</b>
  42  *
  43  *  @author Jamie Ho
  44  */
  45 public abstract class LinkInfo {
  46 
  47     /**
  48      * The class we want to link to.  Null if we are not linking
  49      * to a class.
  50      */
  51     public TypeElement typeElement;
  52 
  53     /**
  54      * The executable element we want to link to.  Null if we are not linking
  55      * to an executable element.
  56      */
  57     public ExecutableElement executableElement;
  58 
  59     /**
  60      * The Type we want to link to.  Null if we are not linking to a type.
  61      */
  62     public TypeMirror type;
  63 
  64     /**
  65      * True if this is a link to a VarArg.
  66      */
  67     public boolean isVarArg = false;
  68 
  69     /**
  70      * Set this to true to indicate that you are linking to a type parameter.
  71      */
  72     public boolean isTypeBound = false;
  73 
  74     /**
  75      * The label for the link.
  76      */
  77     public Content label;
  78 
  79     /**
  80      * True if the link should be strong.
  81      */
  82     public boolean isStrong = false;
  83 
  84     /**
  85      * True if we should include the type in the link label.  False otherwise.
  86      */
  87     public boolean includeTypeInClassLinkLabel = true;
  88 
  89     /**
  90      * True if we should include the type as separate link.  False otherwise.
  91      */
  92     public boolean includeTypeAsSepLink = false;
  93 
  94     /**
  95      * True if we should exclude the type bounds for the type parameter.
  96      */
  97     public boolean excludeTypeBounds = false;
  98 
  99     /**
 100      * True if we should print the type parameters, but not link them.
 101      */
 102     public boolean excludeTypeParameterLinks = false;
 103 
 104     /**
 105      * True if we should print the type bounds, but not link them.
 106      */
 107     public boolean excludeTypeBoundsLinks = false;
 108 
 109     /**
 110      * By default, the link can be to the page it's already on.  However,
 111      * there are cases where we don't want this (e.g. heading of class page).
 112      */
 113     public boolean linkToSelf = true;
 114 
 115     /**
 116      * Return an empty instance of a content object.
 117      *
 118      * @return an empty instance of a content object.
 119      */
 120     protected abstract Content newContent();
 121 
 122     /**
 123      * Return true if this link is linkable and false if we can't link to the
 124      * desired place.
 125      *
 126      * @return true if this link is linkable and false if we can't link to the
 127      * desired place.
 128      */
 129     public abstract boolean isLinkable();
 130 
 131     /**
 132      * Return the label for this class link.
 133      *
 134      * @param configuration the current configuration of the doclet.
 135      * @return the label for this class link.
 136      */
 137     public Content getClassLinkLabel(BaseConfiguration configuration) {
 138         if (label != null && !label.isEmpty()) {
 139             return label;
 140         } else if (isLinkable()) {
 141             Content tlabel = newContent();
 142             tlabel.add(configuration.utils.getSimpleName(typeElement));
 143             return tlabel;
 144         } else {
 145             Content tlabel = newContent();
 146             tlabel.add(configuration.getClassName(typeElement));
 147             return tlabel;
 148         }
 149     }
 150 
 151     @Override
 152     public String toString() {
 153         return "LinkInfo{" + "typeElement=" + typeElement +
 154                 ", executableElement=" + executableElement +
 155                 ", type=" + type +
 156                 ", isVarArg=" + isVarArg +
 157                 ", isTypeBound=" + isTypeBound +
 158                 ", label=" + label +
 159                 ", isStrong=" + isStrong +
 160                 ", includeTypeInClassLinkLabel=" + includeTypeInClassLinkLabel +
 161                 ", includeTypeAsSepLink=" + includeTypeAsSepLink +
 162                 ", excludeTypeBounds=" + excludeTypeBounds +
 163                 ", excludeTypeParameterLinks=" + excludeTypeParameterLinks +
 164                 ", excludeTypeBoundsLinks=" + excludeTypeBoundsLinks +
 165                 ", linkToSelf=" + linkToSelf + '}';
 166     }
 167 }