001/* 002 * Copyright (c) 2003, 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 java.util.*; 029 030import javax.lang.model.element.PackageElement; 031 032import org.jdrupes.mdoclet.internal.doclets.toolkit.BaseConfiguration; 033import org.jdrupes.mdoclet.internal.doclets.toolkit.BaseOptions; 034import org.jdrupes.mdoclet.internal.doclets.toolkit.DocletException; 035import org.jdrupes.mdoclet.internal.doclets.toolkit.Messages; 036import org.jdrupes.mdoclet.internal.doclets.toolkit.Resources; 037import org.jdrupes.mdoclet.internal.doclets.toolkit.util.Utils; 038 039/** 040 * The superclass for all builders. A builder is a class that provides 041 * the structure and content of API documentation. A builder is completely 042 * doclet independent which means that any doclet can use builders to 043 * construct documentation, as long as it implements the appropriate 044 * writer interfaces. For example, if a doclet wanted to use 045 * {@link ConstantsSummaryBuilder} to build a constant summary, all it has to 046 * do is implement the ConstantsSummaryWriter interface and pass it to the 047 * builder using a WriterFactory. 048 */ 049public abstract class AbstractBuilder { 050 public static class Context { 051 /** 052 * The configuration used in this run of the doclet. 053 */ 054 final BaseConfiguration configuration; 055 056 /** 057 * Keep track of which packages we have seen for 058 * efficiency purposes. We don't want to copy the 059 * doc files multiple times for a single package. 060 */ 061 final Set<PackageElement> containingPackagesSeen; 062 063 Context(BaseConfiguration configuration, 064 Set<PackageElement> containingPackagesSeen) { 065 this.configuration = configuration; 066 this.containingPackagesSeen = containingPackagesSeen; 067 } 068 } 069 070 /** 071 * The configuration used in this run of the doclet. 072 */ 073 protected final BaseConfiguration configuration; 074 protected final BaseOptions options; 075 076 protected final BuilderFactory builderFactory; 077 protected final Messages messages; 078 protected final Resources resources; 079 protected final Utils utils; 080 081 /** 082 * Keep track of which packages we have seen for 083 * efficiency purposes. We don't want to copy the 084 * doc files multiple times for a single package. 085 */ 086 protected final Set<PackageElement> containingPackagesSeen; 087 088 /** 089 * Construct a Builder. 090 * @param c a context providing information used in this run of the doclet 091 */ 092 public AbstractBuilder(Context c) { 093 this.configuration = c.configuration; 094 this.options = configuration.getOptions(); 095 this.builderFactory = configuration.getBuilderFactory(); 096 this.messages = configuration.getMessages(); 097 this.resources = configuration.getDocResources(); 098 this.utils = configuration.utils; 099 this.containingPackagesSeen = c.containingPackagesSeen; 100 } 101 102 /** 103 * Build the documentation. 104 * 105 * @throws DocletException if there is a problem building the documentation 106 */ 107 public abstract void build() throws DocletException; 108}