1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/ProfileSummaryBuilder.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,328 @@ 1.4 +/* 1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.tools.doclets.internal.toolkit.builders; 1.30 + 1.31 +import java.io.*; 1.32 + 1.33 +import com.sun.javadoc.*; 1.34 +import com.sun.tools.javac.jvm.Profile; 1.35 +import com.sun.tools.doclets.internal.toolkit.*; 1.36 +import com.sun.tools.doclets.internal.toolkit.util.*; 1.37 + 1.38 +/** 1.39 + * Builds the summary for a given profile. 1.40 + * 1.41 + * <p><b>This is NOT part of any supported API. 1.42 + * If you write code that depends on this, you do so at your own risk. 1.43 + * This code and its internal interfaces are subject to change or 1.44 + * deletion without notice.</b> 1.45 + * 1.46 + * @author Bhavesh Patel 1.47 + */ 1.48 +public class ProfileSummaryBuilder extends AbstractBuilder { 1.49 + /** 1.50 + * The root element of the profile summary XML is {@value}. 1.51 + */ 1.52 + public static final String ROOT = "ProfileDoc"; 1.53 + 1.54 + /** 1.55 + * The profile being documented. 1.56 + */ 1.57 + private final Profile profile; 1.58 + 1.59 + /** 1.60 + * The doclet specific writer that will output the result. 1.61 + */ 1.62 + private final ProfileSummaryWriter profileWriter; 1.63 + 1.64 + /** 1.65 + * The content that will be added to the profile summary documentation tree. 1.66 + */ 1.67 + private Content contentTree; 1.68 + 1.69 + /** 1.70 + * The profile package being documented. 1.71 + */ 1.72 + private PackageDoc pkg; 1.73 + 1.74 + /** 1.75 + * Construct a new ProfileSummaryBuilder. 1.76 + * 1.77 + * @param context the build context. 1.78 + * @param profile the profile being documented. 1.79 + * @param profileWriter the doclet specific writer that will output the 1.80 + * result. 1.81 + */ 1.82 + private ProfileSummaryBuilder(Context context, 1.83 + Profile profile, ProfileSummaryWriter profileWriter) { 1.84 + super(context); 1.85 + this.profile = profile; 1.86 + this.profileWriter = profileWriter; 1.87 + } 1.88 + 1.89 + /** 1.90 + * Construct a new ProfileSummaryBuilder. 1.91 + * 1.92 + * @param context the build context. 1.93 + * @param profile the profile being documented. 1.94 + * @param profileWriter the doclet specific writer that will output the 1.95 + * result. 1.96 + * 1.97 + * @return an instance of a ProfileSummaryBuilder. 1.98 + */ 1.99 + public static ProfileSummaryBuilder getInstance(Context context, 1.100 + Profile profile, ProfileSummaryWriter profileWriter) { 1.101 + return new ProfileSummaryBuilder(context, profile, profileWriter); 1.102 + } 1.103 + 1.104 + /** 1.105 + * Build the profile summary. 1.106 + */ 1.107 + public void build() throws IOException { 1.108 + if (profileWriter == null) { 1.109 + //Doclet does not support this output. 1.110 + return; 1.111 + } 1.112 + build(layoutParser.parseXML(ROOT), contentTree); 1.113 + } 1.114 + 1.115 + /** 1.116 + * {@inheritDoc} 1.117 + */ 1.118 + public String getName() { 1.119 + return ROOT; 1.120 + } 1.121 + 1.122 + /** 1.123 + * Build the profile documentation. 1.124 + * 1.125 + * @param node the XML element that specifies which components to document 1.126 + * @param contentTree the content tree to which the documentation will be added 1.127 + */ 1.128 + public void buildProfileDoc(XMLNode node, Content contentTree) throws Exception { 1.129 + contentTree = profileWriter.getProfileHeader(profile.name); 1.130 + buildChildren(node, contentTree); 1.131 + profileWriter.addProfileFooter(contentTree); 1.132 + profileWriter.printDocument(contentTree); 1.133 + profileWriter.close(); 1.134 + Util.copyDocFiles(configuration, DocPaths.profileSummary(profile.name)); 1.135 + } 1.136 + 1.137 + /** 1.138 + * Build the content for the profile doc. 1.139 + * 1.140 + * @param node the XML element that specifies which components to document 1.141 + * @param contentTree the content tree to which the profile contents 1.142 + * will be added 1.143 + */ 1.144 + public void buildContent(XMLNode node, Content contentTree) { 1.145 + Content profileContentTree = profileWriter.getContentHeader(); 1.146 + buildChildren(node, profileContentTree); 1.147 + contentTree.addContent(profileContentTree); 1.148 + } 1.149 + 1.150 + /** 1.151 + * Build the profile summary. 1.152 + * 1.153 + * @param node the XML element that specifies which components to document 1.154 + * @param profileContentTree the profile content tree to which the summaries will 1.155 + * be added 1.156 + */ 1.157 + public void buildSummary(XMLNode node, Content profileContentTree) { 1.158 + Content summaryContentTree = profileWriter.getSummaryHeader(); 1.159 + buildChildren(node, summaryContentTree); 1.160 + profileContentTree.addContent(profileWriter.getSummaryTree(summaryContentTree)); 1.161 + } 1.162 + 1.163 + /** 1.164 + * Build the profile package summary. 1.165 + * 1.166 + * @param node the XML element that specifies which components to document 1.167 + * @param summaryContentTree the content tree to which the summaries will 1.168 + * be added 1.169 + */ 1.170 + public void buildPackageSummary(XMLNode node, Content summaryContentTree) { 1.171 + PackageDoc[] packages = configuration.profilePackages.get(profile.name); 1.172 + for (int i = 0; i < packages.length; i++) { 1.173 + this.pkg = packages[i]; 1.174 + Content packageSummaryContentTree = profileWriter.getPackageSummaryHeader(this.pkg); 1.175 + buildChildren(node, packageSummaryContentTree); 1.176 + summaryContentTree.addContent(profileWriter.getPackageSummaryTree( 1.177 + packageSummaryContentTree)); 1.178 + } 1.179 + } 1.180 + 1.181 + /** 1.182 + * Build the summary for the interfaces in the package. 1.183 + * 1.184 + * @param node the XML element that specifies which components to document 1.185 + * @param packageSummaryContentTree the tree to which the interface summary 1.186 + * will be added 1.187 + */ 1.188 + public void buildInterfaceSummary(XMLNode node, Content packageSummaryContentTree) { 1.189 + String interfaceTableSummary = 1.190 + configuration.getText("doclet.Member_Table_Summary", 1.191 + configuration.getText("doclet.Interface_Summary"), 1.192 + configuration.getText("doclet.interfaces")); 1.193 + String[] interfaceTableHeader = new String[] { 1.194 + configuration.getText("doclet.Interface"), 1.195 + configuration.getText("doclet.Description") 1.196 + }; 1.197 + ClassDoc[] interfaces = pkg.interfaces(); 1.198 + if (interfaces.length > 0) { 1.199 + profileWriter.addClassesSummary( 1.200 + interfaces, 1.201 + configuration.getText("doclet.Interface_Summary"), 1.202 + interfaceTableSummary, interfaceTableHeader, packageSummaryContentTree); 1.203 + } 1.204 + } 1.205 + 1.206 + /** 1.207 + * Build the summary for the classes in the package. 1.208 + * 1.209 + * @param node the XML element that specifies which components to document 1.210 + * @param packageSummaryContentTree the tree to which the class summary will 1.211 + * be added 1.212 + */ 1.213 + public void buildClassSummary(XMLNode node, Content packageSummaryContentTree) { 1.214 + String classTableSummary = 1.215 + configuration.getText("doclet.Member_Table_Summary", 1.216 + configuration.getText("doclet.Class_Summary"), 1.217 + configuration.getText("doclet.classes")); 1.218 + String[] classTableHeader = new String[] { 1.219 + configuration.getText("doclet.Class"), 1.220 + configuration.getText("doclet.Description") 1.221 + }; 1.222 + ClassDoc[] classes = pkg.ordinaryClasses(); 1.223 + if (classes.length > 0) { 1.224 + profileWriter.addClassesSummary( 1.225 + classes, 1.226 + configuration.getText("doclet.Class_Summary"), 1.227 + classTableSummary, classTableHeader, packageSummaryContentTree); 1.228 + } 1.229 + } 1.230 + 1.231 + /** 1.232 + * Build the summary for the enums in the package. 1.233 + * 1.234 + * @param node the XML element that specifies which components to document 1.235 + * @param packageSummaryContentTree the tree to which the enum summary will 1.236 + * be added 1.237 + */ 1.238 + public void buildEnumSummary(XMLNode node, Content packageSummaryContentTree) { 1.239 + String enumTableSummary = 1.240 + configuration.getText("doclet.Member_Table_Summary", 1.241 + configuration.getText("doclet.Enum_Summary"), 1.242 + configuration.getText("doclet.enums")); 1.243 + String[] enumTableHeader = new String[] { 1.244 + configuration.getText("doclet.Enum"), 1.245 + configuration.getText("doclet.Description") 1.246 + }; 1.247 + ClassDoc[] enums = pkg.enums(); 1.248 + if (enums.length > 0) { 1.249 + profileWriter.addClassesSummary( 1.250 + enums, 1.251 + configuration.getText("doclet.Enum_Summary"), 1.252 + enumTableSummary, enumTableHeader, packageSummaryContentTree); 1.253 + } 1.254 + } 1.255 + 1.256 + /** 1.257 + * Build the summary for the exceptions in the package. 1.258 + * 1.259 + * @param node the XML element that specifies which components to document 1.260 + * @param packageSummaryContentTree the tree to which the exception summary will 1.261 + * be added 1.262 + */ 1.263 + public void buildExceptionSummary(XMLNode node, Content packageSummaryContentTree) { 1.264 + String exceptionTableSummary = 1.265 + configuration.getText("doclet.Member_Table_Summary", 1.266 + configuration.getText("doclet.Exception_Summary"), 1.267 + configuration.getText("doclet.exceptions")); 1.268 + String[] exceptionTableHeader = new String[] { 1.269 + configuration.getText("doclet.Exception"), 1.270 + configuration.getText("doclet.Description") 1.271 + }; 1.272 + ClassDoc[] exceptions = pkg.exceptions(); 1.273 + if (exceptions.length > 0) { 1.274 + profileWriter.addClassesSummary( 1.275 + exceptions, 1.276 + configuration.getText("doclet.Exception_Summary"), 1.277 + exceptionTableSummary, exceptionTableHeader, packageSummaryContentTree); 1.278 + } 1.279 + } 1.280 + 1.281 + /** 1.282 + * Build the summary for the errors in the package. 1.283 + * 1.284 + * @param node the XML element that specifies which components to document 1.285 + * @param packageSummaryContentTree the tree to which the error summary will 1.286 + * be added 1.287 + */ 1.288 + public void buildErrorSummary(XMLNode node, Content packageSummaryContentTree) { 1.289 + String errorTableSummary = 1.290 + configuration.getText("doclet.Member_Table_Summary", 1.291 + configuration.getText("doclet.Error_Summary"), 1.292 + configuration.getText("doclet.errors")); 1.293 + String[] errorTableHeader = new String[] { 1.294 + configuration.getText("doclet.Error"), 1.295 + configuration.getText("doclet.Description") 1.296 + }; 1.297 + ClassDoc[] errors = pkg.errors(); 1.298 + if (errors.length > 0) { 1.299 + profileWriter.addClassesSummary( 1.300 + errors, 1.301 + configuration.getText("doclet.Error_Summary"), 1.302 + errorTableSummary, errorTableHeader, packageSummaryContentTree); 1.303 + } 1.304 + } 1.305 + 1.306 + /** 1.307 + * Build the summary for the annotation type in the package. 1.308 + * 1.309 + * @param node the XML element that specifies which components to document 1.310 + * @param packageSummaryContentTree the tree to which the annotation type 1.311 + * summary will be added 1.312 + */ 1.313 + public void buildAnnotationTypeSummary(XMLNode node, Content packageSummaryContentTree) { 1.314 + String annotationtypeTableSummary = 1.315 + configuration.getText("doclet.Member_Table_Summary", 1.316 + configuration.getText("doclet.Annotation_Types_Summary"), 1.317 + configuration.getText("doclet.annotationtypes")); 1.318 + String[] annotationtypeTableHeader = new String[] { 1.319 + configuration.getText("doclet.AnnotationType"), 1.320 + configuration.getText("doclet.Description") 1.321 + }; 1.322 + ClassDoc[] annotationTypes = pkg.annotationTypes(); 1.323 + if (annotationTypes.length > 0) { 1.324 + profileWriter.addClassesSummary( 1.325 + annotationTypes, 1.326 + configuration.getText("doclet.Annotation_Types_Summary"), 1.327 + annotationtypeTableSummary, annotationtypeTableHeader, 1.328 + packageSummaryContentTree); 1.329 + } 1.330 + } 1.331 +}