Thu, 02 Oct 2008 19:58:40 -0700
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.builders; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 29 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 30 | import com.sun.javadoc.*; |
duke@1 | 31 | import java.io.*; |
duke@1 | 32 | import java.util.*; |
duke@1 | 33 | import java.lang.reflect.*; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * Builds the summary for a given class. |
duke@1 | 37 | * |
duke@1 | 38 | * This code is not part of an API. |
duke@1 | 39 | * It is implementation that is subject to change. |
duke@1 | 40 | * Do not use it as an API |
duke@1 | 41 | * |
duke@1 | 42 | * @author Jamie Ho |
duke@1 | 43 | * @since 1.5 |
duke@1 | 44 | */ |
duke@1 | 45 | public class ClassBuilder extends AbstractBuilder { |
duke@1 | 46 | |
duke@1 | 47 | /** |
duke@1 | 48 | * The root element of the class XML is {@value}. |
duke@1 | 49 | */ |
duke@1 | 50 | public static final String ROOT = "ClassDoc"; |
duke@1 | 51 | |
duke@1 | 52 | /** |
duke@1 | 53 | * The class being documented. |
duke@1 | 54 | */ |
duke@1 | 55 | private ClassDoc classDoc; |
duke@1 | 56 | |
duke@1 | 57 | /** |
duke@1 | 58 | * The doclet specific writer. |
duke@1 | 59 | */ |
duke@1 | 60 | private ClassWriter writer; |
duke@1 | 61 | |
duke@1 | 62 | /** |
duke@1 | 63 | * Keep track of whether or not this classdoc is an interface. |
duke@1 | 64 | */ |
duke@1 | 65 | private boolean isInterface = false; |
duke@1 | 66 | |
duke@1 | 67 | /** |
duke@1 | 68 | * Keep track of whether or not this classdoc is an enum. |
duke@1 | 69 | */ |
duke@1 | 70 | private boolean isEnum = false; |
duke@1 | 71 | |
duke@1 | 72 | /** |
duke@1 | 73 | * Construct a new ClassBuilder. |
duke@1 | 74 | * |
duke@1 | 75 | * @param configuration the current configuration of the |
duke@1 | 76 | * doclet. |
duke@1 | 77 | */ |
duke@1 | 78 | private ClassBuilder(Configuration configuration) { |
duke@1 | 79 | super(configuration); |
duke@1 | 80 | } |
duke@1 | 81 | |
duke@1 | 82 | /** |
duke@1 | 83 | * Construct a new ClassBuilder. |
duke@1 | 84 | * |
duke@1 | 85 | * @param configuration the current configuration of the doclet. |
duke@1 | 86 | * @param classDoc the class being documented. |
duke@1 | 87 | * @param writer the doclet specific writer. |
duke@1 | 88 | */ |
duke@1 | 89 | public static ClassBuilder getInstance(Configuration configuration, |
duke@1 | 90 | ClassDoc classDoc, ClassWriter writer) |
duke@1 | 91 | throws Exception { |
duke@1 | 92 | ClassBuilder builder = new ClassBuilder(configuration); |
duke@1 | 93 | builder.configuration = configuration; |
duke@1 | 94 | builder.classDoc = classDoc; |
duke@1 | 95 | builder.writer = writer; |
duke@1 | 96 | if (classDoc.isInterface()) { |
duke@1 | 97 | builder.isInterface = true; |
duke@1 | 98 | } else if (classDoc.isEnum()) { |
duke@1 | 99 | builder.isEnum = true; |
duke@1 | 100 | Util.setEnumDocumentation(configuration, classDoc); |
duke@1 | 101 | } |
duke@1 | 102 | if(containingPackagesSeen == null) { |
jjg@74 | 103 | containingPackagesSeen = new HashSet<String>(); |
duke@1 | 104 | } |
duke@1 | 105 | return builder; |
duke@1 | 106 | } |
duke@1 | 107 | |
duke@1 | 108 | /** |
duke@1 | 109 | * {@inheritDoc} |
duke@1 | 110 | */ |
duke@1 | 111 | public void invokeMethod(String methodName, Class[] paramClasses, |
duke@1 | 112 | Object[] params) |
duke@1 | 113 | throws Exception { |
duke@1 | 114 | if (DEBUG) { |
duke@1 | 115 | configuration.root.printError("DEBUG: " + this.getClass().getName() |
duke@1 | 116 | + "." + methodName); |
duke@1 | 117 | } |
duke@1 | 118 | Method method = this.getClass().getMethod(methodName, paramClasses); |
duke@1 | 119 | method.invoke(this, params); |
duke@1 | 120 | } |
duke@1 | 121 | |
duke@1 | 122 | /** |
duke@1 | 123 | * {@inheritDoc} |
duke@1 | 124 | */ |
duke@1 | 125 | public void build() throws IOException { |
duke@1 | 126 | build(LayoutParser.getInstance(configuration).parseXML(ROOT)); |
duke@1 | 127 | } |
duke@1 | 128 | |
duke@1 | 129 | /** |
duke@1 | 130 | * {@inheritDoc} |
duke@1 | 131 | */ |
duke@1 | 132 | public String getName() { |
duke@1 | 133 | return ROOT; |
duke@1 | 134 | } |
duke@1 | 135 | |
duke@1 | 136 | /** |
duke@1 | 137 | * Handles the <ClassDoc> tag. |
duke@1 | 138 | * |
duke@1 | 139 | * @param elements the XML elements that specify how to document a class. |
duke@1 | 140 | */ |
duke@1 | 141 | public void buildClassDoc(List elements) throws Exception { |
duke@1 | 142 | build(elements); |
duke@1 | 143 | writer.close(); |
duke@1 | 144 | copyDocFiles(); |
duke@1 | 145 | } |
duke@1 | 146 | |
duke@1 | 147 | |
duke@1 | 148 | /** |
duke@1 | 149 | * Copy the doc files for the current ClassDoc if necessary. |
duke@1 | 150 | */ |
duke@1 | 151 | private void copyDocFiles() { |
duke@1 | 152 | PackageDoc containingPackage = classDoc.containingPackage(); |
duke@1 | 153 | if((configuration.packages == null || |
duke@1 | 154 | Arrays.binarySearch(configuration.packages, |
duke@1 | 155 | containingPackage) < 0) && |
duke@1 | 156 | ! containingPackagesSeen.contains(containingPackage.name())){ |
duke@1 | 157 | //Only copy doc files dir if the containing package is not |
duke@1 | 158 | //documented AND if we have not documented a class from the same |
duke@1 | 159 | //package already. Otherwise, we are making duplicate copies. |
duke@1 | 160 | Util.copyDocFiles(configuration, |
duke@1 | 161 | Util.getPackageSourcePath(configuration, |
duke@1 | 162 | classDoc.containingPackage()) + |
duke@1 | 163 | DirectoryManager.getDirectoryPath(classDoc.containingPackage()) |
duke@1 | 164 | + File.separator, DocletConstants.DOC_FILES_DIR_NAME, true); |
duke@1 | 165 | containingPackagesSeen.add(containingPackage.name()); |
duke@1 | 166 | } |
duke@1 | 167 | } |
duke@1 | 168 | |
duke@1 | 169 | /** |
duke@1 | 170 | * Build the header of the page. |
duke@1 | 171 | */ |
duke@1 | 172 | public void buildClassHeader() { |
duke@1 | 173 | String key; |
duke@1 | 174 | if (isInterface) { |
duke@1 | 175 | key = "doclet.Interface"; |
duke@1 | 176 | } else if (isEnum) { |
duke@1 | 177 | key = "doclet.Enum"; |
duke@1 | 178 | } else { |
duke@1 | 179 | key = "doclet.Class"; |
duke@1 | 180 | } |
duke@1 | 181 | |
duke@1 | 182 | writer.writeHeader(configuration.getText(key) + " " + classDoc.name()); |
duke@1 | 183 | } |
duke@1 | 184 | |
duke@1 | 185 | /** |
duke@1 | 186 | * Build the class tree documentation. |
duke@1 | 187 | */ |
duke@1 | 188 | public void buildClassTree() { |
duke@1 | 189 | writer.writeClassTree(); |
duke@1 | 190 | } |
duke@1 | 191 | |
duke@1 | 192 | /** |
duke@1 | 193 | * If this is a class, list all interfaces |
duke@1 | 194 | * implemented by this class. |
duke@1 | 195 | */ |
duke@1 | 196 | public void buildImplementedInterfacesInfo() { |
duke@1 | 197 | writer.writeImplementedInterfacesInfo(); |
duke@1 | 198 | } |
duke@1 | 199 | |
duke@1 | 200 | /** |
duke@1 | 201 | * If this is an interface, list all super interfaces. |
duke@1 | 202 | */ |
duke@1 | 203 | public void buildSuperInterfacesInfo() { |
duke@1 | 204 | writer.writeSuperInterfacesInfo(); |
duke@1 | 205 | } |
duke@1 | 206 | |
duke@1 | 207 | /** |
duke@1 | 208 | * List the parameters of this class. |
duke@1 | 209 | */ |
duke@1 | 210 | public void buildTypeParamInfo() { |
duke@1 | 211 | writer.writeTypeParamInfo(); |
duke@1 | 212 | } |
duke@1 | 213 | |
duke@1 | 214 | /** |
duke@1 | 215 | * List all the classes extend this one. |
duke@1 | 216 | */ |
duke@1 | 217 | public void buildSubClassInfo() { |
duke@1 | 218 | writer.writeSubClassInfo(); |
duke@1 | 219 | } |
duke@1 | 220 | |
duke@1 | 221 | /** |
duke@1 | 222 | * List all the interfaces that extend this one. |
duke@1 | 223 | */ |
duke@1 | 224 | public void buildSubInterfacesInfo() { |
duke@1 | 225 | writer.writeSubInterfacesInfo(); |
duke@1 | 226 | } |
duke@1 | 227 | |
duke@1 | 228 | /** |
duke@1 | 229 | * If this is an interface, list all classes that implement this interface. |
duke@1 | 230 | */ |
duke@1 | 231 | public void buildInterfaceUsageInfo () { |
duke@1 | 232 | writer.writeInterfaceUsageInfo(); |
duke@1 | 233 | } |
duke@1 | 234 | |
duke@1 | 235 | /** |
duke@1 | 236 | * If this is an inner class or interface, list the enclosing class or |
duke@1 | 237 | * interface. |
duke@1 | 238 | */ |
duke@1 | 239 | public void buildNestedClassInfo () { |
duke@1 | 240 | writer.writeNestedClassInfo(); |
duke@1 | 241 | } |
duke@1 | 242 | |
duke@1 | 243 | /** |
duke@1 | 244 | * If this class is deprecated, print the appropriate information. |
duke@1 | 245 | */ |
duke@1 | 246 | public void buildDeprecationInfo () { |
duke@1 | 247 | writer.writeClassDeprecationInfo(); |
duke@1 | 248 | } |
duke@1 | 249 | |
duke@1 | 250 | /** |
duke@1 | 251 | * Build the signature of the current class. |
duke@1 | 252 | */ |
duke@1 | 253 | public void buildClassSignature() { |
duke@1 | 254 | StringBuffer modifiers = new StringBuffer(classDoc.modifiers() + " "); |
duke@1 | 255 | if (isEnum) { |
duke@1 | 256 | modifiers.append("enum "); |
duke@1 | 257 | int index; |
duke@1 | 258 | if ((index = modifiers.indexOf("abstract")) >= 0) { |
duke@1 | 259 | modifiers.delete(index, index + (new String("abstract")).length()); |
duke@1 | 260 | modifiers = new StringBuffer( |
duke@1 | 261 | Util.replaceText(modifiers.toString(), " ", " ")); |
duke@1 | 262 | } |
duke@1 | 263 | if ((index = modifiers.indexOf("final")) >= 0) { |
duke@1 | 264 | modifiers.delete(index, index + (new String("final")).length()); |
duke@1 | 265 | modifiers = new StringBuffer( |
duke@1 | 266 | Util.replaceText(modifiers.toString(), " ", " ")); |
duke@1 | 267 | } |
duke@1 | 268 | //} else if (classDoc.isAnnotationType()) { |
duke@1 | 269 | //modifiers.append("@interface "); |
duke@1 | 270 | } else if (! isInterface) { |
duke@1 | 271 | modifiers.append("class "); |
duke@1 | 272 | } |
duke@1 | 273 | writer.writeClassSignature(modifiers.toString()); |
duke@1 | 274 | } |
duke@1 | 275 | |
duke@1 | 276 | /** |
duke@1 | 277 | * Build the class description. |
duke@1 | 278 | */ |
duke@1 | 279 | public void buildClassDescription() { |
duke@1 | 280 | writer.writeClassDescription(); |
duke@1 | 281 | } |
duke@1 | 282 | |
duke@1 | 283 | /** |
duke@1 | 284 | * Build the tag information for the current class. |
duke@1 | 285 | */ |
duke@1 | 286 | public void buildClassTagInfo() { |
duke@1 | 287 | writer.writeClassTagInfo(); |
duke@1 | 288 | } |
duke@1 | 289 | |
duke@1 | 290 | /** |
duke@1 | 291 | * Build the contents of the page. |
duke@1 | 292 | * |
duke@1 | 293 | * @param elements the XML elements that specify how a member summary is |
duke@1 | 294 | * documented. |
duke@1 | 295 | */ |
duke@1 | 296 | public void buildMemberSummary(List elements) throws Exception { |
duke@1 | 297 | configuration.getBuilderFactory(). |
duke@1 | 298 | getMemberSummaryBuilder(writer).build(elements); |
duke@1 | 299 | writer.completeMemberSummaryBuild(); |
duke@1 | 300 | } |
duke@1 | 301 | |
duke@1 | 302 | /** |
duke@1 | 303 | * Build the enum constants documentation. |
duke@1 | 304 | * |
duke@1 | 305 | * @param elements the XML elements that specify how a enum constants are |
duke@1 | 306 | * documented. |
duke@1 | 307 | */ |
duke@1 | 308 | public void buildEnumConstantsDetails(List elements) throws Exception { |
duke@1 | 309 | configuration.getBuilderFactory(). |
duke@1 | 310 | getEnumConstantsBuilder(writer).build(elements); |
duke@1 | 311 | } |
duke@1 | 312 | |
duke@1 | 313 | /** |
duke@1 | 314 | * Build the field documentation. |
duke@1 | 315 | * |
duke@1 | 316 | * @param elements the XML elements that specify how a field is documented. |
duke@1 | 317 | */ |
duke@1 | 318 | public void buildFieldDetails(List elements) throws Exception { |
duke@1 | 319 | configuration.getBuilderFactory(). |
duke@1 | 320 | getFieldBuilder(writer).build(elements); |
duke@1 | 321 | } |
duke@1 | 322 | |
duke@1 | 323 | /** |
duke@1 | 324 | * Build the constructor documentation. |
duke@1 | 325 | * |
duke@1 | 326 | * @param elements the XML elements that specify how to document a |
duke@1 | 327 | * constructor. |
duke@1 | 328 | */ |
duke@1 | 329 | public void buildConstructorDetails(List elements) throws Exception { |
duke@1 | 330 | configuration.getBuilderFactory(). |
duke@1 | 331 | getConstructorBuilder(writer).build(elements); |
duke@1 | 332 | } |
duke@1 | 333 | |
duke@1 | 334 | /** |
duke@1 | 335 | * Build the method documentation. |
duke@1 | 336 | * |
duke@1 | 337 | * @param elements the XML elements that specify how a method is documented. |
duke@1 | 338 | */ |
duke@1 | 339 | public void buildMethodDetails(List elements) throws Exception { |
duke@1 | 340 | configuration.getBuilderFactory(). |
duke@1 | 341 | getMethodBuilder(writer).build(elements); |
duke@1 | 342 | } |
duke@1 | 343 | |
duke@1 | 344 | /** |
duke@1 | 345 | * Build the footer of the page. |
duke@1 | 346 | */ |
duke@1 | 347 | public void buildClassFooter() { |
duke@1 | 348 | writer.writeFooter(); |
duke@1 | 349 | } |
duke@1 | 350 | } |