Mon, 10 Dec 2012 16:21:26 +0000
8003967: detect and remove all mutable implicit static enum fields in langtools
Reviewed-by: jjg
duke@1 | 1 | /* |
jjg@1359 | 2 | * Copyright (c) 2003, 2012, Oracle and/or its affiliates. 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 |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle 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 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * 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 | * |
jjg@1359 | 33 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 34 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 35 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 36 | * deletion without notice.</b> |
jjg@1359 | 37 | * |
duke@1 | 38 | * @author Jamie Ho |
duke@1 | 39 | * @since 1.5 |
duke@1 | 40 | */ |
duke@1 | 41 | public abstract class LinkFactory { |
duke@1 | 42 | |
duke@1 | 43 | /** |
duke@1 | 44 | * Return an empty instance of the link output object. |
duke@1 | 45 | * |
duke@1 | 46 | * @return an empty instance of the link output object. |
duke@1 | 47 | */ |
duke@1 | 48 | protected abstract LinkOutput getOutputInstance(); |
duke@1 | 49 | |
duke@1 | 50 | /** |
duke@1 | 51 | * Constructs a link from the given link information. |
duke@1 | 52 | * |
duke@1 | 53 | * @param linkInfo the information about the link. |
duke@1 | 54 | * @return the output of the link. |
duke@1 | 55 | */ |
duke@1 | 56 | public LinkOutput getLinkOutput(LinkInfo linkInfo) { |
duke@1 | 57 | if (linkInfo.type != null) { |
duke@1 | 58 | Type type = linkInfo.type; |
duke@1 | 59 | LinkOutput linkOutput = getOutputInstance(); |
duke@1 | 60 | if (type.isPrimitive()) { |
duke@1 | 61 | //Just a primitive. |
duke@1 | 62 | linkInfo.displayLength += type.typeName().length(); |
duke@1 | 63 | linkOutput.append(type.typeName()); |
duke@1 | 64 | } else if (type.asWildcardType() != null) { |
duke@1 | 65 | //Wildcard type. |
duke@1 | 66 | linkInfo.isTypeBound = true; |
duke@1 | 67 | linkInfo.displayLength += 1; |
duke@1 | 68 | linkOutput.append("?"); |
duke@1 | 69 | WildcardType wildcardType = type.asWildcardType(); |
duke@1 | 70 | Type[] extendsBounds = wildcardType.extendsBounds(); |
duke@1 | 71 | for (int i = 0; i < extendsBounds.length; i++) { |
duke@1 | 72 | linkInfo.displayLength += i > 0 ? 2 : 9; |
duke@1 | 73 | linkOutput.append(i > 0 ? ", " : " extends "); |
duke@1 | 74 | setBoundsLinkInfo(linkInfo, extendsBounds[i]); |
duke@1 | 75 | linkOutput.append(getLinkOutput(linkInfo)); |
duke@1 | 76 | } |
duke@1 | 77 | Type[] superBounds = wildcardType.superBounds(); |
duke@1 | 78 | for (int i = 0; i < superBounds.length; i++) { |
duke@1 | 79 | linkInfo.displayLength += i > 0 ? 2 : 7; |
duke@1 | 80 | linkOutput.append(i > 0 ? ", " : " super "); |
duke@1 | 81 | setBoundsLinkInfo(linkInfo, superBounds[i]); |
duke@1 | 82 | linkOutput.append(getLinkOutput(linkInfo)); |
duke@1 | 83 | } |
duke@1 | 84 | } else if (type.asTypeVariable()!= null) { |
duke@1 | 85 | linkInfo.isTypeBound = true; |
duke@1 | 86 | //A type variable. |
duke@1 | 87 | Doc owner = type.asTypeVariable().owner(); |
duke@1 | 88 | if ((! linkInfo.excludeTypeParameterLinks) && |
duke@1 | 89 | owner instanceof ClassDoc) { |
duke@1 | 90 | linkInfo.classDoc = (ClassDoc) owner; |
duke@1 | 91 | linkInfo.label = type.typeName(); |
jjg@74 | 92 | linkOutput.append(getClassLink(linkInfo)); |
duke@1 | 93 | } else { |
duke@1 | 94 | //No need to link method type parameters. |
duke@1 | 95 | linkInfo.displayLength += type.typeName().length(); |
duke@1 | 96 | linkOutput.append(type.typeName()); |
duke@1 | 97 | } |
duke@1 | 98 | |
duke@1 | 99 | Type[] bounds = type.asTypeVariable().bounds(); |
duke@1 | 100 | if (! linkInfo.excludeTypeBounds) { |
duke@1 | 101 | linkInfo.excludeTypeBounds = true; |
duke@1 | 102 | for (int i = 0; i < bounds.length; i++) { |
duke@1 | 103 | linkInfo.displayLength += i > 0 ? 2 : 9; |
duke@1 | 104 | linkOutput.append(i > 0 ? " & " : " extends "); |
duke@1 | 105 | setBoundsLinkInfo(linkInfo, bounds[i]); |
duke@1 | 106 | linkOutput.append(getLinkOutput(linkInfo)); |
duke@1 | 107 | } |
duke@1 | 108 | } |
duke@1 | 109 | } else if (type.asClassDoc() != null) { |
duke@1 | 110 | //A class type. |
duke@1 | 111 | if (linkInfo.isTypeBound && |
duke@1 | 112 | linkInfo.excludeTypeBoundsLinks) { |
duke@1 | 113 | //Since we are excluding type parameter links, we should not |
duke@1 | 114 | //be linking to the type bound. |
duke@1 | 115 | linkInfo.displayLength += type.typeName().length(); |
duke@1 | 116 | linkOutput.append(type.typeName()); |
duke@1 | 117 | linkOutput.append(getTypeParameterLinks(linkInfo)); |
duke@1 | 118 | return linkOutput; |
duke@1 | 119 | } else { |
duke@1 | 120 | linkInfo.classDoc = type.asClassDoc(); |
jjg@74 | 121 | linkOutput = getClassLink(linkInfo); |
duke@1 | 122 | if (linkInfo.includeTypeAsSepLink) { |
duke@1 | 123 | linkOutput.append(getTypeParameterLinks(linkInfo, false)); |
duke@1 | 124 | } |
duke@1 | 125 | } |
duke@1 | 126 | } |
duke@1 | 127 | |
duke@1 | 128 | if (linkInfo.isVarArg) { |
duke@1 | 129 | if (type.dimension().length() > 2) { |
duke@1 | 130 | //Javadoc returns var args as array. |
duke@1 | 131 | //Strip out the first [] from the var arg. |
duke@1 | 132 | linkInfo.displayLength += type.dimension().length()-2; |
duke@1 | 133 | linkOutput.append(type.dimension().substring(2)); |
duke@1 | 134 | } |
duke@1 | 135 | linkInfo.displayLength += 3; |
duke@1 | 136 | linkOutput.append("..."); |
duke@1 | 137 | } else { |
duke@1 | 138 | linkInfo.displayLength += type.dimension().length(); |
duke@1 | 139 | linkOutput.append(type.dimension()); |
duke@1 | 140 | } |
duke@1 | 141 | return linkOutput; |
duke@1 | 142 | } else if (linkInfo.classDoc != null) { |
duke@1 | 143 | //Just a class link |
jjg@74 | 144 | LinkOutput linkOutput = getClassLink(linkInfo); |
duke@1 | 145 | if (linkInfo.includeTypeAsSepLink) { |
duke@1 | 146 | linkOutput.append(getTypeParameterLinks(linkInfo, false)); |
duke@1 | 147 | } |
duke@1 | 148 | return linkOutput; |
duke@1 | 149 | } else { |
duke@1 | 150 | return null; |
duke@1 | 151 | } |
duke@1 | 152 | } |
duke@1 | 153 | |
duke@1 | 154 | private void setBoundsLinkInfo(LinkInfo linkInfo, Type bound) { |
duke@1 | 155 | linkInfo.classDoc = null; |
duke@1 | 156 | linkInfo.label = null; |
duke@1 | 157 | linkInfo.type = bound; |
duke@1 | 158 | } |
duke@1 | 159 | |
duke@1 | 160 | /** |
duke@1 | 161 | * Return the link to the given class. |
duke@1 | 162 | * |
duke@1 | 163 | * @param linkInfo the information about the link to construct. |
duke@1 | 164 | * |
duke@1 | 165 | * @return the link for the given class. |
duke@1 | 166 | */ |
duke@1 | 167 | protected abstract LinkOutput getClassLink(LinkInfo linkInfo); |
duke@1 | 168 | |
duke@1 | 169 | /** |
duke@1 | 170 | * Return the link to the given type parameter. |
duke@1 | 171 | * |
duke@1 | 172 | * @param linkInfo the information about the link to construct. |
duke@1 | 173 | * @param typeParam the type parameter to link to. |
duke@1 | 174 | */ |
duke@1 | 175 | protected abstract LinkOutput getTypeParameterLink(LinkInfo linkInfo, |
duke@1 | 176 | Type typeParam); |
duke@1 | 177 | |
duke@1 | 178 | /** |
duke@1 | 179 | * Return the links to the type parameters. |
duke@1 | 180 | * |
duke@1 | 181 | * @param linkInfo the information about the link to construct. |
duke@1 | 182 | * @return the links to the type parameters. |
duke@1 | 183 | */ |
duke@1 | 184 | public LinkOutput getTypeParameterLinks(LinkInfo linkInfo) { |
duke@1 | 185 | return getTypeParameterLinks(linkInfo, true); |
duke@1 | 186 | } |
duke@1 | 187 | |
duke@1 | 188 | /** |
duke@1 | 189 | * Return the links to the type parameters. |
duke@1 | 190 | * |
duke@1 | 191 | * @param linkInfo the information about the link to construct. |
duke@1 | 192 | * @param isClassLabel true if this is a class label. False if it is |
duke@1 | 193 | * the type parameters portion of the link. |
duke@1 | 194 | * @return the links to the type parameters. |
duke@1 | 195 | */ |
duke@1 | 196 | public LinkOutput getTypeParameterLinks(LinkInfo linkInfo, boolean isClassLabel) { |
duke@1 | 197 | LinkOutput output = getOutputInstance(); |
duke@1 | 198 | Type[] vars; |
duke@1 | 199 | if (linkInfo.executableMemberDoc != null) { |
duke@1 | 200 | vars = linkInfo.executableMemberDoc.typeParameters(); |
duke@1 | 201 | } else if (linkInfo.type != null && |
duke@1 | 202 | linkInfo.type.asParameterizedType() != null){ |
duke@1 | 203 | vars = linkInfo.type.asParameterizedType().typeArguments(); |
duke@1 | 204 | } else if (linkInfo.classDoc != null){ |
duke@1 | 205 | vars = linkInfo.classDoc.typeParameters(); |
duke@1 | 206 | } else { |
duke@1 | 207 | //Nothing to document. |
duke@1 | 208 | return output; |
duke@1 | 209 | } |
duke@1 | 210 | if (((linkInfo.includeTypeInClassLinkLabel && isClassLabel) || |
duke@1 | 211 | (linkInfo.includeTypeAsSepLink && ! isClassLabel) |
duke@1 | 212 | ) |
duke@1 | 213 | && vars.length > 0) { |
duke@1 | 214 | linkInfo.displayLength += 1; |
duke@1 | 215 | output.append(getLessThanString()); |
duke@1 | 216 | for (int i = 0; i < vars.length; i++) { |
duke@1 | 217 | if (i > 0) { |
duke@1 | 218 | linkInfo.displayLength += 1; |
duke@1 | 219 | output.append(","); |
duke@1 | 220 | } |
duke@1 | 221 | output.append(getTypeParameterLink(linkInfo, vars[i])); |
duke@1 | 222 | } |
duke@1 | 223 | linkInfo.displayLength += 1; |
duke@1 | 224 | output.append(getGreaterThanString()); |
duke@1 | 225 | } |
duke@1 | 226 | return output; |
duke@1 | 227 | } |
duke@1 | 228 | |
duke@1 | 229 | /** |
duke@1 | 230 | * Return &lt;, which is used in type parameters. Override this |
duke@1 | 231 | * if your doclet uses something different. |
duke@1 | 232 | * |
duke@1 | 233 | * @return return &lt;, which is used in type parameters. |
duke@1 | 234 | */ |
duke@1 | 235 | protected String getLessThanString() { |
duke@1 | 236 | return "<"; |
duke@1 | 237 | } |
duke@1 | 238 | |
duke@1 | 239 | /** |
duke@1 | 240 | * Return &gt;, which is used in type parameters. Override this |
duke@1 | 241 | * if your doclet uses something different. |
duke@1 | 242 | * |
duke@1 | 243 | * @return return &gt;, which is used in type parameters. |
duke@1 | 244 | */ |
duke@1 | 245 | protected String getGreaterThanString() { |
duke@1 | 246 | return ">"; |
duke@1 | 247 | } |
duke@1 | 248 | } |