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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.internal.toolkit.builders;
aoqi@0 27
aoqi@0 28 import java.io.*;
aoqi@0 29
aoqi@0 30 import com.sun.javadoc.*;
aoqi@0 31 import com.sun.tools.javac.jvm.Profile;
aoqi@0 32 import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0 33 import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0 34
aoqi@0 35 /**
aoqi@0 36 * Builds the summary for a given profile.
aoqi@0 37 *
aoqi@0 38 * <p><b>This is NOT part of any supported API.
aoqi@0 39 * If you write code that depends on this, you do so at your own risk.
aoqi@0 40 * This code and its internal interfaces are subject to change or
aoqi@0 41 * deletion without notice.</b>
aoqi@0 42 *
aoqi@0 43 * @author Bhavesh Patel
aoqi@0 44 */
aoqi@0 45 public class ProfileSummaryBuilder extends AbstractBuilder {
aoqi@0 46 /**
aoqi@0 47 * The root element of the profile summary XML is {@value}.
aoqi@0 48 */
aoqi@0 49 public static final String ROOT = "ProfileDoc";
aoqi@0 50
aoqi@0 51 /**
aoqi@0 52 * The profile being documented.
aoqi@0 53 */
aoqi@0 54 private final Profile profile;
aoqi@0 55
aoqi@0 56 /**
aoqi@0 57 * The doclet specific writer that will output the result.
aoqi@0 58 */
aoqi@0 59 private final ProfileSummaryWriter profileWriter;
aoqi@0 60
aoqi@0 61 /**
aoqi@0 62 * The content that will be added to the profile summary documentation tree.
aoqi@0 63 */
aoqi@0 64 private Content contentTree;
aoqi@0 65
aoqi@0 66 /**
aoqi@0 67 * The profile package being documented.
aoqi@0 68 */
aoqi@0 69 private PackageDoc pkg;
aoqi@0 70
aoqi@0 71 /**
aoqi@0 72 * Construct a new ProfileSummaryBuilder.
aoqi@0 73 *
aoqi@0 74 * @param context the build context.
aoqi@0 75 * @param profile the profile being documented.
aoqi@0 76 * @param profileWriter the doclet specific writer that will output the
aoqi@0 77 * result.
aoqi@0 78 */
aoqi@0 79 private ProfileSummaryBuilder(Context context,
aoqi@0 80 Profile profile, ProfileSummaryWriter profileWriter) {
aoqi@0 81 super(context);
aoqi@0 82 this.profile = profile;
aoqi@0 83 this.profileWriter = profileWriter;
aoqi@0 84 }
aoqi@0 85
aoqi@0 86 /**
aoqi@0 87 * Construct a new ProfileSummaryBuilder.
aoqi@0 88 *
aoqi@0 89 * @param context the build context.
aoqi@0 90 * @param profile the profile being documented.
aoqi@0 91 * @param profileWriter the doclet specific writer that will output the
aoqi@0 92 * result.
aoqi@0 93 *
aoqi@0 94 * @return an instance of a ProfileSummaryBuilder.
aoqi@0 95 */
aoqi@0 96 public static ProfileSummaryBuilder getInstance(Context context,
aoqi@0 97 Profile profile, ProfileSummaryWriter profileWriter) {
aoqi@0 98 return new ProfileSummaryBuilder(context, profile, profileWriter);
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 /**
aoqi@0 102 * Build the profile summary.
aoqi@0 103 */
aoqi@0 104 public void build() throws IOException {
aoqi@0 105 if (profileWriter == null) {
aoqi@0 106 //Doclet does not support this output.
aoqi@0 107 return;
aoqi@0 108 }
aoqi@0 109 build(layoutParser.parseXML(ROOT), contentTree);
aoqi@0 110 }
aoqi@0 111
aoqi@0 112 /**
aoqi@0 113 * {@inheritDoc}
aoqi@0 114 */
aoqi@0 115 public String getName() {
aoqi@0 116 return ROOT;
aoqi@0 117 }
aoqi@0 118
aoqi@0 119 /**
aoqi@0 120 * Build the profile documentation.
aoqi@0 121 *
aoqi@0 122 * @param node the XML element that specifies which components to document
aoqi@0 123 * @param contentTree the content tree to which the documentation will be added
aoqi@0 124 */
aoqi@0 125 public void buildProfileDoc(XMLNode node, Content contentTree) throws Exception {
aoqi@0 126 contentTree = profileWriter.getProfileHeader(profile.name);
aoqi@0 127 buildChildren(node, contentTree);
aoqi@0 128 profileWriter.addProfileFooter(contentTree);
aoqi@0 129 profileWriter.printDocument(contentTree);
aoqi@0 130 profileWriter.close();
aoqi@0 131 Util.copyDocFiles(configuration, DocPaths.profileSummary(profile.name));
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 /**
aoqi@0 135 * Build the content for the profile doc.
aoqi@0 136 *
aoqi@0 137 * @param node the XML element that specifies which components to document
aoqi@0 138 * @param contentTree the content tree to which the profile contents
aoqi@0 139 * will be added
aoqi@0 140 */
aoqi@0 141 public void buildContent(XMLNode node, Content contentTree) {
aoqi@0 142 Content profileContentTree = profileWriter.getContentHeader();
aoqi@0 143 buildChildren(node, profileContentTree);
aoqi@0 144 contentTree.addContent(profileContentTree);
aoqi@0 145 }
aoqi@0 146
aoqi@0 147 /**
aoqi@0 148 * Build the profile summary.
aoqi@0 149 *
aoqi@0 150 * @param node the XML element that specifies which components to document
aoqi@0 151 * @param profileContentTree the profile content tree to which the summaries will
aoqi@0 152 * be added
aoqi@0 153 */
aoqi@0 154 public void buildSummary(XMLNode node, Content profileContentTree) {
aoqi@0 155 Content summaryContentTree = profileWriter.getSummaryHeader();
aoqi@0 156 buildChildren(node, summaryContentTree);
aoqi@0 157 profileContentTree.addContent(profileWriter.getSummaryTree(summaryContentTree));
aoqi@0 158 }
aoqi@0 159
aoqi@0 160 /**
aoqi@0 161 * Build the profile package summary.
aoqi@0 162 *
aoqi@0 163 * @param node the XML element that specifies which components to document
aoqi@0 164 * @param summaryContentTree the content tree to which the summaries will
aoqi@0 165 * be added
aoqi@0 166 */
aoqi@0 167 public void buildPackageSummary(XMLNode node, Content summaryContentTree) {
aoqi@0 168 PackageDoc[] packages = configuration.profilePackages.get(profile.name);
aoqi@0 169 for (int i = 0; i < packages.length; i++) {
aoqi@0 170 this.pkg = packages[i];
aoqi@0 171 Content packageSummaryContentTree = profileWriter.getPackageSummaryHeader(this.pkg);
aoqi@0 172 buildChildren(node, packageSummaryContentTree);
aoqi@0 173 summaryContentTree.addContent(profileWriter.getPackageSummaryTree(
aoqi@0 174 packageSummaryContentTree));
aoqi@0 175 }
aoqi@0 176 }
aoqi@0 177
aoqi@0 178 /**
aoqi@0 179 * Build the summary for the interfaces in the package.
aoqi@0 180 *
aoqi@0 181 * @param node the XML element that specifies which components to document
aoqi@0 182 * @param packageSummaryContentTree the tree to which the interface summary
aoqi@0 183 * will be added
aoqi@0 184 */
aoqi@0 185 public void buildInterfaceSummary(XMLNode node, Content packageSummaryContentTree) {
aoqi@0 186 String interfaceTableSummary =
aoqi@0 187 configuration.getText("doclet.Member_Table_Summary",
aoqi@0 188 configuration.getText("doclet.Interface_Summary"),
aoqi@0 189 configuration.getText("doclet.interfaces"));
aoqi@0 190 String[] interfaceTableHeader = new String[] {
aoqi@0 191 configuration.getText("doclet.Interface"),
aoqi@0 192 configuration.getText("doclet.Description")
aoqi@0 193 };
aoqi@0 194 ClassDoc[] interfaces = pkg.interfaces();
aoqi@0 195 if (interfaces.length > 0) {
aoqi@0 196 profileWriter.addClassesSummary(
aoqi@0 197 interfaces,
aoqi@0 198 configuration.getText("doclet.Interface_Summary"),
aoqi@0 199 interfaceTableSummary, interfaceTableHeader, packageSummaryContentTree);
aoqi@0 200 }
aoqi@0 201 }
aoqi@0 202
aoqi@0 203 /**
aoqi@0 204 * Build the summary for the classes in the package.
aoqi@0 205 *
aoqi@0 206 * @param node the XML element that specifies which components to document
aoqi@0 207 * @param packageSummaryContentTree the tree to which the class summary will
aoqi@0 208 * be added
aoqi@0 209 */
aoqi@0 210 public void buildClassSummary(XMLNode node, Content packageSummaryContentTree) {
aoqi@0 211 String classTableSummary =
aoqi@0 212 configuration.getText("doclet.Member_Table_Summary",
aoqi@0 213 configuration.getText("doclet.Class_Summary"),
aoqi@0 214 configuration.getText("doclet.classes"));
aoqi@0 215 String[] classTableHeader = new String[] {
aoqi@0 216 configuration.getText("doclet.Class"),
aoqi@0 217 configuration.getText("doclet.Description")
aoqi@0 218 };
aoqi@0 219 ClassDoc[] classes = pkg.ordinaryClasses();
aoqi@0 220 if (classes.length > 0) {
aoqi@0 221 profileWriter.addClassesSummary(
aoqi@0 222 classes,
aoqi@0 223 configuration.getText("doclet.Class_Summary"),
aoqi@0 224 classTableSummary, classTableHeader, packageSummaryContentTree);
aoqi@0 225 }
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 /**
aoqi@0 229 * Build the summary for the enums in the package.
aoqi@0 230 *
aoqi@0 231 * @param node the XML element that specifies which components to document
aoqi@0 232 * @param packageSummaryContentTree the tree to which the enum summary will
aoqi@0 233 * be added
aoqi@0 234 */
aoqi@0 235 public void buildEnumSummary(XMLNode node, Content packageSummaryContentTree) {
aoqi@0 236 String enumTableSummary =
aoqi@0 237 configuration.getText("doclet.Member_Table_Summary",
aoqi@0 238 configuration.getText("doclet.Enum_Summary"),
aoqi@0 239 configuration.getText("doclet.enums"));
aoqi@0 240 String[] enumTableHeader = new String[] {
aoqi@0 241 configuration.getText("doclet.Enum"),
aoqi@0 242 configuration.getText("doclet.Description")
aoqi@0 243 };
aoqi@0 244 ClassDoc[] enums = pkg.enums();
aoqi@0 245 if (enums.length > 0) {
aoqi@0 246 profileWriter.addClassesSummary(
aoqi@0 247 enums,
aoqi@0 248 configuration.getText("doclet.Enum_Summary"),
aoqi@0 249 enumTableSummary, enumTableHeader, packageSummaryContentTree);
aoqi@0 250 }
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 /**
aoqi@0 254 * Build the summary for the exceptions in the package.
aoqi@0 255 *
aoqi@0 256 * @param node the XML element that specifies which components to document
aoqi@0 257 * @param packageSummaryContentTree the tree to which the exception summary will
aoqi@0 258 * be added
aoqi@0 259 */
aoqi@0 260 public void buildExceptionSummary(XMLNode node, Content packageSummaryContentTree) {
aoqi@0 261 String exceptionTableSummary =
aoqi@0 262 configuration.getText("doclet.Member_Table_Summary",
aoqi@0 263 configuration.getText("doclet.Exception_Summary"),
aoqi@0 264 configuration.getText("doclet.exceptions"));
aoqi@0 265 String[] exceptionTableHeader = new String[] {
aoqi@0 266 configuration.getText("doclet.Exception"),
aoqi@0 267 configuration.getText("doclet.Description")
aoqi@0 268 };
aoqi@0 269 ClassDoc[] exceptions = pkg.exceptions();
aoqi@0 270 if (exceptions.length > 0) {
aoqi@0 271 profileWriter.addClassesSummary(
aoqi@0 272 exceptions,
aoqi@0 273 configuration.getText("doclet.Exception_Summary"),
aoqi@0 274 exceptionTableSummary, exceptionTableHeader, packageSummaryContentTree);
aoqi@0 275 }
aoqi@0 276 }
aoqi@0 277
aoqi@0 278 /**
aoqi@0 279 * Build the summary for the errors in the package.
aoqi@0 280 *
aoqi@0 281 * @param node the XML element that specifies which components to document
aoqi@0 282 * @param packageSummaryContentTree the tree to which the error summary will
aoqi@0 283 * be added
aoqi@0 284 */
aoqi@0 285 public void buildErrorSummary(XMLNode node, Content packageSummaryContentTree) {
aoqi@0 286 String errorTableSummary =
aoqi@0 287 configuration.getText("doclet.Member_Table_Summary",
aoqi@0 288 configuration.getText("doclet.Error_Summary"),
aoqi@0 289 configuration.getText("doclet.errors"));
aoqi@0 290 String[] errorTableHeader = new String[] {
aoqi@0 291 configuration.getText("doclet.Error"),
aoqi@0 292 configuration.getText("doclet.Description")
aoqi@0 293 };
aoqi@0 294 ClassDoc[] errors = pkg.errors();
aoqi@0 295 if (errors.length > 0) {
aoqi@0 296 profileWriter.addClassesSummary(
aoqi@0 297 errors,
aoqi@0 298 configuration.getText("doclet.Error_Summary"),
aoqi@0 299 errorTableSummary, errorTableHeader, packageSummaryContentTree);
aoqi@0 300 }
aoqi@0 301 }
aoqi@0 302
aoqi@0 303 /**
aoqi@0 304 * Build the summary for the annotation type in the package.
aoqi@0 305 *
aoqi@0 306 * @param node the XML element that specifies which components to document
aoqi@0 307 * @param packageSummaryContentTree the tree to which the annotation type
aoqi@0 308 * summary will be added
aoqi@0 309 */
aoqi@0 310 public void buildAnnotationTypeSummary(XMLNode node, Content packageSummaryContentTree) {
aoqi@0 311 String annotationtypeTableSummary =
aoqi@0 312 configuration.getText("doclet.Member_Table_Summary",
aoqi@0 313 configuration.getText("doclet.Annotation_Types_Summary"),
aoqi@0 314 configuration.getText("doclet.annotationtypes"));
aoqi@0 315 String[] annotationtypeTableHeader = new String[] {
aoqi@0 316 configuration.getText("doclet.AnnotationType"),
aoqi@0 317 configuration.getText("doclet.Description")
aoqi@0 318 };
aoqi@0 319 ClassDoc[] annotationTypes = pkg.annotationTypes();
aoqi@0 320 if (annotationTypes.length > 0) {
aoqi@0 321 profileWriter.addClassesSummary(
aoqi@0 322 annotationTypes,
aoqi@0 323 configuration.getText("doclet.Annotation_Types_Summary"),
aoqi@0 324 annotationtypeTableSummary, annotationtypeTableHeader,
aoqi@0 325 packageSummaryContentTree);
aoqi@0 326 }
aoqi@0 327 }
aoqi@0 328 }

mercurial