Tue, 23 Oct 2012 13:20:37 -0700
8000741: refactor javadoc to use abstraction to handle relative paths
Reviewed-by: darcy
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 | */ |
duke@1 | 57 | private AnnotationTypeDoc annotationTypeDoc; |
duke@1 | 58 | |
duke@1 | 59 | /** |
duke@1 | 60 | * The doclet specific writer. |
duke@1 | 61 | */ |
duke@1 | 62 | private 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 | * |
duke@1 | 72 | * @param configuration the current configuration of the |
duke@1 | 73 | * doclet. |
duke@1 | 74 | */ |
duke@1 | 75 | private AnnotationTypeBuilder(Configuration configuration) { |
duke@1 | 76 | super(configuration); |
duke@1 | 77 | } |
duke@1 | 78 | |
duke@1 | 79 | /** |
duke@1 | 80 | * Construct a new ClassBuilder. |
duke@1 | 81 | * |
duke@1 | 82 | * @param configuration the current configuration of the doclet. |
duke@1 | 83 | * @param annotationTypeDoc the class being documented. |
duke@1 | 84 | * @param writer the doclet specific writer. |
duke@1 | 85 | */ |
duke@1 | 86 | public static AnnotationTypeBuilder getInstance(Configuration configuration, |
duke@1 | 87 | AnnotationTypeDoc annotationTypeDoc, AnnotationTypeWriter writer) |
duke@1 | 88 | throws Exception { |
duke@1 | 89 | AnnotationTypeBuilder builder = new AnnotationTypeBuilder(configuration); |
duke@1 | 90 | builder.configuration = configuration; |
duke@1 | 91 | builder.annotationTypeDoc = annotationTypeDoc; |
duke@1 | 92 | builder.writer = writer; |
duke@1 | 93 | if(containingPackagesSeen == null) { |
jjg@74 | 94 | containingPackagesSeen = new HashSet<String>(); |
duke@1 | 95 | } |
duke@1 | 96 | return builder; |
duke@1 | 97 | } |
duke@1 | 98 | |
duke@1 | 99 | /** |
duke@1 | 100 | * {@inheritDoc} |
duke@1 | 101 | */ |
duke@1 | 102 | public void build() throws IOException { |
bpatel@766 | 103 | build(LayoutParser.getInstance(configuration).parseXML(ROOT), contentTree); |
duke@1 | 104 | } |
duke@1 | 105 | |
duke@1 | 106 | /** |
duke@1 | 107 | * {@inheritDoc} |
duke@1 | 108 | */ |
duke@1 | 109 | public String getName() { |
duke@1 | 110 | return ROOT; |
duke@1 | 111 | } |
duke@1 | 112 | |
bpatel@766 | 113 | /** |
bpatel@766 | 114 | * Build the annotation type documentation. |
duke@1 | 115 | * |
bpatel@766 | 116 | * @param node the XML element that specifies which components to document |
bpatel@766 | 117 | * @param contentTree the content tree to which the documentation will be added |
duke@1 | 118 | */ |
bpatel@766 | 119 | public void buildAnnotationTypeDoc(XMLNode node, Content contentTree) throws Exception { |
bpatel@766 | 120 | contentTree = writer.getHeader(configuration.getText("doclet.AnnotationType") + |
bpatel@766 | 121 | " " + annotationTypeDoc.name()); |
bpatel@766 | 122 | Content annotationContentTree = writer.getAnnotationContentHeader(); |
bpatel@766 | 123 | buildChildren(node, annotationContentTree); |
bpatel@766 | 124 | contentTree.addContent(annotationContentTree); |
bpatel@766 | 125 | writer.addFooter(contentTree); |
bpatel@766 | 126 | writer.printDocument(contentTree); |
bpatel@766 | 127 | writer.close(); |
bpatel@766 | 128 | copyDocFiles(); |
duke@1 | 129 | } |
duke@1 | 130 | |
duke@1 | 131 | /** |
duke@1 | 132 | * Copy the doc files for the current ClassDoc if necessary. |
duke@1 | 133 | */ |
duke@1 | 134 | private void copyDocFiles() { |
duke@1 | 135 | PackageDoc containingPackage = annotationTypeDoc.containingPackage(); |
duke@1 | 136 | if((configuration.packages == null || |
duke@1 | 137 | Arrays.binarySearch(configuration.packages, |
duke@1 | 138 | containingPackage) < 0) && |
duke@1 | 139 | ! containingPackagesSeen.contains(containingPackage.name())){ |
duke@1 | 140 | //Only copy doc files dir if the containing package is not |
duke@1 | 141 | //documented AND if we have not documented a class from the same |
duke@1 | 142 | //package already. Otherwise, we are making duplicate copies. |
duke@1 | 143 | Util.copyDocFiles(configuration, |
jjg@1372 | 144 | new File(Util.getPackageSourcePath(configuration, containingPackage), |
jjg@1372 | 145 | DocPath.forPackage(annotationTypeDoc).getPath()), |
jjg@1372 | 146 | DocPaths.DOC_FILES, true); |
duke@1 | 147 | containingPackagesSeen.add(containingPackage.name()); |
duke@1 | 148 | } |
duke@1 | 149 | } |
duke@1 | 150 | |
duke@1 | 151 | /** |
bpatel@766 | 152 | * Build the annotation information tree documentation. |
bpatel@766 | 153 | * |
bpatel@766 | 154 | * @param node the XML element that specifies which components to document |
bpatel@766 | 155 | * @param annotationContentTree the content tree to which the documentation will be added |
duke@1 | 156 | */ |
bpatel@766 | 157 | public void buildAnnotationTypeInfo(XMLNode node, Content annotationContentTree) { |
bpatel@766 | 158 | Content annotationInfoTree = writer.getAnnotationInfoTreeHeader(); |
bpatel@766 | 159 | buildChildren(node, annotationInfoTree); |
bpatel@766 | 160 | annotationContentTree.addContent(writer.getAnnotationInfo(annotationInfoTree)); |
duke@1 | 161 | } |
duke@1 | 162 | |
duke@1 | 163 | /** |
bpatel@766 | 164 | * If this annotation is deprecated, build the appropriate information. |
bpatel@766 | 165 | * |
bpatel@766 | 166 | * @param node the XML element that specifies which components to document |
bpatel@766 | 167 | * @param annotationInfoTree the content tree to which the documentation will be added |
duke@1 | 168 | */ |
bpatel@766 | 169 | public void buildDeprecationInfo (XMLNode node, Content annotationInfoTree) { |
bpatel@766 | 170 | writer.addAnnotationTypeDeprecationInfo(annotationInfoTree); |
duke@1 | 171 | } |
duke@1 | 172 | |
duke@1 | 173 | /** |
duke@1 | 174 | * Build the signature of the current annotation type. |
bpatel@766 | 175 | * |
bpatel@766 | 176 | * @param node the XML element that specifies which components to document |
bpatel@766 | 177 | * @param annotationInfoTree the content tree to which the documentation will be added |
duke@1 | 178 | */ |
bpatel@766 | 179 | public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) { |
jjg@1362 | 180 | StringBuilder modifiers = new StringBuilder( |
bpatel@766 | 181 | annotationTypeDoc.modifiers() + " "); |
bpatel@766 | 182 | writer.addAnnotationTypeSignature(Util.replaceText( |
bpatel@766 | 183 | modifiers.toString(), "interface", "@interface"), annotationInfoTree); |
duke@1 | 184 | } |
duke@1 | 185 | |
duke@1 | 186 | /** |
bpatel@766 | 187 | * Build the annotation type description. |
bpatel@766 | 188 | * |
bpatel@766 | 189 | * @param node the XML element that specifies which components to document |
bpatel@766 | 190 | * @param annotationInfoTree the content tree to which the documentation will be added |
duke@1 | 191 | */ |
bpatel@766 | 192 | public void buildAnnotationTypeDescription(XMLNode node, Content annotationInfoTree) { |
bpatel@766 | 193 | writer.addAnnotationTypeDescription(annotationInfoTree); |
duke@1 | 194 | } |
duke@1 | 195 | |
duke@1 | 196 | /** |
bpatel@766 | 197 | * Build the tag information for the current annotation type. |
bpatel@766 | 198 | * |
bpatel@766 | 199 | * @param node the XML element that specifies which components to document |
bpatel@766 | 200 | * @param annotationInfoTree the content tree to which the documentation will be added |
duke@1 | 201 | */ |
bpatel@766 | 202 | public void buildAnnotationTypeTagInfo(XMLNode node, Content annotationInfoTree) { |
bpatel@766 | 203 | writer.addAnnotationTypeTagInfo(annotationInfoTree); |
duke@1 | 204 | } |
duke@1 | 205 | |
duke@1 | 206 | /** |
bpatel@766 | 207 | * Build the member summary contents of the page. |
duke@1 | 208 | * |
bpatel@766 | 209 | * @param node the XML element that specifies which components to document |
bpatel@766 | 210 | * @param annotationContentTree the content tree to which the documentation will be added |
duke@1 | 211 | */ |
bpatel@766 | 212 | public void buildMemberSummary(XMLNode node, Content annotationContentTree) |
bpatel@766 | 213 | throws Exception { |
bpatel@766 | 214 | Content memberSummaryTree = writer.getMemberTreeHeader(); |
duke@1 | 215 | configuration.getBuilderFactory(). |
bpatel@766 | 216 | getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree); |
bpatel@766 | 217 | annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree)); |
bpatel@766 | 218 | } |
bpatel@766 | 219 | |
bpatel@766 | 220 | /** |
bpatel@766 | 221 | * Build the member details contents of the page. |
bpatel@766 | 222 | * |
bpatel@766 | 223 | * @param node the XML element that specifies which components to document |
bpatel@766 | 224 | * @param annotationContentTree the content tree to which the documentation will be added |
bpatel@766 | 225 | */ |
bpatel@766 | 226 | public void buildAnnotationTypeMemberDetails(XMLNode node, Content annotationContentTree) { |
bpatel@766 | 227 | Content memberDetailsTree = writer.getMemberTreeHeader(); |
bpatel@766 | 228 | buildChildren(node, memberDetailsTree); |
bpatel@766 | 229 | if (memberDetailsTree.isValid()) { |
bpatel@766 | 230 | Content memberDetails = writer.getMemberTreeHeader(); |
bpatel@766 | 231 | writer.addAnnotationDetailsMarker(memberDetails); |
bpatel@766 | 232 | memberDetails.addContent(writer.getMemberTree(memberDetailsTree)); |
bpatel@766 | 233 | annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetails)); |
bpatel@766 | 234 | } |
duke@1 | 235 | } |
duke@1 | 236 | |
duke@1 | 237 | /** |
duke@1 | 238 | * Build the annotation type optional member documentation. |
duke@1 | 239 | * |
bpatel@766 | 240 | * @param node the XML element that specifies which components to document |
bpatel@766 | 241 | * @param memberDetailsTree the content tree to which the documentation will be added |
duke@1 | 242 | */ |
bpatel@766 | 243 | public void buildAnnotationTypeOptionalMemberDetails(XMLNode node, Content memberDetailsTree) |
bpatel@766 | 244 | throws Exception { |
duke@1 | 245 | configuration.getBuilderFactory(). |
bpatel@766 | 246 | getAnnotationTypeOptionalMemberBuilder(writer).buildChildren(node, memberDetailsTree); |
duke@1 | 247 | } |
duke@1 | 248 | |
duke@1 | 249 | /** |
duke@1 | 250 | * Build the annotation type required member documentation. |
duke@1 | 251 | * |
bpatel@766 | 252 | * @param node the XML element that specifies which components to document |
bpatel@766 | 253 | * @param memberDetailsTree the content tree to which the documentation will be added |
duke@1 | 254 | */ |
bpatel@766 | 255 | public void buildAnnotationTypeRequiredMemberDetails(XMLNode node, Content memberDetailsTree) |
bpatel@766 | 256 | throws Exception { |
duke@1 | 257 | configuration.getBuilderFactory(). |
bpatel@766 | 258 | getAnnotationTypeRequiredMemberBuilder(writer).buildChildren(node, memberDetailsTree); |
duke@1 | 259 | } |
duke@1 | 260 | } |