Mon, 19 Nov 2012 16:10:34 -0800
8002304: Group methods by types in methods summary section
Reviewed-by: jjg
1 /*
2 * Copyright (c) 2003, 2012, 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 */
26 package com.sun.tools.doclets.internal.toolkit.builders;
28 import java.util.HashSet;
29 import java.util.Set;
31 import com.sun.javadoc.*;
32 import com.sun.tools.doclets.internal.toolkit.*;
33 import com.sun.tools.doclets.internal.toolkit.util.*;
35 /**
36 * The factory for constructing builders.
37 *
38 * <p><b>This is NOT part of any supported API.
39 * If you write code that depends on this, you do so at your own risk.
40 * This code and its internal interfaces are subject to change or
41 * deletion without notice.</b>
42 *
43 * @author Jamie Ho
44 * @since 1.4
45 */
47 public class BuilderFactory {
49 /**
50 * The current configuration of the doclet.
51 */
52 private final Configuration configuration;
54 /**
55 * The factory to retrieve the required writers from.
56 */
57 private final WriterFactory writerFactory;
59 private final AbstractBuilder.Context context;
61 /**
62 * Construct a builder factory using the given configuration.
63 * @param configuration the configuration for the current doclet
64 * being executed.
65 */
66 public BuilderFactory (Configuration configuration) {
67 this.configuration = configuration;
68 this.writerFactory = configuration.getWriterFactory();
70 Set<String> containingPackagesSeen = new HashSet<String>();
71 context = new AbstractBuilder.Context(configuration, containingPackagesSeen,
72 LayoutParser.getInstance(configuration));
73 }
75 /**
76 * Return the builder that builds the constant summary.
77 * @return the builder that builds the constant summary.
78 */
79 public AbstractBuilder getConstantsSummaryBuider() throws Exception {
80 return ConstantsSummaryBuilder.getInstance(context,
81 writerFactory.getConstantsSummaryWriter());
82 }
84 /**
85 * Return the builder that builds the package summary.
86 *
87 * @param pkg the package being documented.
88 * @param prevPkg the previous package being documented.
89 * @param nextPkg the next package being documented.
90 * @return the builder that builds the constant summary.
91 */
92 public AbstractBuilder getPackageSummaryBuilder(PackageDoc pkg, PackageDoc prevPkg,
93 PackageDoc nextPkg) throws Exception {
94 return PackageSummaryBuilder.getInstance(context, pkg,
95 writerFactory.getPackageSummaryWriter(pkg, prevPkg, nextPkg));
96 }
98 /**
99 * Return the builder for the class.
100 *
101 * @param classDoc the class being documented.
102 * @param prevClass the previous class that was documented.
103 * @param nextClass the next class being documented.
104 * @param classTree the class tree.
105 * @return the writer for the class. Return null if this
106 * writer is not supported by the doclet.
107 */
108 public AbstractBuilder getClassBuilder(ClassDoc classDoc,
109 ClassDoc prevClass, ClassDoc nextClass, ClassTree classTree)
110 throws Exception {
111 return ClassBuilder.getInstance(context, classDoc,
112 writerFactory.getClassWriter(classDoc, prevClass, nextClass,
113 classTree));
114 }
116 /**
117 * Return the builder for the annotation type.
118 *
119 * @param annotationType the annotation type being documented.
120 * @param prevType the previous type that was documented.
121 * @param nextType the next type being documented.
122 * @return the writer for the annotation type. Return null if this
123 * writer is not supported by the doclet.
124 */
125 public AbstractBuilder getAnnotationTypeBuilder(
126 AnnotationTypeDoc annotationType,
127 Type prevType, Type nextType)
128 throws Exception {
129 return AnnotationTypeBuilder.getInstance(context, annotationType,
130 writerFactory.getAnnotationTypeWriter(annotationType, prevType, nextType));
131 }
133 /**
134 * Return an instance of the method builder for the given class.
135 *
136 * @return an instance of the method builder for the given class.
137 */
138 public AbstractBuilder getMethodBuilder(ClassWriter classWriter)
139 throws Exception {
140 return MethodBuilder.getInstance(context,
141 classWriter.getClassDoc(),
142 writerFactory.getMethodWriter(classWriter));
143 }
145 /**
146 * Return an instance of the annotation type member builder for the given
147 * class.
148 *
149 * @return an instance of the annotation type memebr builder for the given
150 * annotation type.
151 */
152 public AbstractBuilder getAnnotationTypeOptionalMemberBuilder(
153 AnnotationTypeWriter annotationTypeWriter)
154 throws Exception {
155 return AnnotationTypeOptionalMemberBuilder.getInstance(context,
156 annotationTypeWriter.getAnnotationTypeDoc(),
157 writerFactory.getAnnotationTypeOptionalMemberWriter(
158 annotationTypeWriter));
159 }
161 /**
162 * Return an instance of the annotation type member builder for the given
163 * class.
164 *
165 * @return an instance of the annotation type memebr builder for the given
166 * annotation type.
167 */
168 public AbstractBuilder getAnnotationTypeRequiredMemberBuilder(
169 AnnotationTypeWriter annotationTypeWriter)
170 throws Exception {
171 return AnnotationTypeRequiredMemberBuilder.getInstance(context,
172 annotationTypeWriter.getAnnotationTypeDoc(),
173 writerFactory.getAnnotationTypeRequiredMemberWriter(
174 annotationTypeWriter));
175 }
177 /**
178 * Return an instance of the enum constants builder for the given class.
179 *
180 * @return an instance of the enum constants builder for the given class.
181 */
182 public AbstractBuilder getEnumConstantsBuilder(ClassWriter classWriter)
183 throws Exception {
184 return EnumConstantBuilder.getInstance(context, classWriter.getClassDoc(),
185 writerFactory.getEnumConstantWriter(classWriter));
186 }
188 /**
189 * Return an instance of the field builder for the given class.
190 *
191 * @return an instance of the field builder for the given class.
192 */
193 public AbstractBuilder getFieldBuilder(ClassWriter classWriter)
194 throws Exception {
195 return FieldBuilder.getInstance(context, classWriter.getClassDoc(),
196 writerFactory.getFieldWriter(classWriter));
197 }
199 /**
200 * Return an instance of the constructor builder for the given class.
201 *
202 * @return an instance of the constructor builder for the given class.
203 */
204 public AbstractBuilder getConstructorBuilder(ClassWriter classWriter)
205 throws Exception {
206 return ConstructorBuilder.getInstance(context,
207 classWriter.getClassDoc(),
208 writerFactory.getConstructorWriter(classWriter));
209 }
211 /**
212 * Return an instance of the member summary builder for the given class.
213 *
214 * @return an instance of the member summary builder for the given class.
215 */
216 public AbstractBuilder getMemberSummaryBuilder(ClassWriter classWriter)
217 throws Exception {
218 return MemberSummaryBuilder.getInstance(classWriter, context);
219 }
221 /**
222 * Return an instance of the member summary builder for the given annotation
223 * type.
224 *
225 * @return an instance of the member summary builder for the given
226 * annotation type.
227 */
228 public AbstractBuilder getMemberSummaryBuilder(
229 AnnotationTypeWriter annotationTypeWriter)
230 throws Exception {
231 return MemberSummaryBuilder.getInstance(annotationTypeWriter, context);
232 }
234 /**
235 * Return the builder that builds the serialized form.
236 *
237 * @return the builder that builds the serialized form.
238 */
239 public AbstractBuilder getSerializedFormBuilder()
240 throws Exception {
241 return SerializedFormBuilder.getInstance(context);
242 }
243 }