src/share/classes/com/sun/tools/doclets/internal/toolkit/util/links/LinkFactory.java

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 554
9d9f26857129
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
xdono@117 2 * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit.util.links;
duke@1 27
duke@1 28 import com.sun.javadoc.*;
duke@1 29
duke@1 30 /**
duke@1 31 * A factory that constructs links from given link information.
duke@1 32 *
duke@1 33 * @author Jamie Ho
duke@1 34 * @since 1.5
duke@1 35 */
duke@1 36 public abstract class LinkFactory {
duke@1 37
duke@1 38 /**
duke@1 39 * Return an empty instance of the link output object.
duke@1 40 *
duke@1 41 * @return an empty instance of the link output object.
duke@1 42 */
duke@1 43 protected abstract LinkOutput getOutputInstance();
duke@1 44
duke@1 45 /**
duke@1 46 * Constructs a link from the given link information.
duke@1 47 *
duke@1 48 * @param linkInfo the information about the link.
duke@1 49 * @return the output of the link.
duke@1 50 */
duke@1 51 public LinkOutput getLinkOutput(LinkInfo linkInfo) {
duke@1 52 if (linkInfo.type != null) {
duke@1 53 Type type = linkInfo.type;
duke@1 54 LinkOutput linkOutput = getOutputInstance();
duke@1 55 if (type.isPrimitive()) {
duke@1 56 //Just a primitive.
duke@1 57 linkInfo.displayLength += type.typeName().length();
duke@1 58 linkOutput.append(type.typeName());
duke@1 59 } else if (type.asWildcardType() != null) {
duke@1 60 //Wildcard type.
duke@1 61 linkInfo.isTypeBound = true;
duke@1 62 linkInfo.displayLength += 1;
duke@1 63 linkOutput.append("?");
duke@1 64 WildcardType wildcardType = type.asWildcardType();
duke@1 65 Type[] extendsBounds = wildcardType.extendsBounds();
duke@1 66 for (int i = 0; i < extendsBounds.length; i++) {
duke@1 67 linkInfo.displayLength += i > 0 ? 2 : 9;
duke@1 68 linkOutput.append(i > 0 ? ", " : " extends ");
duke@1 69 setBoundsLinkInfo(linkInfo, extendsBounds[i]);
duke@1 70 linkOutput.append(getLinkOutput(linkInfo));
duke@1 71 }
duke@1 72 Type[] superBounds = wildcardType.superBounds();
duke@1 73 for (int i = 0; i < superBounds.length; i++) {
duke@1 74 linkInfo.displayLength += i > 0 ? 2 : 7;
duke@1 75 linkOutput.append(i > 0 ? ", " : " super ");
duke@1 76 setBoundsLinkInfo(linkInfo, superBounds[i]);
duke@1 77 linkOutput.append(getLinkOutput(linkInfo));
duke@1 78 }
duke@1 79 } else if (type.asTypeVariable()!= null) {
duke@1 80 linkInfo.isTypeBound = true;
duke@1 81 //A type variable.
duke@1 82 Doc owner = type.asTypeVariable().owner();
duke@1 83 if ((! linkInfo.excludeTypeParameterLinks) &&
duke@1 84 owner instanceof ClassDoc) {
duke@1 85 linkInfo.classDoc = (ClassDoc) owner;
duke@1 86 linkInfo.label = type.typeName();
jjg@74 87 linkOutput.append(getClassLink(linkInfo));
duke@1 88 } else {
duke@1 89 //No need to link method type parameters.
duke@1 90 linkInfo.displayLength += type.typeName().length();
duke@1 91 linkOutput.append(type.typeName());
duke@1 92 }
duke@1 93
duke@1 94 Type[] bounds = type.asTypeVariable().bounds();
duke@1 95 if (! linkInfo.excludeTypeBounds) {
duke@1 96 linkInfo.excludeTypeBounds = true;
duke@1 97 for (int i = 0; i < bounds.length; i++) {
duke@1 98 linkInfo.displayLength += i > 0 ? 2 : 9;
duke@1 99 linkOutput.append(i > 0 ? " & " : " extends ");
duke@1 100 setBoundsLinkInfo(linkInfo, bounds[i]);
duke@1 101 linkOutput.append(getLinkOutput(linkInfo));
duke@1 102 }
duke@1 103 }
duke@1 104 } else if (type.asClassDoc() != null) {
duke@1 105 //A class type.
duke@1 106 if (linkInfo.isTypeBound &&
duke@1 107 linkInfo.excludeTypeBoundsLinks) {
duke@1 108 //Since we are excluding type parameter links, we should not
duke@1 109 //be linking to the type bound.
duke@1 110 linkInfo.displayLength += type.typeName().length();
duke@1 111 linkOutput.append(type.typeName());
duke@1 112 linkOutput.append(getTypeParameterLinks(linkInfo));
duke@1 113 return linkOutput;
duke@1 114 } else {
duke@1 115 linkInfo.classDoc = type.asClassDoc();
jjg@74 116 linkOutput = getClassLink(linkInfo);
duke@1 117 if (linkInfo.includeTypeAsSepLink) {
duke@1 118 linkOutput.append(getTypeParameterLinks(linkInfo, false));
duke@1 119 }
duke@1 120 }
duke@1 121 }
duke@1 122
duke@1 123 if (linkInfo.isVarArg) {
duke@1 124 if (type.dimension().length() > 2) {
duke@1 125 //Javadoc returns var args as array.
duke@1 126 //Strip out the first [] from the var arg.
duke@1 127 linkInfo.displayLength += type.dimension().length()-2;
duke@1 128 linkOutput.append(type.dimension().substring(2));
duke@1 129 }
duke@1 130 linkInfo.displayLength += 3;
duke@1 131 linkOutput.append("...");
duke@1 132 } else {
duke@1 133 linkInfo.displayLength += type.dimension().length();
duke@1 134 linkOutput.append(type.dimension());
duke@1 135 }
duke@1 136 return linkOutput;
duke@1 137 } else if (linkInfo.classDoc != null) {
duke@1 138 //Just a class link
jjg@74 139 LinkOutput linkOutput = getClassLink(linkInfo);
duke@1 140 if (linkInfo.includeTypeAsSepLink) {
duke@1 141 linkOutput.append(getTypeParameterLinks(linkInfo, false));
duke@1 142 }
duke@1 143 return linkOutput;
duke@1 144 } else {
duke@1 145 return null;
duke@1 146 }
duke@1 147 }
duke@1 148
duke@1 149 private void setBoundsLinkInfo(LinkInfo linkInfo, Type bound) {
duke@1 150 linkInfo.classDoc = null;
duke@1 151 linkInfo.label = null;
duke@1 152 linkInfo.type = bound;
duke@1 153 }
duke@1 154
duke@1 155 /**
duke@1 156 * Return the link to the given class.
duke@1 157 *
duke@1 158 * @param linkInfo the information about the link to construct.
duke@1 159 *
duke@1 160 * @return the link for the given class.
duke@1 161 */
duke@1 162 protected abstract LinkOutput getClassLink(LinkInfo linkInfo);
duke@1 163
duke@1 164 /**
duke@1 165 * Return the link to the given type parameter.
duke@1 166 *
duke@1 167 * @param linkInfo the information about the link to construct.
duke@1 168 * @param typeParam the type parameter to link to.
duke@1 169 */
duke@1 170 protected abstract LinkOutput getTypeParameterLink(LinkInfo linkInfo,
duke@1 171 Type typeParam);
duke@1 172
duke@1 173 /**
duke@1 174 * Return the links to the type parameters.
duke@1 175 *
duke@1 176 * @param linkInfo the information about the link to construct.
duke@1 177 * @return the links to the type parameters.
duke@1 178 */
duke@1 179 public LinkOutput getTypeParameterLinks(LinkInfo linkInfo) {
duke@1 180 return getTypeParameterLinks(linkInfo, true);
duke@1 181 }
duke@1 182
duke@1 183 /**
duke@1 184 * Return the links to the type parameters.
duke@1 185 *
duke@1 186 * @param linkInfo the information about the link to construct.
duke@1 187 * @param isClassLabel true if this is a class label. False if it is
duke@1 188 * the type parameters portion of the link.
duke@1 189 * @return the links to the type parameters.
duke@1 190 */
duke@1 191 public LinkOutput getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) {
duke@1 192 LinkOutput output = getOutputInstance();
duke@1 193 Type[] vars;
duke@1 194 if (linkInfo.executableMemberDoc != null) {
duke@1 195 vars = linkInfo.executableMemberDoc.typeParameters();
duke@1 196 } else if (linkInfo.type != null &&
duke@1 197 linkInfo.type.asParameterizedType() != null){
duke@1 198 vars = linkInfo.type.asParameterizedType().typeArguments();
duke@1 199 } else if (linkInfo.classDoc != null){
duke@1 200 vars = linkInfo.classDoc.typeParameters();
duke@1 201 } else {
duke@1 202 //Nothing to document.
duke@1 203 return output;
duke@1 204 }
duke@1 205 if (((linkInfo.includeTypeInClassLinkLabel && isClassLabel) ||
duke@1 206 (linkInfo.includeTypeAsSepLink && ! isClassLabel)
duke@1 207 )
duke@1 208 && vars.length > 0) {
duke@1 209 linkInfo.displayLength += 1;
duke@1 210 output.append(getLessThanString());
duke@1 211 for (int i = 0; i < vars.length; i++) {
duke@1 212 if (i > 0) {
duke@1 213 linkInfo.displayLength += 1;
duke@1 214 output.append(",");
duke@1 215 }
duke@1 216 output.append(getTypeParameterLink(linkInfo, vars[i]));
duke@1 217 }
duke@1 218 linkInfo.displayLength += 1;
duke@1 219 output.append(getGreaterThanString());
duke@1 220 }
duke@1 221 return output;
duke@1 222 }
duke@1 223
duke@1 224 /**
duke@1 225 * Return &amp;lt;, which is used in type parameters. Override this
duke@1 226 * if your doclet uses something different.
duke@1 227 *
duke@1 228 * @return return &amp;lt;, which is used in type parameters.
duke@1 229 */
duke@1 230 protected String getLessThanString() {
duke@1 231 return "&lt;";
duke@1 232 }
duke@1 233
duke@1 234 /**
duke@1 235 * Return &amp;gt;, which is used in type parameters. Override this
duke@1 236 * if your doclet uses something different.
duke@1 237 *
duke@1 238 * @return return &amp;gt;, which is used in type parameters.
duke@1 239 */
duke@1 240 protected String getGreaterThanString() {
duke@1 241 return "&gt;";
duke@1 242 }
duke@1 243 }

mercurial