Mon, 19 Nov 2012 16:10:34 -0800
8002304: Group methods by types in methods summary section
Reviewed-by: jjg
duke@1 | 1 | /* |
jjg@1357 | 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.builders; |
duke@1 | 27 | |
bpatel@766 | 28 | import java.io.*; |
bpatel@766 | 29 | import java.util.*; |
jjg@1357 | 30 | |
jjg@1357 | 31 | import com.sun.javadoc.*; |
jjg@1357 | 32 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 33 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * Builds the summary for a given annotation type. |
duke@1 | 37 | * |
jjg@1359 | 38 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 39 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 40 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 41 | * deletion without notice.</b> |
duke@1 | 42 | * |
duke@1 | 43 | * @author Jamie Ho |
bpatel@766 | 44 | * @author Bhavesh Patel (Modified) |
duke@1 | 45 | * @since 1.5 |
duke@1 | 46 | */ |
duke@1 | 47 | public class AnnotationTypeBuilder extends AbstractBuilder { |
duke@1 | 48 | |
duke@1 | 49 | /** |
duke@1 | 50 | * The root element of the annotation type XML is {@value}. |
duke@1 | 51 | */ |
duke@1 | 52 | public static final String ROOT = "AnnotationTypeDoc"; |
duke@1 | 53 | |
duke@1 | 54 | /** |
duke@1 | 55 | * The annotation type being documented. |
duke@1 | 56 | */ |
jjg@1410 | 57 | private final AnnotationTypeDoc annotationTypeDoc; |
duke@1 | 58 | |
duke@1 | 59 | /** |
duke@1 | 60 | * The doclet specific writer. |
duke@1 | 61 | */ |
jjg@1410 | 62 | private final AnnotationTypeWriter writer; |
duke@1 | 63 | |
duke@1 | 64 | /** |
bpatel@766 | 65 | * The content tree for the annotation documentation. |
bpatel@766 | 66 | */ |
bpatel@766 | 67 | private Content contentTree; |
bpatel@766 | 68 | |
bpatel@766 | 69 | /** |
duke@1 | 70 | * Construct a new ClassBuilder. |
duke@1 | 71 | * |
jjg@1410 | 72 | * @param context the build context. |
jjg@1410 | 73 | * @param annotationTypeDoc the class being documented. |
jjg@1410 | 74 | * @param writer the doclet specific writer. |
duke@1 | 75 | */ |
jjg@1410 | 76 | private AnnotationTypeBuilder(Context context, |
jjg@1410 | 77 | AnnotationTypeDoc annotationTypeDoc, |
jjg@1410 | 78 | AnnotationTypeWriter writer) { |
jjg@1410 | 79 | super(context); |
jjg@1410 | 80 | this.annotationTypeDoc = annotationTypeDoc; |
jjg@1410 | 81 | this.writer = writer; |
duke@1 | 82 | } |
duke@1 | 83 | |
duke@1 | 84 | /** |
duke@1 | 85 | * Construct a new ClassBuilder. |
duke@1 | 86 | * |
jjg@1410 | 87 | * @param context the build context. |
duke@1 | 88 | * @param annotationTypeDoc the class being documented. |
duke@1 | 89 | * @param writer the doclet specific writer. |
duke@1 | 90 | */ |
jjg@1410 | 91 | public static AnnotationTypeBuilder getInstance(Context context, |
jjg@1410 | 92 | AnnotationTypeDoc annotationTypeDoc, |
jjg@1410 | 93 | AnnotationTypeWriter writer) |
jjg@1410 | 94 | throws Exception { |
jjg@1410 | 95 | return new AnnotationTypeBuilder(context, annotationTypeDoc, writer); |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | /** |
duke@1 | 99 | * {@inheritDoc} |
duke@1 | 100 | */ |
duke@1 | 101 | public void build() throws IOException { |
jjg@1410 | 102 | build(layoutParser.parseXML(ROOT), contentTree); |
duke@1 | 103 | } |
duke@1 | 104 | |
duke@1 | 105 | /** |
duke@1 | 106 | * {@inheritDoc} |
duke@1 | 107 | */ |
duke@1 | 108 | public String getName() { |
duke@1 | 109 | return ROOT; |
duke@1 | 110 | } |
duke@1 | 111 | |
bpatel@766 | 112 | /** |
bpatel@766 | 113 | * Build the annotation type documentation. |
duke@1 | 114 | * |
bpatel@766 | 115 | * @param node the XML element that specifies which components to document |
bpatel@766 | 116 | * @param contentTree the content tree to which the documentation will be added |
duke@1 | 117 | */ |
bpatel@766 | 118 | public void buildAnnotationTypeDoc(XMLNode node, Content contentTree) throws Exception { |
bpatel@766 | 119 | contentTree = writer.getHeader(configuration.getText("doclet.AnnotationType") + |
bpatel@766 | 120 | " " + annotationTypeDoc.name()); |
bpatel@766 | 121 | Content annotationContentTree = writer.getAnnotationContentHeader(); |
bpatel@766 | 122 | buildChildren(node, annotationContentTree); |
bpatel@766 | 123 | contentTree.addContent(annotationContentTree); |
bpatel@766 | 124 | writer.addFooter(contentTree); |
bpatel@766 | 125 | writer.printDocument(contentTree); |
bpatel@766 | 126 | writer.close(); |
bpatel@766 | 127 | copyDocFiles(); |
duke@1 | 128 | } |
duke@1 | 129 | |
duke@1 | 130 | /** |
duke@1 | 131 | * Copy the doc files for the current ClassDoc if necessary. |
duke@1 | 132 | */ |
duke@1 | 133 | private void copyDocFiles() { |
duke@1 | 134 | PackageDoc containingPackage = annotationTypeDoc.containingPackage(); |
duke@1 | 135 | if((configuration.packages == null || |
duke@1 | 136 | Arrays.binarySearch(configuration.packages, |
duke@1 | 137 | containingPackage) < 0) && |
duke@1 | 138 | ! containingPackagesSeen.contains(containingPackage.name())){ |
duke@1 | 139 | //Only copy doc files dir if the containing package is not |
duke@1 | 140 | //documented AND if we have not documented a class from the same |
duke@1 | 141 | //package already. Otherwise, we are making duplicate copies. |
jjg@1383 | 142 | Util.copyDocFiles(configuration, containingPackage); |
duke@1 | 143 | containingPackagesSeen.add(containingPackage.name()); |
duke@1 | 144 | } |
duke@1 | 145 | } |
duke@1 | 146 | |
duke@1 | 147 | /** |
bpatel@766 | 148 | * Build the annotation information tree documentation. |
bpatel@766 | 149 | * |
bpatel@766 | 150 | * @param node the XML element that specifies which components to document |
bpatel@766 | 151 | * @param annotationContentTree the content tree to which the documentation will be added |
duke@1 | 152 | */ |
bpatel@766 | 153 | public void buildAnnotationTypeInfo(XMLNode node, Content annotationContentTree) { |
bpatel@766 | 154 | Content annotationInfoTree = writer.getAnnotationInfoTreeHeader(); |
bpatel@766 | 155 | buildChildren(node, annotationInfoTree); |
bpatel@766 | 156 | annotationContentTree.addContent(writer.getAnnotationInfo(annotationInfoTree)); |
duke@1 | 157 | } |
duke@1 | 158 | |
duke@1 | 159 | /** |
bpatel@766 | 160 | * If this annotation is deprecated, build the appropriate information. |
bpatel@766 | 161 | * |
bpatel@766 | 162 | * @param node the XML element that specifies which components to document |
bpatel@766 | 163 | * @param annotationInfoTree the content tree to which the documentation will be added |
duke@1 | 164 | */ |
bpatel@766 | 165 | public void buildDeprecationInfo (XMLNode node, Content annotationInfoTree) { |
bpatel@766 | 166 | writer.addAnnotationTypeDeprecationInfo(annotationInfoTree); |
duke@1 | 167 | } |
duke@1 | 168 | |
duke@1 | 169 | /** |
duke@1 | 170 | * Build the signature of the current annotation type. |
bpatel@766 | 171 | * |
bpatel@766 | 172 | * @param node the XML element that specifies which components to document |
bpatel@766 | 173 | * @param annotationInfoTree the content tree to which the documentation will be added |
duke@1 | 174 | */ |
bpatel@766 | 175 | public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) { |
jjg@1362 | 176 | StringBuilder modifiers = new StringBuilder( |
bpatel@766 | 177 | annotationTypeDoc.modifiers() + " "); |
bpatel@766 | 178 | writer.addAnnotationTypeSignature(Util.replaceText( |
bpatel@766 | 179 | modifiers.toString(), "interface", "@interface"), annotationInfoTree); |
duke@1 | 180 | } |
duke@1 | 181 | |
duke@1 | 182 | /** |
bpatel@766 | 183 | * Build the annotation type description. |
bpatel@766 | 184 | * |
bpatel@766 | 185 | * @param node the XML element that specifies which components to document |
bpatel@766 | 186 | * @param annotationInfoTree the content tree to which the documentation will be added |
duke@1 | 187 | */ |
bpatel@766 | 188 | public void buildAnnotationTypeDescription(XMLNode node, Content annotationInfoTree) { |
bpatel@766 | 189 | writer.addAnnotationTypeDescription(annotationInfoTree); |
duke@1 | 190 | } |
duke@1 | 191 | |
duke@1 | 192 | /** |
bpatel@766 | 193 | * Build the tag information for the current annotation type. |
bpatel@766 | 194 | * |
bpatel@766 | 195 | * @param node the XML element that specifies which components to document |
bpatel@766 | 196 | * @param annotationInfoTree the content tree to which the documentation will be added |
duke@1 | 197 | */ |
bpatel@766 | 198 | public void buildAnnotationTypeTagInfo(XMLNode node, Content annotationInfoTree) { |
bpatel@766 | 199 | writer.addAnnotationTypeTagInfo(annotationInfoTree); |
duke@1 | 200 | } |
duke@1 | 201 | |
duke@1 | 202 | /** |
bpatel@766 | 203 | * Build the member summary contents of the page. |
duke@1 | 204 | * |
bpatel@766 | 205 | * @param node the XML element that specifies which components to document |
bpatel@766 | 206 | * @param annotationContentTree the content tree to which the documentation will be added |
duke@1 | 207 | */ |
bpatel@766 | 208 | public void buildMemberSummary(XMLNode node, Content annotationContentTree) |
bpatel@766 | 209 | throws Exception { |
bpatel@766 | 210 | Content memberSummaryTree = writer.getMemberTreeHeader(); |
duke@1 | 211 | configuration.getBuilderFactory(). |
bpatel@766 | 212 | getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree); |
bpatel@766 | 213 | annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree)); |
bpatel@766 | 214 | } |
bpatel@766 | 215 | |
bpatel@766 | 216 | /** |
bpatel@766 | 217 | * Build the member details contents of the page. |
bpatel@766 | 218 | * |
bpatel@766 | 219 | * @param node the XML element that specifies which components to document |
bpatel@766 | 220 | * @param annotationContentTree the content tree to which the documentation will be added |
bpatel@766 | 221 | */ |
bpatel@766 | 222 | public void buildAnnotationTypeMemberDetails(XMLNode node, Content annotationContentTree) { |
bpatel@766 | 223 | Content memberDetailsTree = writer.getMemberTreeHeader(); |
bpatel@766 | 224 | buildChildren(node, memberDetailsTree); |
bpatel@766 | 225 | if (memberDetailsTree.isValid()) { |
bpatel@766 | 226 | Content memberDetails = writer.getMemberTreeHeader(); |
bpatel@766 | 227 | writer.addAnnotationDetailsMarker(memberDetails); |
bpatel@766 | 228 | memberDetails.addContent(writer.getMemberTree(memberDetailsTree)); |
bpatel@766 | 229 | annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetails)); |
bpatel@766 | 230 | } |
duke@1 | 231 | } |
duke@1 | 232 | |
duke@1 | 233 | /** |
duke@1 | 234 | * Build the annotation type optional member documentation. |
duke@1 | 235 | * |
bpatel@766 | 236 | * @param node the XML element that specifies which components to document |
bpatel@766 | 237 | * @param memberDetailsTree the content tree to which the documentation will be added |
duke@1 | 238 | */ |
bpatel@766 | 239 | public void buildAnnotationTypeOptionalMemberDetails(XMLNode node, Content memberDetailsTree) |
bpatel@766 | 240 | throws Exception { |
duke@1 | 241 | configuration.getBuilderFactory(). |
bpatel@766 | 242 | getAnnotationTypeOptionalMemberBuilder(writer).buildChildren(node, memberDetailsTree); |
duke@1 | 243 | } |
duke@1 | 244 | |
duke@1 | 245 | /** |
duke@1 | 246 | * Build the annotation type required member documentation. |
duke@1 | 247 | * |
bpatel@766 | 248 | * @param node the XML element that specifies which components to document |
bpatel@766 | 249 | * @param memberDetailsTree the content tree to which the documentation will be added |
duke@1 | 250 | */ |
bpatel@766 | 251 | public void buildAnnotationTypeRequiredMemberDetails(XMLNode node, Content memberDetailsTree) |
bpatel@766 | 252 | throws Exception { |
duke@1 | 253 | configuration.getBuilderFactory(). |
bpatel@766 | 254 | getAnnotationTypeRequiredMemberBuilder(writer).buildChildren(node, memberDetailsTree); |
duke@1 | 255 | } |
duke@1 | 256 | } |