001/* 002 * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package org.jdrupes.mdoclet.internal.doclets.toolkit.builders; 027 028import javax.lang.model.element.ModuleElement; 029 030import org.jdrupes.mdoclet.internal.doclets.toolkit.Content; 031import org.jdrupes.mdoclet.internal.doclets.toolkit.DocFilesHandler; 032import org.jdrupes.mdoclet.internal.doclets.toolkit.DocletException; 033import org.jdrupes.mdoclet.internal.doclets.toolkit.ModuleSummaryWriter; 034 035/** 036 * Builds the summary for a given module. 037 */ 038public class ModuleSummaryBuilder extends AbstractBuilder { 039 040 /** 041 * The module being documented. 042 */ 043 private final ModuleElement mdle; 044 045 /** 046 * The doclet specific writer that will output the result. 047 */ 048 private final ModuleSummaryWriter moduleWriter; 049 050 /** 051 * Construct a new ModuleSummaryBuilder. 052 * 053 * @param context the build context. 054 * @param mdle the module being documented. 055 * @param moduleWriter the doclet specific writer that will output the 056 * result. 057 */ 058 private ModuleSummaryBuilder(Context context, 059 ModuleElement mdle, ModuleSummaryWriter moduleWriter) { 060 super(context); 061 this.mdle = mdle; 062 this.moduleWriter = moduleWriter; 063 } 064 065 /** 066 * Construct a new ModuleSummaryBuilder. 067 * 068 * @param context the build context. 069 * @param mdle the module being documented. 070 * @param moduleWriter the doclet specific writer that will output the 071 * result. 072 * 073 * @return an instance of a ModuleSummaryBuilder. 074 */ 075 public static ModuleSummaryBuilder getInstance(Context context, 076 ModuleElement mdle, ModuleSummaryWriter moduleWriter) { 077 return new ModuleSummaryBuilder(context, mdle, moduleWriter); 078 } 079 080 /** 081 * Build the module summary. 082 * 083 * @throws DocletException if there is a problem while building the documentation 084 */ 085 @Override 086 public void build() throws DocletException { 087 if (moduleWriter == null) { 088 // Doclet does not support this output. 089 return; 090 } 091 buildModuleDoc(); 092 } 093 094 /** 095 * Build the module documentation. 096 * 097 * @throws DocletException if there is a problem while building the documentation 098 */ 099 protected void buildModuleDoc() throws DocletException { 100 Content content 101 = moduleWriter.getModuleHeader(mdle.getQualifiedName().toString()); 102 103 buildContent(); 104 105 moduleWriter.addModuleFooter(); 106 moduleWriter.printDocument(content); 107 DocFilesHandler docFilesHandler 108 = configuration.getWriterFactory().getDocFilesHandler(mdle); 109 docFilesHandler.copyDocFiles(); 110 } 111 112 /** 113 * Build the content for the module doc. 114 * 115 * @throws DocletException if there is a problem while building the documentation 116 */ 117 protected void buildContent() throws DocletException { 118 Content moduleContent = moduleWriter.getContentHeader(); 119 120 moduleWriter.addModuleSignature(moduleContent); 121 buildModuleDescription(moduleContent); 122 buildSummary(moduleContent); 123 124 moduleWriter.addModuleContent(moduleContent); 125 } 126 127 /** 128 * Builds the list of summary sections for this module. 129 * 130 * @param target the module content to which the summaries will 131 * be added 132 * @throws DocletException if there is a problem while building the documentation 133 */ 134 protected void buildSummary(Content target) throws DocletException { 135 Content summariesList = moduleWriter.getSummariesList(); 136 137 buildPackagesSummary(summariesList); 138 buildModulesSummary(summariesList); 139 buildServicesSummary(summariesList); 140 141 target.add(moduleWriter.getSummary(summariesList)); 142 } 143 144 /** 145 * Builds the summary of the module dependencies of this module. 146 * 147 * @param summariesList the list of summaries to which the summary will be added 148 */ 149 protected void buildModulesSummary(Content summariesList) { 150 moduleWriter.addModulesSummary(summariesList); 151 } 152 153 /** 154 * Builds the summary of the packages exported or opened by this module. 155 * 156 * @param summariesList the list of summaries to which the summary will be added 157 */ 158 protected void buildPackagesSummary(Content summariesList) { 159 moduleWriter.addPackagesSummary(summariesList); 160 } 161 162 /** 163 * Builds the summary of the services used or provided by this module. 164 * 165 * @param summariesList the list of summaries to which the summary will be added 166 */ 167 protected void buildServicesSummary(Content summariesList) { 168 moduleWriter.addServicesSummary(summariesList); 169 } 170 171 /** 172 * Builds the description for this module. 173 * 174 * @param moduleContent the content to which the module description will 175 * be added 176 */ 177 protected void buildModuleDescription(Content moduleContent) { 178 if (!options.noComment()) { 179 moduleWriter.addModuleDescription(moduleContent); 180 } 181 } 182}