BuilderFactory.java revision 3606:4b17f176d19c
1239922Sgonzo/*
2239922Sgonzo * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3239922Sgonzo * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4239922Sgonzo *
5239922Sgonzo * This code is free software; you can redistribute it and/or modify it
6239922Sgonzo * under the terms of the GNU General Public License version 2 only, as
7239922Sgonzo * published by the Free Software Foundation.  Oracle designates this
8239922Sgonzo * particular file as subject to the "Classpath" exception as provided
9239922Sgonzo * by Oracle in the LICENSE file that accompanied this code.
10239922Sgonzo *
11239922Sgonzo * This code is distributed in the hope that it will be useful, but WITHOUT
12239922Sgonzo * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13239922Sgonzo * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14239922Sgonzo * version 2 for more details (a copy is included in the LICENSE file that
15239922Sgonzo * accompanied this code).
16239922Sgonzo *
17239922Sgonzo * You should have received a copy of the GNU General Public License version
18239922Sgonzo * 2 along with this work; if not, write to the Free Software Foundation,
19239922Sgonzo * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20239922Sgonzo *
21239922Sgonzo * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22239922Sgonzo * or visit www.oracle.com if you need additional information or have any
23239922Sgonzo * questions.
24239922Sgonzo */
25239922Sgonzo
26239922Sgonzopackage jdk.javadoc.internal.doclets.toolkit.builders;
27239922Sgonzo
28239922Sgonzoimport java.util.HashSet;
29239922Sgonzoimport java.util.Set;
30239922Sgonzo
31239922Sgonzoimport javax.lang.model.element.ModuleElement;
32239922Sgonzoimport javax.lang.model.element.PackageElement;
33239922Sgonzoimport javax.lang.model.element.TypeElement;
34239922Sgonzoimport javax.lang.model.type.TypeMirror;
35239922Sgonzo
36239922Sgonzoimport jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
37239922Sgonzoimport jdk.javadoc.internal.doclets.toolkit.ClassWriter;
38239922Sgonzoimport jdk.javadoc.internal.doclets.toolkit.Configuration;
39239922Sgonzoimport jdk.javadoc.internal.doclets.toolkit.PropertyWriter;
40239922Sgonzoimport jdk.javadoc.internal.doclets.toolkit.WriterFactory;
41239922Sgonzoimport jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
42239922Sgonzo
43239922Sgonzo/**
44239922Sgonzo * The factory for constructing builders.
45239922Sgonzo *
46239922Sgonzo *  <p><b>This is NOT part of any supported API.
47239922Sgonzo *  If you write code that depends on this, you do so at your own risk.
48239922Sgonzo *  This code and its internal interfaces are subject to change or
49239922Sgonzo *  deletion without notice.</b>
50239922Sgonzo *
51239922Sgonzo * @author Jamie Ho
52239922Sgonzo */
53239922Sgonzo
54239922Sgonzopublic class BuilderFactory {
55239922Sgonzo
56239922Sgonzo    /**
57239922Sgonzo     * The current configuration of the doclet.
58239922Sgonzo     */
59239922Sgonzo    private final Configuration configuration;
60239922Sgonzo
61239922Sgonzo    /**
62239922Sgonzo     * The factory to retrieve the required writers from.
63239922Sgonzo     */
64239922Sgonzo    private final WriterFactory writerFactory;
65239922Sgonzo
66239922Sgonzo    private final AbstractBuilder.Context context;
67239922Sgonzo
68239922Sgonzo    /**
69239922Sgonzo     * Construct a builder factory using the given configuration.
70239922Sgonzo     * @param configuration the configuration for the current doclet
71239922Sgonzo     * being executed.
72239922Sgonzo     */
73239922Sgonzo    public BuilderFactory (Configuration configuration) {
74239922Sgonzo        this.configuration = configuration;
75239922Sgonzo        this.writerFactory = configuration.getWriterFactory();
76239922Sgonzo
77239922Sgonzo        Set<PackageElement> containingPackagesSeen = new HashSet<>();
78239922Sgonzo        context = new AbstractBuilder.Context(configuration, containingPackagesSeen,
79239922Sgonzo                LayoutParser.getInstance(configuration));
80239922Sgonzo    }
81239922Sgonzo
82239922Sgonzo    /**
83239922Sgonzo     * Return the builder that builds the constant summary.
84239922Sgonzo     * @return the builder that builds the constant summary.
85239922Sgonzo     */
86239922Sgonzo    public AbstractBuilder getConstantsSummaryBuilder() {
87239922Sgonzo        return ConstantsSummaryBuilder.getInstance(context,
88239922Sgonzo            writerFactory.getConstantsSummaryWriter());
89239922Sgonzo    }
90239922Sgonzo
91239922Sgonzo    /**
92239922Sgonzo     * Return the builder that builds the package summary.
93266152Sian     *
94266152Sian     * @param pkg the package being documented.
95266152Sian     * @param prevPkg the previous package being documented.
96266152Sian     * @param nextPkg the next package being documented.
97239922Sgonzo     * @return the builder that builds the constant summary.
98239922Sgonzo     */
99239922Sgonzo    public AbstractBuilder getPackageSummaryBuilder(PackageElement pkg, PackageElement prevPkg,
100239922Sgonzo            PackageElement nextPkg) {
101239922Sgonzo        return PackageSummaryBuilder.getInstance(context, pkg,
102239922Sgonzo            writerFactory.getPackageSummaryWriter(pkg, prevPkg, nextPkg));
103239922Sgonzo    }
104239922Sgonzo
105239922Sgonzo    /**
106239922Sgonzo     * Return the builder that builds the module summary.
107239922Sgonzo     *
108239922Sgonzo     * @param mdle the module being documented.
109239922Sgonzo     * @param prevModule the previous module being documented.
110239922Sgonzo     * @param nextModule the next module being documented.
111239922Sgonzo     * @return the builder that builds the module summary.
112239922Sgonzo     */
113239922Sgonzo    public AbstractBuilder getModuleSummaryBuilder(ModuleElement mdle, ModuleElement prevModule,
114239922Sgonzo            ModuleElement nextModule) {
115239922Sgonzo        return ModuleSummaryBuilder.getInstance(context, mdle,
116239922Sgonzo            writerFactory.getModuleSummaryWriter(mdle, prevModule, nextModule));
117239922Sgonzo    }
118239922Sgonzo
119239922Sgonzo    /**
120239922Sgonzo     * Return the builder for the class.
121239922Sgonzo     *
122239922Sgonzo     * @param typeElement the class being documented.
123239922Sgonzo     * @param prevClass the previous class that was documented.
124239922Sgonzo     * @param nextClass the next class being documented.
125239922Sgonzo     * @param classTree the class tree.
126239922Sgonzo     * @return the writer for the class.  Return null if this
127239922Sgonzo     * writer is not supported by the doclet.
128239922Sgonzo     */
129239922Sgonzo    public AbstractBuilder getClassBuilder(TypeElement typeElement,
130239922Sgonzo            TypeElement prevClass, TypeElement nextClass, ClassTree classTree) {
131239922Sgonzo        return ClassBuilder.getInstance(context, typeElement,
132239922Sgonzo            writerFactory.getClassWriter(typeElement, prevClass, nextClass, classTree));
133239922Sgonzo    }
134239922Sgonzo
135239922Sgonzo    /**
136239922Sgonzo     * Return the builder for the annotation type.
137239922Sgonzo     *
138239922Sgonzo     * @param annotationType the annotation type being documented.
139239922Sgonzo     * @param prevType the previous type that was documented.
140239922Sgonzo     * @param nextType the next type being documented.
141239922Sgonzo     * @return the writer for the annotation type.  Return null if this
142239922Sgonzo     * writer is not supported by the doclet.
143239922Sgonzo     */
144239922Sgonzo    public AbstractBuilder getAnnotationTypeBuilder(
145239922Sgonzo        TypeElement annotationType, TypeMirror prevType, TypeMirror nextType) {
146239922Sgonzo        return AnnotationTypeBuilder.getInstance(context, annotationType,
147239922Sgonzo            writerFactory.getAnnotationTypeWriter(annotationType, prevType, nextType));
148239922Sgonzo    }
149239922Sgonzo
150239922Sgonzo    /**
151239922Sgonzo     * Return an instance of the method builder for the given class.
152239922Sgonzo     *
153239922Sgonzo     * @return an instance of the method builder for the given class.
154239922Sgonzo     */
155239922Sgonzo    public AbstractBuilder getMethodBuilder(ClassWriter classWriter) {
156239922Sgonzo        return MethodBuilder.getInstance(context, classWriter.getTypeElement(),
157239922Sgonzo            writerFactory.getMethodWriter(classWriter));
158239922Sgonzo    }
159239922Sgonzo
160239922Sgonzo    /**
161239922Sgonzo     * Return an instance of the annotation type fields builder for the given
162239922Sgonzo     * class.
163239922Sgonzo     *
164239922Sgonzo     * @return an instance of the annotation type field builder for the given
165239922Sgonzo     *         annotation type.
166239922Sgonzo     */
167239922Sgonzo    public AbstractBuilder getAnnotationTypeFieldsBuilder(
168239922Sgonzo            AnnotationTypeWriter annotationTypeWriter) {
169239922Sgonzo        return AnnotationTypeFieldBuilder.getInstance(context,
170239922Sgonzo                annotationTypeWriter.getAnnotationTypeElement(),
171239922Sgonzo                writerFactory.getAnnotationTypeFieldWriter(annotationTypeWriter));
172239922Sgonzo    }
173239922Sgonzo
174239922Sgonzo    /**
175239922Sgonzo     * Return an instance of the annotation type member builder for the given
176239922Sgonzo     * class.
177239922Sgonzo     *
178239922Sgonzo     * @return an instance of the annotation type member builder for the given
179239922Sgonzo     *         annotation type.
180239922Sgonzo     */
181239922Sgonzo    public AbstractBuilder getAnnotationTypeOptionalMemberBuilder(
182239922Sgonzo            AnnotationTypeWriter annotationTypeWriter) {
183239922Sgonzo        return AnnotationTypeOptionalMemberBuilder.getInstance(context,
184239922Sgonzo            annotationTypeWriter.getAnnotationTypeElement(),
185239922Sgonzo            writerFactory.getAnnotationTypeOptionalMemberWriter(annotationTypeWriter));
186239922Sgonzo    }
187239922Sgonzo
188239922Sgonzo    /**
189239922Sgonzo     * Return an instance of the annotation type member builder for the given
190239922Sgonzo     * class.
191239922Sgonzo     *
192239922Sgonzo     * @return an instance of the annotation type member builder for the given
193239922Sgonzo     *         annotation type.
194239922Sgonzo     */
195239922Sgonzo    public AbstractBuilder getAnnotationTypeRequiredMemberBuilder(
196239922Sgonzo            AnnotationTypeWriter annotationTypeWriter) {
197239922Sgonzo        return AnnotationTypeRequiredMemberBuilder.getInstance(context,
198239922Sgonzo            annotationTypeWriter.getAnnotationTypeElement(),
199239922Sgonzo            writerFactory.getAnnotationTypeRequiredMemberWriter(annotationTypeWriter));
200239922Sgonzo    }
201239922Sgonzo
202239922Sgonzo    /**
203239922Sgonzo     * Return an instance of the enum constants builder for the given class.
204239922Sgonzo     *
205239922Sgonzo     * @return an instance of the enum constants builder for the given class.
206239922Sgonzo     */
207239922Sgonzo    public AbstractBuilder getEnumConstantsBuilder(ClassWriter classWriter) {
208        return EnumConstantBuilder.getInstance(context, classWriter.getTypeElement(),
209                writerFactory.getEnumConstantWriter(classWriter));
210    }
211
212    /**
213     * Return an instance of the field builder for the given class.
214     *
215     * @return an instance of the field builder for the given class.
216     */
217    public AbstractBuilder getFieldBuilder(ClassWriter classWriter) {
218        return FieldBuilder.getInstance(context, classWriter.getTypeElement(),
219            writerFactory.getFieldWriter(classWriter));
220    }
221
222    /**
223     * Return an instance of the property builder for the given class.
224     *
225     * @return an instance of the field builder for the given class.
226     */
227    public AbstractBuilder getPropertyBuilder(ClassWriter classWriter) {
228        final PropertyWriter propertyWriter =
229                writerFactory.getPropertyWriter(classWriter);
230        return PropertyBuilder.getInstance(context,
231                                           classWriter.getTypeElement(),
232                                           propertyWriter);
233    }
234
235    /**
236     * Return an instance of the constructor builder for the given class.
237     *
238     * @return an instance of the constructor builder for the given class.
239     */
240    public AbstractBuilder getConstructorBuilder(ClassWriter classWriter) {
241        return ConstructorBuilder.getInstance(context, classWriter.getTypeElement(),
242            writerFactory.getConstructorWriter(classWriter));
243    }
244
245    /**
246     * Return an instance of the member summary builder for the given class.
247     *
248     * @return an instance of the member summary builder for the given class.
249     */
250    public AbstractBuilder getMemberSummaryBuilder(ClassWriter classWriter) {
251        return MemberSummaryBuilder.getInstance(classWriter, context);
252    }
253
254    /**
255     * Return an instance of the member summary builder for the given annotation
256     * type.
257     *
258     * @return an instance of the member summary builder for the given
259     *         annotation type.
260     */
261    public AbstractBuilder getMemberSummaryBuilder(AnnotationTypeWriter annotationTypeWriter) {
262        return MemberSummaryBuilder.getInstance(annotationTypeWriter, context);
263    }
264
265    /**
266     * Return the builder that builds the serialized form.
267     *
268     * @return the builder that builds the serialized form.
269     */
270    public AbstractBuilder getSerializedFormBuilder() {
271        return SerializedFormBuilder.getInstance(context);
272    }
273}
274