1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/LinkInfoImpl.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,431 @@ 1.4 +/* 1.5 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 + 1.30 +package com.sun.tools.doclets.formats.html; 1.31 + 1.32 +import com.sun.javadoc.*; 1.33 +import com.sun.tools.doclets.formats.html.markup.ContentBuilder; 1.34 +import com.sun.tools.doclets.formats.html.markup.StringContent; 1.35 +import com.sun.tools.doclets.internal.toolkit.Content; 1.36 +import com.sun.tools.doclets.internal.toolkit.util.*; 1.37 +import com.sun.tools.doclets.internal.toolkit.util.links.*; 1.38 + 1.39 +/** 1.40 + * <p><b>This is NOT part of any supported API. 1.41 + * If you write code that depends on this, you do so at your own risk. 1.42 + * This code and its internal interfaces are subject to change or 1.43 + * deletion without notice.</b> 1.44 + */ 1.45 +public class LinkInfoImpl extends LinkInfo { 1.46 + 1.47 + public enum Kind { 1.48 + DEFAULT, 1.49 + 1.50 + /** 1.51 + * Indicate that the link appears in a class list. 1.52 + */ 1.53 + ALL_CLASSES_FRAME, 1.54 + 1.55 + /** 1.56 + * Indicate that the link appears in a class documentation. 1.57 + */ 1.58 + CLASS, 1.59 + 1.60 + /** 1.61 + * Indicate that the link appears in member documentation. 1.62 + */ 1.63 + MEMBER, 1.64 + 1.65 + /** 1.66 + * Indicate that the link appears in class use documentation. 1.67 + */ 1.68 + CLASS_USE, 1.69 + 1.70 + /** 1.71 + * Indicate that the link appears in index documentation. 1.72 + */ 1.73 + INDEX, 1.74 + 1.75 + /** 1.76 + * Indicate that the link appears in constant value summary. 1.77 + */ 1.78 + CONSTANT_SUMMARY, 1.79 + 1.80 + /** 1.81 + * Indicate that the link appears in serialized form documentation. 1.82 + */ 1.83 + SERIALIZED_FORM, 1.84 + 1.85 + /** 1.86 + * Indicate that the link appears in serial member documentation. 1.87 + */ 1.88 + SERIAL_MEMBER, 1.89 + 1.90 + /** 1.91 + * Indicate that the link appears in package documentation. 1.92 + */ 1.93 + PACKAGE, 1.94 + 1.95 + /** 1.96 + * Indicate that the link appears in see tag documentation. 1.97 + */ 1.98 + SEE_TAG, 1.99 + 1.100 + /** 1.101 + * Indicate that the link appears in value tag documentation. 1.102 + */ 1.103 + VALUE_TAG, 1.104 + 1.105 + /** 1.106 + * Indicate that the link appears in tree documentation. 1.107 + */ 1.108 + TREE, 1.109 + 1.110 + /** 1.111 + * Indicate that the link appears in a class list. 1.112 + */ 1.113 + PACKAGE_FRAME, 1.114 + 1.115 + /** 1.116 + * The header in the class documentation. 1.117 + */ 1.118 + CLASS_HEADER, 1.119 + 1.120 + /** 1.121 + * The signature in the class documentation. 1.122 + */ 1.123 + CLASS_SIGNATURE, 1.124 + 1.125 + /** 1.126 + * The return type of a method. 1.127 + */ 1.128 + RETURN_TYPE, 1.129 + 1.130 + /** 1.131 + * The return type of a method in a member summary. 1.132 + */ 1.133 + SUMMARY_RETURN_TYPE, 1.134 + 1.135 + /** 1.136 + * The type of a method/constructor parameter. 1.137 + */ 1.138 + EXECUTABLE_MEMBER_PARAM, 1.139 + 1.140 + /** 1.141 + * Super interface links. 1.142 + */ 1.143 + SUPER_INTERFACES, 1.144 + 1.145 + /** 1.146 + * Implemented interface links. 1.147 + */ 1.148 + IMPLEMENTED_INTERFACES, 1.149 + 1.150 + /** 1.151 + * Implemented class links. 1.152 + */ 1.153 + IMPLEMENTED_CLASSES, 1.154 + 1.155 + /** 1.156 + * Subinterface links. 1.157 + */ 1.158 + SUBINTERFACES, 1.159 + 1.160 + /** 1.161 + * Subclasses links. 1.162 + */ 1.163 + SUBCLASSES, 1.164 + 1.165 + /** 1.166 + * The signature in the class documentation (implements/extends portion). 1.167 + */ 1.168 + CLASS_SIGNATURE_PARENT_NAME, 1.169 + 1.170 + /** 1.171 + * The header for method documentation copied from parent. 1.172 + */ 1.173 + METHOD_DOC_COPY, 1.174 + 1.175 + /** 1.176 + * Method "specified by" link. 1.177 + */ 1.178 + METHOD_SPECIFIED_BY, 1.179 + 1.180 + /** 1.181 + * Method "overrides" link. 1.182 + */ 1.183 + METHOD_OVERRIDES, 1.184 + 1.185 + /** 1.186 + * Annotation link. 1.187 + */ 1.188 + ANNOTATION, 1.189 + 1.190 + /** 1.191 + * The header for field documentation copied from parent. 1.192 + */ 1.193 + FIELD_DOC_COPY, 1.194 + 1.195 + /** 1.196 + * The parent nodes in the class tree. 1.197 + */ 1.198 + CLASS_TREE_PARENT, 1.199 + 1.200 + /** 1.201 + * The type parameters of a method or constructor. 1.202 + */ 1.203 + MEMBER_TYPE_PARAMS, 1.204 + 1.205 + /** 1.206 + * Indicate that the link appears in class use documentation. 1.207 + */ 1.208 + CLASS_USE_HEADER, 1.209 + 1.210 + /** 1.211 + * The header for property documentation copied from parent. 1.212 + */ 1.213 + PROPERTY_DOC_COPY 1.214 + } 1.215 + 1.216 + public final ConfigurationImpl configuration; 1.217 + 1.218 + /** 1.219 + * The location of the link. 1.220 + */ 1.221 + public Kind context = Kind.DEFAULT; 1.222 + 1.223 + /** 1.224 + * The value of the marker #. 1.225 + */ 1.226 + public String where = ""; 1.227 + 1.228 + /** 1.229 + * String style of text defined in style sheet. 1.230 + */ 1.231 + public String styleName = ""; 1.232 + 1.233 + /** 1.234 + * The value of the target. 1.235 + */ 1.236 + public String target = ""; 1.237 + 1.238 + /** 1.239 + * Construct a LinkInfo object. 1.240 + * 1.241 + * @param configuration the configuration data for the doclet 1.242 + * @param context the context of the link. 1.243 + * @param context the context of the link. 1.244 + * @param executableMemberDoc the member to link to. 1.245 + */ 1.246 + public LinkInfoImpl(ConfigurationImpl configuration, 1.247 + Kind context, ExecutableMemberDoc executableMemberDoc) { 1.248 + this.configuration = configuration; 1.249 + this.executableMemberDoc = executableMemberDoc; 1.250 + setContext(context); 1.251 + } 1.252 + 1.253 + /** 1.254 + * {@inherotDoc} 1.255 + */ 1.256 + protected Content newContent() { 1.257 + return new ContentBuilder(); 1.258 + } 1.259 + 1.260 + /** 1.261 + * Construct a LinkInfo object. 1.262 + * 1.263 + * @param configuration the configuration data for the doclet 1.264 + * @param context the context of the link. 1.265 + * @param classDoc the class to link to. 1.266 + */ 1.267 + public LinkInfoImpl(ConfigurationImpl configuration, 1.268 + Kind context, ClassDoc classDoc) { 1.269 + this.configuration = configuration; 1.270 + this.classDoc = classDoc; 1.271 + setContext(context); 1.272 + } 1.273 + 1.274 + /** 1.275 + * Construct a LinkInfo object. 1.276 + * 1.277 + * @param configuration the configuration data for the doclet 1.278 + * @param context the context of the link. 1.279 + * @param type the class to link to. 1.280 + */ 1.281 + public LinkInfoImpl(ConfigurationImpl configuration, 1.282 + Kind context, Type type) { 1.283 + this.configuration = configuration; 1.284 + this.type = type; 1.285 + setContext(context); 1.286 + } 1.287 + 1.288 + 1.289 + /** 1.290 + * Set the label for the link. 1.291 + * @param label plain-text label for the link 1.292 + */ 1.293 + public LinkInfoImpl label(String label) { 1.294 + this.label = new StringContent(label); 1.295 + return this; 1.296 + } 1.297 + 1.298 + /** 1.299 + * Set the label for the link. 1.300 + */ 1.301 + public LinkInfoImpl label(Content label) { 1.302 + this.label = label; 1.303 + return this; 1.304 + } 1.305 + 1.306 + /** 1.307 + * Set whether or not the link should be strong. 1.308 + */ 1.309 + public LinkInfoImpl strong(boolean strong) { 1.310 + this.isStrong = strong; 1.311 + return this; 1.312 + } 1.313 + 1.314 + /** 1.315 + * Set the style to be used for the link. 1.316 + * @param styleName String style of text defined in style sheet. 1.317 + */ 1.318 + public LinkInfoImpl styleName(String styleName) { 1.319 + this.styleName = styleName; 1.320 + return this; 1.321 + } 1.322 + 1.323 + /** 1.324 + * Set the target to be used for the link. 1.325 + * @param styleName String style of text defined in style sheet. 1.326 + */ 1.327 + public LinkInfoImpl target(String target) { 1.328 + this.target = target; 1.329 + return this; 1.330 + } 1.331 + 1.332 + /** 1.333 + * Set whether or not this is a link to a varargs parameter. 1.334 + */ 1.335 + public LinkInfoImpl varargs(boolean varargs) { 1.336 + this.isVarArg = varargs; 1.337 + return this; 1.338 + } 1.339 + 1.340 + /** 1.341 + * Set the fragment specifier for the link. 1.342 + */ 1.343 + public LinkInfoImpl where(String where) { 1.344 + this.where = where; 1.345 + return this; 1.346 + } 1.347 + 1.348 + /** 1.349 + * {@inheritDoc} 1.350 + */ 1.351 + public Kind getContext() { 1.352 + return context; 1.353 + } 1.354 + 1.355 + /** 1.356 + * {@inheritDoc} 1.357 + * 1.358 + * This method sets the link attributes to the appropriate values 1.359 + * based on the context. 1.360 + * 1.361 + * @param c the context id to set. 1.362 + */ 1.363 + public final void setContext(Kind c) { 1.364 + //NOTE: Put context specific link code here. 1.365 + switch (c) { 1.366 + case ALL_CLASSES_FRAME: 1.367 + case PACKAGE_FRAME: 1.368 + case IMPLEMENTED_CLASSES: 1.369 + case SUBCLASSES: 1.370 + case METHOD_DOC_COPY: 1.371 + case FIELD_DOC_COPY: 1.372 + case PROPERTY_DOC_COPY: 1.373 + case CLASS_USE_HEADER: 1.374 + includeTypeInClassLinkLabel = false; 1.375 + break; 1.376 + 1.377 + case ANNOTATION: 1.378 + excludeTypeParameterLinks = true; 1.379 + excludeTypeBounds = true; 1.380 + break; 1.381 + 1.382 + case IMPLEMENTED_INTERFACES: 1.383 + case SUPER_INTERFACES: 1.384 + case SUBINTERFACES: 1.385 + case CLASS_TREE_PARENT: 1.386 + case TREE: 1.387 + case CLASS_SIGNATURE_PARENT_NAME: 1.388 + excludeTypeParameterLinks = true; 1.389 + excludeTypeBounds = true; 1.390 + includeTypeInClassLinkLabel = false; 1.391 + includeTypeAsSepLink = true; 1.392 + break; 1.393 + 1.394 + case PACKAGE: 1.395 + case CLASS_USE: 1.396 + case CLASS_HEADER: 1.397 + case CLASS_SIGNATURE: 1.398 + excludeTypeParameterLinks = true; 1.399 + includeTypeAsSepLink = true; 1.400 + includeTypeInClassLinkLabel = false; 1.401 + break; 1.402 + 1.403 + case MEMBER_TYPE_PARAMS: 1.404 + includeTypeAsSepLink = true; 1.405 + includeTypeInClassLinkLabel = false; 1.406 + break; 1.407 + 1.408 + case RETURN_TYPE: 1.409 + case SUMMARY_RETURN_TYPE: 1.410 + excludeTypeBounds = true; 1.411 + break; 1.412 + case EXECUTABLE_MEMBER_PARAM: 1.413 + excludeTypeBounds = true; 1.414 + break; 1.415 + } 1.416 + context = c; 1.417 + if (type != null && 1.418 + type.asTypeVariable()!= null && 1.419 + type.asTypeVariable().owner() instanceof ExecutableMemberDoc) { 1.420 + excludeTypeParameterLinks = true; 1.421 + } 1.422 + } 1.423 + 1.424 + /** 1.425 + * Return true if this link is linkable and false if we can't link to the 1.426 + * desired place. 1.427 + * 1.428 + * @return true if this link is linkable and false if we can't link to the 1.429 + * desired place. 1.430 + */ 1.431 + public boolean isLinkable() { 1.432 + return Util.isLinkable(classDoc, configuration); 1.433 + } 1.434 +}