Fri, 18 Jun 2010 21:13:56 -0700
6961178: Allow doclet.xml to contain XML attributes
Reviewed-by: bpatel
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2003, 2008, 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.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 | |
duke@1 | 34 | /** |
duke@1 | 35 | * Builds the summary for a given annotation type. |
duke@1 | 36 | * |
duke@1 | 37 | * This code is not part of an API. |
duke@1 | 38 | * It is implementation that is subject to change. |
duke@1 | 39 | * Do not use it as an API |
duke@1 | 40 | * |
duke@1 | 41 | * @author Jamie Ho |
duke@1 | 42 | * @since 1.5 |
duke@1 | 43 | */ |
duke@1 | 44 | public class AnnotationTypeBuilder extends AbstractBuilder { |
duke@1 | 45 | |
duke@1 | 46 | /** |
duke@1 | 47 | * The root element of the annotation type XML is {@value}. |
duke@1 | 48 | */ |
duke@1 | 49 | public static final String ROOT = "AnnotationTypeDoc"; |
duke@1 | 50 | |
duke@1 | 51 | /** |
duke@1 | 52 | * The annotation type being documented. |
duke@1 | 53 | */ |
duke@1 | 54 | private AnnotationTypeDoc annotationTypeDoc; |
duke@1 | 55 | |
duke@1 | 56 | /** |
duke@1 | 57 | * The doclet specific writer. |
duke@1 | 58 | */ |
duke@1 | 59 | private AnnotationTypeWriter writer; |
duke@1 | 60 | |
duke@1 | 61 | /** |
duke@1 | 62 | * Construct a new ClassBuilder. |
duke@1 | 63 | * |
duke@1 | 64 | * @param configuration the current configuration of the |
duke@1 | 65 | * doclet. |
duke@1 | 66 | */ |
duke@1 | 67 | private AnnotationTypeBuilder(Configuration configuration) { |
duke@1 | 68 | super(configuration); |
duke@1 | 69 | } |
duke@1 | 70 | |
duke@1 | 71 | /** |
duke@1 | 72 | * Construct a new ClassBuilder. |
duke@1 | 73 | * |
duke@1 | 74 | * @param configuration the current configuration of the doclet. |
duke@1 | 75 | * @param annotationTypeDoc the class being documented. |
duke@1 | 76 | * @param writer the doclet specific writer. |
duke@1 | 77 | */ |
duke@1 | 78 | public static AnnotationTypeBuilder getInstance(Configuration configuration, |
duke@1 | 79 | AnnotationTypeDoc annotationTypeDoc, AnnotationTypeWriter writer) |
duke@1 | 80 | throws Exception { |
duke@1 | 81 | AnnotationTypeBuilder builder = new AnnotationTypeBuilder(configuration); |
duke@1 | 82 | builder.configuration = configuration; |
duke@1 | 83 | builder.annotationTypeDoc = annotationTypeDoc; |
duke@1 | 84 | builder.writer = writer; |
duke@1 | 85 | if(containingPackagesSeen == null) { |
jjg@74 | 86 | containingPackagesSeen = new HashSet<String>(); |
duke@1 | 87 | } |
duke@1 | 88 | return builder; |
duke@1 | 89 | } |
duke@1 | 90 | |
duke@1 | 91 | /** |
duke@1 | 92 | * {@inheritDoc} |
duke@1 | 93 | */ |
duke@1 | 94 | public void build() throws IOException { |
duke@1 | 95 | build(LayoutParser.getInstance(configuration).parseXML(ROOT)); |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | /** |
duke@1 | 99 | * {@inheritDoc} |
duke@1 | 100 | */ |
duke@1 | 101 | public String getName() { |
duke@1 | 102 | return ROOT; |
duke@1 | 103 | } |
duke@1 | 104 | |
duke@1 | 105 | /** |
duke@1 | 106 | * Handles the <AnnotationTypeDoc> tag. |
duke@1 | 107 | * |
duke@1 | 108 | * @param elements the XML elements that specify how to document a class. |
duke@1 | 109 | */ |
jjg@589 | 110 | public void buildAnnotationTypeDoc(XMLNode node) throws Exception { |
jjg@589 | 111 | buildChildren(node); |
duke@1 | 112 | writer.close(); |
duke@1 | 113 | copyDocFiles(); |
duke@1 | 114 | } |
duke@1 | 115 | |
duke@1 | 116 | |
duke@1 | 117 | /** |
duke@1 | 118 | * Copy the doc files for the current ClassDoc if necessary. |
duke@1 | 119 | */ |
duke@1 | 120 | private void copyDocFiles() { |
duke@1 | 121 | PackageDoc containingPackage = annotationTypeDoc.containingPackage(); |
duke@1 | 122 | if((configuration.packages == null || |
duke@1 | 123 | Arrays.binarySearch(configuration.packages, |
duke@1 | 124 | containingPackage) < 0) && |
duke@1 | 125 | ! containingPackagesSeen.contains(containingPackage.name())){ |
duke@1 | 126 | //Only copy doc files dir if the containing package is not |
duke@1 | 127 | //documented AND if we have not documented a class from the same |
duke@1 | 128 | //package already. Otherwise, we are making duplicate copies. |
duke@1 | 129 | Util.copyDocFiles(configuration, |
duke@1 | 130 | Util.getPackageSourcePath(configuration, |
duke@1 | 131 | annotationTypeDoc.containingPackage()) + |
duke@1 | 132 | DirectoryManager.getDirectoryPath( |
duke@1 | 133 | annotationTypeDoc.containingPackage()) |
duke@1 | 134 | + File.separator, DocletConstants.DOC_FILES_DIR_NAME, true); |
duke@1 | 135 | containingPackagesSeen.add(containingPackage.name()); |
duke@1 | 136 | } |
duke@1 | 137 | } |
duke@1 | 138 | |
duke@1 | 139 | /** |
duke@1 | 140 | * Build the header of the page. |
duke@1 | 141 | */ |
jjg@589 | 142 | public void buildAnnotationTypeHeader(XMLNode node) { |
duke@1 | 143 | writer.writeHeader(configuration.getText("doclet.AnnotationType") + |
duke@1 | 144 | " " + annotationTypeDoc.name()); |
duke@1 | 145 | } |
duke@1 | 146 | |
duke@1 | 147 | /** |
duke@1 | 148 | * If this class is deprecated, print the appropriate information. |
duke@1 | 149 | */ |
jjg@589 | 150 | public void buildDeprecationInfo (XMLNode node) { |
duke@1 | 151 | writer.writeAnnotationTypeDeprecationInfo(); |
duke@1 | 152 | } |
duke@1 | 153 | |
duke@1 | 154 | /** |
duke@1 | 155 | * Build the signature of the current annotation type. |
duke@1 | 156 | */ |
jjg@589 | 157 | public void buildAnnotationTypeSignature(XMLNode node) { |
duke@1 | 158 | StringBuffer modifiers = new StringBuffer( |
duke@1 | 159 | annotationTypeDoc.modifiers() + " "); |
duke@1 | 160 | writer.writeAnnotationTypeSignature( |
duke@1 | 161 | Util.replaceText( |
duke@1 | 162 | modifiers.toString(), "interface", "@interface")); |
duke@1 | 163 | } |
duke@1 | 164 | |
duke@1 | 165 | /** |
duke@1 | 166 | * Build the class description. |
duke@1 | 167 | */ |
jjg@589 | 168 | public void buildAnnotationTypeDescription(XMLNode node) { |
duke@1 | 169 | writer.writeAnnotationTypeDescription(); |
duke@1 | 170 | } |
duke@1 | 171 | |
duke@1 | 172 | /** |
duke@1 | 173 | * Build the tag information for the current class. |
duke@1 | 174 | */ |
jjg@589 | 175 | public void buildAnnotationTypeTagInfo(XMLNode node) { |
duke@1 | 176 | writer.writeAnnotationTypeTagInfo(); |
duke@1 | 177 | } |
duke@1 | 178 | |
duke@1 | 179 | /** |
duke@1 | 180 | * Build the contents of the page. |
duke@1 | 181 | * |
duke@1 | 182 | * @param elements the XML elements that specify how a member summary is |
duke@1 | 183 | * documented. |
duke@1 | 184 | */ |
jjg@589 | 185 | public void buildMemberSummary(XMLNode node) throws Exception { |
duke@1 | 186 | configuration.getBuilderFactory(). |
jjg@589 | 187 | getMemberSummaryBuilder(writer).buildChildren(node); |
duke@1 | 188 | writer.completeMemberSummaryBuild(); |
duke@1 | 189 | } |
duke@1 | 190 | |
duke@1 | 191 | /** |
duke@1 | 192 | * Build the annotation type optional member documentation. |
duke@1 | 193 | * |
duke@1 | 194 | * @param elements the XML elements that specify how a annotation type |
duke@1 | 195 | * members are documented. |
duke@1 | 196 | */ |
jjg@589 | 197 | public void buildAnnotationTypeOptionalMemberDetails(XMLNode node) |
duke@1 | 198 | throws Exception { |
duke@1 | 199 | configuration.getBuilderFactory(). |
jjg@589 | 200 | getAnnotationTypeOptionalMemberBuilder(writer).buildChildren(node); |
duke@1 | 201 | } |
duke@1 | 202 | |
duke@1 | 203 | /** |
duke@1 | 204 | * Build the annotation type required member documentation. |
duke@1 | 205 | * |
duke@1 | 206 | * @param elements the XML elements that specify how a annotation type |
duke@1 | 207 | * members are documented. |
duke@1 | 208 | */ |
jjg@589 | 209 | public void buildAnnotationTypeRequiredMemberDetails(XMLNode node) |
duke@1 | 210 | throws Exception { |
duke@1 | 211 | configuration.getBuilderFactory(). |
jjg@589 | 212 | getAnnotationTypeRequiredMemberBuilder(writer).buildChildren(node); |
duke@1 | 213 | } |
duke@1 | 214 | |
duke@1 | 215 | |
duke@1 | 216 | /** |
duke@1 | 217 | * Build the footer of the page. |
duke@1 | 218 | */ |
jjg@589 | 219 | public void buildAnnotationTypeFooter(XMLNode node) { |
duke@1 | 220 | writer.writeFooter(); |
duke@1 | 221 | } |
duke@1 | 222 | } |