src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AnnotationTypeBuilder.java

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 798
4868a36f6fd8
child 1359
25e14ad23cef
permissions
-rw-r--r--

8000663: clean up langtools imports
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 *
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
bpatel@766 43 * @author Bhavesh Patel (Modified)
duke@1 44 * @since 1.5
duke@1 45 */
duke@1 46 public class AnnotationTypeBuilder extends AbstractBuilder {
duke@1 47
duke@1 48 /**
duke@1 49 * The root element of the annotation type XML is {@value}.
duke@1 50 */
duke@1 51 public static final String ROOT = "AnnotationTypeDoc";
duke@1 52
duke@1 53 /**
duke@1 54 * The annotation type being documented.
duke@1 55 */
duke@1 56 private AnnotationTypeDoc annotationTypeDoc;
duke@1 57
duke@1 58 /**
duke@1 59 * The doclet specific writer.
duke@1 60 */
duke@1 61 private AnnotationTypeWriter writer;
duke@1 62
duke@1 63 /**
bpatel@766 64 * The content tree for the annotation documentation.
bpatel@766 65 */
bpatel@766 66 private Content contentTree;
bpatel@766 67
bpatel@766 68 /**
duke@1 69 * Construct a new ClassBuilder.
duke@1 70 *
duke@1 71 * @param configuration the current configuration of the
duke@1 72 * doclet.
duke@1 73 */
duke@1 74 private AnnotationTypeBuilder(Configuration configuration) {
duke@1 75 super(configuration);
duke@1 76 }
duke@1 77
duke@1 78 /**
duke@1 79 * Construct a new ClassBuilder.
duke@1 80 *
duke@1 81 * @param configuration the current configuration of the doclet.
duke@1 82 * @param annotationTypeDoc the class being documented.
duke@1 83 * @param writer the doclet specific writer.
duke@1 84 */
duke@1 85 public static AnnotationTypeBuilder getInstance(Configuration configuration,
duke@1 86 AnnotationTypeDoc annotationTypeDoc, AnnotationTypeWriter writer)
duke@1 87 throws Exception {
duke@1 88 AnnotationTypeBuilder builder = new AnnotationTypeBuilder(configuration);
duke@1 89 builder.configuration = configuration;
duke@1 90 builder.annotationTypeDoc = annotationTypeDoc;
duke@1 91 builder.writer = writer;
duke@1 92 if(containingPackagesSeen == null) {
jjg@74 93 containingPackagesSeen = new HashSet<String>();
duke@1 94 }
duke@1 95 return builder;
duke@1 96 }
duke@1 97
duke@1 98 /**
duke@1 99 * {@inheritDoc}
duke@1 100 */
duke@1 101 public void build() throws IOException {
bpatel@766 102 build(LayoutParser.getInstance(configuration).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.
duke@1 142 Util.copyDocFiles(configuration,
duke@1 143 Util.getPackageSourcePath(configuration,
duke@1 144 annotationTypeDoc.containingPackage()) +
duke@1 145 DirectoryManager.getDirectoryPath(
duke@1 146 annotationTypeDoc.containingPackage())
duke@1 147 + File.separator, DocletConstants.DOC_FILES_DIR_NAME, true);
duke@1 148 containingPackagesSeen.add(containingPackage.name());
duke@1 149 }
duke@1 150 }
duke@1 151
duke@1 152 /**
bpatel@766 153 * Build the annotation information tree documentation.
bpatel@766 154 *
bpatel@766 155 * @param node the XML element that specifies which components to document
bpatel@766 156 * @param annotationContentTree the content tree to which the documentation will be added
duke@1 157 */
bpatel@766 158 public void buildAnnotationTypeInfo(XMLNode node, Content annotationContentTree) {
bpatel@766 159 Content annotationInfoTree = writer.getAnnotationInfoTreeHeader();
bpatel@766 160 buildChildren(node, annotationInfoTree);
bpatel@766 161 annotationContentTree.addContent(writer.getAnnotationInfo(annotationInfoTree));
duke@1 162 }
duke@1 163
duke@1 164 /**
bpatel@766 165 * If this annotation is deprecated, build the appropriate information.
bpatel@766 166 *
bpatel@766 167 * @param node the XML element that specifies which components to document
bpatel@766 168 * @param annotationInfoTree the content tree to which the documentation will be added
duke@1 169 */
bpatel@766 170 public void buildDeprecationInfo (XMLNode node, Content annotationInfoTree) {
bpatel@766 171 writer.addAnnotationTypeDeprecationInfo(annotationInfoTree);
duke@1 172 }
duke@1 173
duke@1 174 /**
duke@1 175 * Build the signature of the current annotation type.
bpatel@766 176 *
bpatel@766 177 * @param node the XML element that specifies which components to document
bpatel@766 178 * @param annotationInfoTree the content tree to which the documentation will be added
duke@1 179 */
bpatel@766 180 public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) {
duke@1 181 StringBuffer modifiers = new StringBuffer(
bpatel@766 182 annotationTypeDoc.modifiers() + " ");
bpatel@766 183 writer.addAnnotationTypeSignature(Util.replaceText(
bpatel@766 184 modifiers.toString(), "interface", "@interface"), annotationInfoTree);
duke@1 185 }
duke@1 186
duke@1 187 /**
bpatel@766 188 * Build the annotation type description.
bpatel@766 189 *
bpatel@766 190 * @param node the XML element that specifies which components to document
bpatel@766 191 * @param annotationInfoTree the content tree to which the documentation will be added
duke@1 192 */
bpatel@766 193 public void buildAnnotationTypeDescription(XMLNode node, Content annotationInfoTree) {
bpatel@766 194 writer.addAnnotationTypeDescription(annotationInfoTree);
duke@1 195 }
duke@1 196
duke@1 197 /**
bpatel@766 198 * Build the tag information for the current annotation type.
bpatel@766 199 *
bpatel@766 200 * @param node the XML element that specifies which components to document
bpatel@766 201 * @param annotationInfoTree the content tree to which the documentation will be added
duke@1 202 */
bpatel@766 203 public void buildAnnotationTypeTagInfo(XMLNode node, Content annotationInfoTree) {
bpatel@766 204 writer.addAnnotationTypeTagInfo(annotationInfoTree);
duke@1 205 }
duke@1 206
duke@1 207 /**
bpatel@766 208 * Build the member summary contents of the page.
duke@1 209 *
bpatel@766 210 * @param node the XML element that specifies which components to document
bpatel@766 211 * @param annotationContentTree the content tree to which the documentation will be added
duke@1 212 */
bpatel@766 213 public void buildMemberSummary(XMLNode node, Content annotationContentTree)
bpatel@766 214 throws Exception {
bpatel@766 215 Content memberSummaryTree = writer.getMemberTreeHeader();
duke@1 216 configuration.getBuilderFactory().
bpatel@766 217 getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
bpatel@766 218 annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
bpatel@766 219 }
bpatel@766 220
bpatel@766 221 /**
bpatel@766 222 * Build the member details contents of the page.
bpatel@766 223 *
bpatel@766 224 * @param node the XML element that specifies which components to document
bpatel@766 225 * @param annotationContentTree the content tree to which the documentation will be added
bpatel@766 226 */
bpatel@766 227 public void buildAnnotationTypeMemberDetails(XMLNode node, Content annotationContentTree) {
bpatel@766 228 Content memberDetailsTree = writer.getMemberTreeHeader();
bpatel@766 229 buildChildren(node, memberDetailsTree);
bpatel@766 230 if (memberDetailsTree.isValid()) {
bpatel@766 231 Content memberDetails = writer.getMemberTreeHeader();
bpatel@766 232 writer.addAnnotationDetailsMarker(memberDetails);
bpatel@766 233 memberDetails.addContent(writer.getMemberTree(memberDetailsTree));
bpatel@766 234 annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetails));
bpatel@766 235 }
duke@1 236 }
duke@1 237
duke@1 238 /**
duke@1 239 * Build the annotation type optional member documentation.
duke@1 240 *
bpatel@766 241 * @param node the XML element that specifies which components to document
bpatel@766 242 * @param memberDetailsTree the content tree to which the documentation will be added
duke@1 243 */
bpatel@766 244 public void buildAnnotationTypeOptionalMemberDetails(XMLNode node, Content memberDetailsTree)
bpatel@766 245 throws Exception {
duke@1 246 configuration.getBuilderFactory().
bpatel@766 247 getAnnotationTypeOptionalMemberBuilder(writer).buildChildren(node, memberDetailsTree);
duke@1 248 }
duke@1 249
duke@1 250 /**
duke@1 251 * Build the annotation type required member documentation.
duke@1 252 *
bpatel@766 253 * @param node the XML element that specifies which components to document
bpatel@766 254 * @param memberDetailsTree the content tree to which the documentation will be added
duke@1 255 */
bpatel@766 256 public void buildAnnotationTypeRequiredMemberDetails(XMLNode node, Content memberDetailsTree)
bpatel@766 257 throws Exception {
duke@1 258 configuration.getBuilderFactory().
bpatel@766 259 getAnnotationTypeRequiredMemberBuilder(writer).buildChildren(node, memberDetailsTree);
duke@1 260 }
duke@1 261 }

mercurial