1 /*
   2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package jdk.javadoc.internal.doclets.toolkit.builders;
  27 
  28 import java.util.*;
  29 
  30 import javax.lang.model.element.PackageElement;
  31 
  32 import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
  33 import jdk.javadoc.internal.doclets.toolkit.DocletException;
  34 import jdk.javadoc.internal.doclets.toolkit.Messages;
  35 import jdk.javadoc.internal.doclets.toolkit.Resources;
  36 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
  37 
  38 
  39 /**
  40  * The superclass for all builders.  A builder is a class that provides
  41  * the structure and content of API documentation.  A builder is completely
  42  * doclet independent which means that any doclet can use builders to
  43  * construct documentation, as long as it implements the appropriate
  44  * writer interfaces.  For example, if a doclet wanted to use
  45  * {@link ConstantsSummaryBuilder} to build a constant summary, all it has to
  46  * do is implement the ConstantsSummaryWriter interface and pass it to the
  47  * builder using a WriterFactory.
  48  *
  49  *  <p><b>This is NOT part of any supported API.
  50  *  If you write code that depends on this, you do so at your own risk.
  51  *  This code and its internal interfaces are subject to change or
  52  *  deletion without notice.</b>
  53  */
  54 
  55 public abstract class AbstractBuilder {
  56     public static class Context {
  57         /**
  58          * The configuration used in this run of the doclet.
  59          */
  60         final BaseConfiguration configuration;
  61 
  62         /**
  63          * Keep track of which packages we have seen for
  64          * efficiency purposes.  We don't want to copy the
  65          * doc files multiple times for a single package.
  66          */
  67         final Set<PackageElement> containingPackagesSeen;
  68 
  69         Context(BaseConfiguration configuration, Set<PackageElement> containingPackagesSeen) {
  70             this.configuration = configuration;
  71             this.containingPackagesSeen = containingPackagesSeen;
  72         }
  73     }
  74 
  75     /**
  76      * The configuration used in this run of the doclet.
  77      */
  78     protected final BaseConfiguration configuration;
  79 
  80     protected final BuilderFactory builderFactory;
  81     protected final Messages messages;
  82     protected final Resources resources;
  83     protected final Utils utils;
  84 
  85     /**
  86      * Keep track of which packages we have seen for
  87      * efficiency purposes.  We don't want to copy the
  88      * doc files multiple times for a single package.
  89      */
  90     protected final Set<PackageElement> containingPackagesSeen;
  91 
  92     /**
  93      * Construct a Builder.
  94      * @param c a context providing information used in this run of the doclet
  95      */
  96     public AbstractBuilder(Context c) {
  97         this.configuration = c.configuration;
  98         this.builderFactory = configuration.getBuilderFactory();
  99         this.messages = configuration.getMessages();
 100         this.resources = configuration.getResources();
 101         this.utils = configuration.utils;
 102         this.containingPackagesSeen = c.containingPackagesSeen;
 103     }
 104 
 105     /**
 106      * Build the documentation.
 107      *
 108      * @throws DocletException if there is a problem building the documentation
 109      */
 110     public abstract void build() throws DocletException;
 111 }