1 /*
   2  * Copyright (c) 2003, 2014, 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 com.sun.tools.doclets.formats.html;
  27 
  28 import com.sun.javadoc.*;
  29 import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
  30 import com.sun.tools.doclets.formats.html.markup.StringContent;
  31 import com.sun.tools.doclets.internal.toolkit.Content;
  32 import com.sun.tools.doclets.internal.toolkit.util.links.*;
  33 
  34 /**
  35  *  <p><b>This is NOT part of any supported API.
  36  *  If you write code that depends on this, you do so at your own risk.
  37  *  This code and its internal interfaces are subject to change or
  38  *  deletion without notice.</b>
  39  */
  40 public class LinkInfoImpl extends LinkInfo {
  41 
  42     public enum Kind {
  43         DEFAULT,
  44 
  45         /**
  46          * Indicate that the link appears in a class list.
  47          */
  48         ALL_CLASSES_FRAME,
  49 
  50         /**
  51          * Indicate that the link appears in a class documentation.
  52          */
  53         CLASS,
  54 
  55         /**
  56          * Indicate that the link appears in member documentation.
  57          */
  58         MEMBER,
  59 
  60         /**
  61          * Indicate that the link appears in class use documentation.
  62          */
  63         CLASS_USE,
  64 
  65         /**
  66          * Indicate that the link appears in index documentation.
  67          */
  68         INDEX,
  69 
  70         /**
  71          * Indicate that the link appears in constant value summary.
  72          */
  73         CONSTANT_SUMMARY,
  74 
  75         /**
  76          * Indicate that the link appears in serialized form documentation.
  77          */
  78         SERIALIZED_FORM,
  79 
  80         /**
  81          * Indicate that the link appears in serial member documentation.
  82          */
  83         SERIAL_MEMBER,
  84 
  85         /**
  86          * Indicate that the link appears in package documentation.
  87          */
  88         PACKAGE,
  89 
  90         /**
  91          * Indicate that the link appears in see tag documentation.
  92          */
  93         SEE_TAG,
  94 
  95         /**
  96          * Indicate that the link appears in value tag documentation.
  97          */
  98         VALUE_TAG,
  99 
 100         /**
 101          * Indicate that the link appears in tree documentation.
 102          */
 103         TREE,
 104 
 105         /**
 106          * Indicate that the link appears in a class list.
 107          */
 108         PACKAGE_FRAME,
 109 
 110         /**
 111          * The header in the class documentation.
 112          */
 113         CLASS_HEADER,
 114 
 115         /**
 116          * The signature in the class documentation.
 117          */
 118         CLASS_SIGNATURE,
 119 
 120         /**
 121          * The return type of a method.
 122          */
 123         RETURN_TYPE,
 124 
 125         /**
 126          * The return type of a method in a member summary.
 127          */
 128         SUMMARY_RETURN_TYPE,
 129 
 130         /**
 131          * The type of a method/constructor parameter.
 132          */
 133         EXECUTABLE_MEMBER_PARAM,
 134 
 135         /**
 136          * Super interface links.
 137          */
 138         SUPER_INTERFACES,
 139 
 140         /**
 141          * Implemented interface links.
 142          */
 143         IMPLEMENTED_INTERFACES,
 144 
 145         /**
 146          * Implemented class links.
 147          */
 148         IMPLEMENTED_CLASSES,
 149 
 150         /**
 151          * Subinterface links.
 152          */
 153         SUBINTERFACES,
 154 
 155         /**
 156          * Subclasses links.
 157          */
 158         SUBCLASSES,
 159 
 160         /**
 161          * The signature in the class documentation (implements/extends portion).
 162          */
 163         CLASS_SIGNATURE_PARENT_NAME,
 164 
 165         /**
 166          * The header for method documentation copied from parent.
 167          */
 168         METHOD_DOC_COPY,
 169 
 170         /**
 171          * Method "specified by" link.
 172          */
 173         METHOD_SPECIFIED_BY,
 174 
 175         /**
 176          * Method "overrides" link.
 177          */
 178         METHOD_OVERRIDES,
 179 
 180         /**
 181          * Annotation link.
 182          */
 183         ANNOTATION,
 184 
 185         /**
 186          * The header for field documentation copied from parent.
 187          */
 188         FIELD_DOC_COPY,
 189 
 190         /**
 191          * The parent nodes in the class tree.
 192          */
 193         CLASS_TREE_PARENT,
 194 
 195         /**
 196          * The type parameters of a method or constructor.
 197          */
 198         MEMBER_TYPE_PARAMS,
 199 
 200         /**
 201          * Indicate that the link appears in class use documentation.
 202          */
 203         CLASS_USE_HEADER,
 204 
 205         /**
 206          * The header for property documentation copied from parent.
 207          */
 208         PROPERTY_DOC_COPY
 209     }
 210 
 211     public final ConfigurationImpl configuration;
 212 
 213     /**
 214      * The location of the link.
 215      */
 216     public Kind context = Kind.DEFAULT;
 217 
 218     /**
 219      * The value of the marker #.
 220      */
 221     public String where = "";
 222 
 223     /**
 224      * String style of text defined in style sheet.
 225      */
 226     public String styleName = "";
 227 
 228     /**
 229      * The value of the target.
 230      */
 231     public String target = "";
 232 
 233     /**
 234      * Construct a LinkInfo object.
 235      *
 236      * @param configuration the configuration data for the doclet
 237      * @param context    the context of the link.
 238      * @param context               the context of the link.
 239      * @param executableMemberDoc   the member to link to.
 240      */
 241     public LinkInfoImpl(ConfigurationImpl configuration,
 242             Kind context, ExecutableMemberDoc executableMemberDoc) {
 243         this.configuration = configuration;
 244         this.executableMemberDoc = executableMemberDoc;
 245         setContext(context);
 246     }
 247 
 248     /**
 249      * {@inheritDoc}
 250      */
 251     protected Content newContent() {
 252         return new ContentBuilder();
 253     }
 254 
 255     /**
 256      * Construct a LinkInfo object.
 257      *
 258      * @param configuration the configuration data for the doclet
 259      * @param context    the context of the link.
 260      * @param classDoc   the class to link to.
 261      */
 262     public LinkInfoImpl(ConfigurationImpl configuration,
 263             Kind context, ClassDoc classDoc) {
 264         this.configuration = configuration;
 265         this.classDoc = classDoc;
 266         setContext(context);
 267     }
 268 
 269     /**
 270      * Construct a LinkInfo object.
 271      *
 272      * @param configuration the configuration data for the doclet
 273      * @param context    the context of the link.
 274      * @param type       the class to link to.
 275      */
 276     public LinkInfoImpl(ConfigurationImpl configuration,
 277             Kind context, Type type) {
 278         this.configuration = configuration;
 279         this.type = type;
 280         setContext(context);
 281     }
 282 
 283 
 284     /**
 285      * Set the label for the link.
 286      * @param label plain-text label for the link
 287      */
 288     public LinkInfoImpl label(String label) {
 289         this.label = new StringContent(label);
 290         return this;
 291     }
 292 
 293     /**
 294      * Set the label for the link.
 295      */
 296     public LinkInfoImpl label(Content label) {
 297         this.label = label;
 298         return this;
 299     }
 300 
 301     /**
 302      * Set whether or not the link should be strong.
 303      */
 304     public LinkInfoImpl strong(boolean strong) {
 305         this.isStrong = strong;
 306         return this;
 307     }
 308 
 309     /**
 310      * Set the style to be used for the link.
 311      * @param styleName  String style of text defined in style sheet.
 312      */
 313     public LinkInfoImpl styleName(String styleName) {
 314         this.styleName = styleName;
 315         return this;
 316     }
 317 
 318     /**
 319      * Set the target to be used for the link.
 320      * @param styleName  String style of text defined in style sheet.
 321      */
 322     public LinkInfoImpl target(String target) {
 323         this.target = target;
 324         return this;
 325     }
 326 
 327     /**
 328      * Set whether or not this is a link to a varargs parameter.
 329      */
 330     public LinkInfoImpl varargs(boolean varargs) {
 331         this.isVarArg = varargs;
 332         return this;
 333     }
 334 
 335     /**
 336      * Set the fragment specifier for the link.
 337      */
 338     public LinkInfoImpl where(String where) {
 339         this.where = where;
 340         return this;
 341      }
 342 
 343     /**
 344      * {@inheritDoc}
 345      */
 346     public Kind getContext() {
 347         return context;
 348     }
 349 
 350     /**
 351      * {@inheritDoc}
 352      *
 353      * This method sets the link attributes to the appropriate values
 354      * based on the context.
 355      *
 356      * @param c the context id to set.
 357      */
 358     public final void setContext(Kind c) {
 359         //NOTE:  Put context specific link code here.
 360         switch (c) {
 361             case ALL_CLASSES_FRAME:
 362             case PACKAGE_FRAME:
 363             case IMPLEMENTED_CLASSES:
 364             case SUBCLASSES:
 365             case METHOD_DOC_COPY:
 366             case FIELD_DOC_COPY:
 367             case PROPERTY_DOC_COPY:
 368             case CLASS_USE_HEADER:
 369                 includeTypeInClassLinkLabel = false;
 370                 break;
 371 
 372             case ANNOTATION:
 373                 excludeTypeParameterLinks = true;
 374                 excludeTypeBounds = true;
 375                 break;
 376 
 377             case IMPLEMENTED_INTERFACES:
 378             case SUPER_INTERFACES:
 379             case SUBINTERFACES:
 380             case CLASS_TREE_PARENT:
 381             case TREE:
 382             case CLASS_SIGNATURE_PARENT_NAME:
 383                 excludeTypeParameterLinks = true;
 384                 excludeTypeBounds = true;
 385                 includeTypeInClassLinkLabel = false;
 386                 includeTypeAsSepLink = true;
 387                 break;
 388 
 389             case PACKAGE:
 390             case CLASS_USE:
 391             case CLASS_HEADER:
 392             case CLASS_SIGNATURE:
 393                 excludeTypeParameterLinks = true;
 394                 includeTypeAsSepLink = true;
 395                 includeTypeInClassLinkLabel = false;
 396                 break;
 397 
 398             case MEMBER_TYPE_PARAMS:
 399                 includeTypeAsSepLink = true;
 400                 includeTypeInClassLinkLabel = false;
 401                 break;
 402 
 403             case RETURN_TYPE:
 404             case SUMMARY_RETURN_TYPE:
 405                 excludeTypeBounds = true;
 406                 break;
 407             case EXECUTABLE_MEMBER_PARAM:
 408                 excludeTypeBounds = true;
 409                 break;
 410         }
 411         context = c;
 412         if (type != null &&
 413             type.asTypeVariable()!= null &&
 414             type.asTypeVariable().owner() instanceof ExecutableMemberDoc) {
 415             excludeTypeParameterLinks = true;
 416         }
 417     }
 418 
 419     /**
 420      * Return true if this link is linkable and false if we can't link to the
 421      * desired place.
 422      *
 423      * @return true if this link is linkable and false if we can't link to the
 424      * desired place.
 425      */
 426     public boolean isLinkable() {
 427         return configuration.utils.isLinkable(classDoc, configuration);
 428     }
 429 }