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 annotation type. |
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 AnnotationTypeBuilder extends AbstractBuilder { |
duke@1 | 46 | |
duke@1 | 47 | /** |
duke@1 | 48 | * The root element of the annotation type XML is {@value}. |
duke@1 | 49 | */ |
duke@1 | 50 | public static final String ROOT = "AnnotationTypeDoc"; |
duke@1 | 51 | |
duke@1 | 52 | /** |
duke@1 | 53 | * The annotation type being documented. |
duke@1 | 54 | */ |
duke@1 | 55 | private AnnotationTypeDoc annotationTypeDoc; |
duke@1 | 56 | |
duke@1 | 57 | /** |
duke@1 | 58 | * The doclet specific writer. |
duke@1 | 59 | */ |
duke@1 | 60 | private AnnotationTypeWriter writer; |
duke@1 | 61 | |
duke@1 | 62 | /** |
duke@1 | 63 | * Construct a new ClassBuilder. |
duke@1 | 64 | * |
duke@1 | 65 | * @param configuration the current configuration of the |
duke@1 | 66 | * doclet. |
duke@1 | 67 | */ |
duke@1 | 68 | private AnnotationTypeBuilder(Configuration configuration) { |
duke@1 | 69 | super(configuration); |
duke@1 | 70 | } |
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 doclet. |
duke@1 | 76 | * @param annotationTypeDoc the class being documented. |
duke@1 | 77 | * @param writer the doclet specific writer. |
duke@1 | 78 | */ |
duke@1 | 79 | public static AnnotationTypeBuilder getInstance(Configuration configuration, |
duke@1 | 80 | AnnotationTypeDoc annotationTypeDoc, AnnotationTypeWriter writer) |
duke@1 | 81 | throws Exception { |
duke@1 | 82 | AnnotationTypeBuilder builder = new AnnotationTypeBuilder(configuration); |
duke@1 | 83 | builder.configuration = configuration; |
duke@1 | 84 | builder.annotationTypeDoc = annotationTypeDoc; |
duke@1 | 85 | builder.writer = writer; |
duke@1 | 86 | if(containingPackagesSeen == null) { |
jjg@74 | 87 | containingPackagesSeen = new HashSet<String>(); |
duke@1 | 88 | } |
duke@1 | 89 | return builder; |
duke@1 | 90 | } |
duke@1 | 91 | |
duke@1 | 92 | /** |
duke@1 | 93 | * {@inheritDoc} |
duke@1 | 94 | */ |
duke@1 | 95 | public void invokeMethod(String methodName, Class[] paramClasses, |
duke@1 | 96 | Object[] params) |
duke@1 | 97 | throws Exception { |
duke@1 | 98 | if (DEBUG) { |
duke@1 | 99 | configuration.root.printError("DEBUG: " + this.getClass().getName() |
duke@1 | 100 | + "." + methodName); |
duke@1 | 101 | } |
duke@1 | 102 | Method method = this.getClass().getMethod(methodName, paramClasses); |
duke@1 | 103 | method.invoke(this, params); |
duke@1 | 104 | } |
duke@1 | 105 | |
duke@1 | 106 | /** |
duke@1 | 107 | * {@inheritDoc} |
duke@1 | 108 | */ |
duke@1 | 109 | public void build() throws IOException { |
duke@1 | 110 | build(LayoutParser.getInstance(configuration).parseXML(ROOT)); |
duke@1 | 111 | } |
duke@1 | 112 | |
duke@1 | 113 | /** |
duke@1 | 114 | * {@inheritDoc} |
duke@1 | 115 | */ |
duke@1 | 116 | public String getName() { |
duke@1 | 117 | return ROOT; |
duke@1 | 118 | } |
duke@1 | 119 | |
duke@1 | 120 | /** |
duke@1 | 121 | * Handles the <AnnotationTypeDoc> tag. |
duke@1 | 122 | * |
duke@1 | 123 | * @param elements the XML elements that specify how to document a class. |
duke@1 | 124 | */ |
duke@1 | 125 | public void buildAnnotationTypeDoc(List elements) throws Exception { |
duke@1 | 126 | build(elements); |
duke@1 | 127 | writer.close(); |
duke@1 | 128 | copyDocFiles(); |
duke@1 | 129 | } |
duke@1 | 130 | |
duke@1 | 131 | |
duke@1 | 132 | /** |
duke@1 | 133 | * Copy the doc files for the current ClassDoc if necessary. |
duke@1 | 134 | */ |
duke@1 | 135 | private void copyDocFiles() { |
duke@1 | 136 | PackageDoc containingPackage = annotationTypeDoc.containingPackage(); |
duke@1 | 137 | if((configuration.packages == null || |
duke@1 | 138 | Arrays.binarySearch(configuration.packages, |
duke@1 | 139 | containingPackage) < 0) && |
duke@1 | 140 | ! containingPackagesSeen.contains(containingPackage.name())){ |
duke@1 | 141 | //Only copy doc files dir if the containing package is not |
duke@1 | 142 | //documented AND if we have not documented a class from the same |
duke@1 | 143 | //package already. Otherwise, we are making duplicate copies. |
duke@1 | 144 | Util.copyDocFiles(configuration, |
duke@1 | 145 | Util.getPackageSourcePath(configuration, |
duke@1 | 146 | annotationTypeDoc.containingPackage()) + |
duke@1 | 147 | DirectoryManager.getDirectoryPath( |
duke@1 | 148 | annotationTypeDoc.containingPackage()) |
duke@1 | 149 | + File.separator, DocletConstants.DOC_FILES_DIR_NAME, true); |
duke@1 | 150 | containingPackagesSeen.add(containingPackage.name()); |
duke@1 | 151 | } |
duke@1 | 152 | } |
duke@1 | 153 | |
duke@1 | 154 | /** |
duke@1 | 155 | * Build the header of the page. |
duke@1 | 156 | */ |
duke@1 | 157 | public void buildAnnotationTypeHeader() { |
duke@1 | 158 | writer.writeHeader(configuration.getText("doclet.AnnotationType") + |
duke@1 | 159 | " " + annotationTypeDoc.name()); |
duke@1 | 160 | } |
duke@1 | 161 | |
duke@1 | 162 | /** |
duke@1 | 163 | * If this class is deprecated, print the appropriate information. |
duke@1 | 164 | */ |
duke@1 | 165 | public void buildDeprecationInfo () { |
duke@1 | 166 | writer.writeAnnotationTypeDeprecationInfo(); |
duke@1 | 167 | } |
duke@1 | 168 | |
duke@1 | 169 | /** |
duke@1 | 170 | * Build the signature of the current annotation type. |
duke@1 | 171 | */ |
duke@1 | 172 | public void buildAnnotationTypeSignature() { |
duke@1 | 173 | StringBuffer modifiers = new StringBuffer( |
duke@1 | 174 | annotationTypeDoc.modifiers() + " "); |
duke@1 | 175 | writer.writeAnnotationTypeSignature( |
duke@1 | 176 | Util.replaceText( |
duke@1 | 177 | modifiers.toString(), "interface", "@interface")); |
duke@1 | 178 | } |
duke@1 | 179 | |
duke@1 | 180 | /** |
duke@1 | 181 | * Build the class description. |
duke@1 | 182 | */ |
duke@1 | 183 | public void buildAnnotationTypeDescription() { |
duke@1 | 184 | writer.writeAnnotationTypeDescription(); |
duke@1 | 185 | } |
duke@1 | 186 | |
duke@1 | 187 | /** |
duke@1 | 188 | * Build the tag information for the current class. |
duke@1 | 189 | */ |
duke@1 | 190 | public void buildAnnotationTypeTagInfo() { |
duke@1 | 191 | writer.writeAnnotationTypeTagInfo(); |
duke@1 | 192 | } |
duke@1 | 193 | |
duke@1 | 194 | /** |
duke@1 | 195 | * Build the contents of the page. |
duke@1 | 196 | * |
duke@1 | 197 | * @param elements the XML elements that specify how a member summary is |
duke@1 | 198 | * documented. |
duke@1 | 199 | */ |
duke@1 | 200 | public void buildMemberSummary(List elements) throws Exception { |
duke@1 | 201 | configuration.getBuilderFactory(). |
duke@1 | 202 | getMemberSummaryBuilder(writer).build(elements); |
duke@1 | 203 | writer.completeMemberSummaryBuild(); |
duke@1 | 204 | } |
duke@1 | 205 | |
duke@1 | 206 | /** |
duke@1 | 207 | * Build the annotation type optional member documentation. |
duke@1 | 208 | * |
duke@1 | 209 | * @param elements the XML elements that specify how a annotation type |
duke@1 | 210 | * members are documented. |
duke@1 | 211 | */ |
duke@1 | 212 | public void buildAnnotationTypeOptionalMemberDetails(List elements) |
duke@1 | 213 | throws Exception { |
duke@1 | 214 | configuration.getBuilderFactory(). |
duke@1 | 215 | getAnnotationTypeOptionalMemberBuilder(writer).build(elements); |
duke@1 | 216 | } |
duke@1 | 217 | |
duke@1 | 218 | /** |
duke@1 | 219 | * Build the annotation type required member documentation. |
duke@1 | 220 | * |
duke@1 | 221 | * @param elements the XML elements that specify how a annotation type |
duke@1 | 222 | * members are documented. |
duke@1 | 223 | */ |
duke@1 | 224 | public void buildAnnotationTypeRequiredMemberDetails(List elements) |
duke@1 | 225 | throws Exception { |
duke@1 | 226 | configuration.getBuilderFactory(). |
duke@1 | 227 | getAnnotationTypeRequiredMemberBuilder(writer).build(elements); |
duke@1 | 228 | } |
duke@1 | 229 | |
duke@1 | 230 | |
duke@1 | 231 | /** |
duke@1 | 232 | * Build the footer of the page. |
duke@1 | 233 | */ |
duke@1 | 234 | public void buildAnnotationTypeFooter() { |
duke@1 | 235 | writer.writeFooter(); |
duke@1 | 236 | } |
duke@1 | 237 | } |