WriterFactoryImpl.java revision 3294:9adfb22ff08f
1221828Sgrehan/*
2221828Sgrehan * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3221828Sgrehan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4221828Sgrehan *
5221828Sgrehan * This code is free software; you can redistribute it and/or modify it
6221828Sgrehan * under the terms of the GNU General Public License version 2 only, as
7221828Sgrehan * published by the Free Software Foundation.  Oracle designates this
8221828Sgrehan * particular file as subject to the "Classpath" exception as provided
9221828Sgrehan * by Oracle in the LICENSE file that accompanied this code.
10221828Sgrehan *
11221828Sgrehan * This code is distributed in the hope that it will be useful, but WITHOUT
12221828Sgrehan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13221828Sgrehan * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14221828Sgrehan * version 2 for more details (a copy is included in the LICENSE file that
15221828Sgrehan * accompanied this code).
16221828Sgrehan *
17221828Sgrehan * You should have received a copy of the GNU General Public License version
18221828Sgrehan * 2 along with this work; if not, write to the Free Software Foundation,
19221828Sgrehan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20221828Sgrehan *
21221828Sgrehan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22221828Sgrehan * or visit www.oracle.com if you need additional information or have any
23221828Sgrehan * questions.
24221828Sgrehan */
25221828Sgrehan
26221828Sgrehanpackage jdk.javadoc.internal.doclets.formats.html;
27221828Sgrehan
28221828Sgrehanimport java.io.IOException;
29221828Sgrehan
30221828Sgrehanimport javax.lang.model.element.ModuleElement;
31221828Sgrehanimport javax.lang.model.element.PackageElement;
32221828Sgrehanimport javax.lang.model.element.TypeElement;
33221828Sgrehanimport javax.lang.model.type.TypeMirror;
34221828Sgrehan
35221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.AnnotationTypeFieldWriter;
36221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.AnnotationTypeOptionalMemberWriter;
37221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter;
38221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
39221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.ClassWriter;
40221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter;
41221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
42221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.ModuleSummaryWriter;
43221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.PackageSummaryWriter;
44221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter;
45221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.WriterFactory;
46221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
47221828Sgrehanimport jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap;
48221828Sgrehan
49221828Sgrehanimport static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap.Kind.*;
50221828Sgrehan
51221828Sgrehan/**
52 * The factory that returns HTML writers.
53 *
54 *  <p><b>This is NOT part of any supported API.
55 *  If you write code that depends on this, you do so at your own risk.
56 *  This code and its internal interfaces are subject to change or
57 *  deletion without notice.</b>
58 *
59 * @author Jamie Ho
60 */
61public class WriterFactoryImpl implements WriterFactory {
62
63    private final ConfigurationImpl configuration;
64    public WriterFactoryImpl(ConfigurationImpl configuration) {
65        this.configuration = configuration;
66    }
67
68    /**
69     * {@inheritDoc}
70     */
71    @Override
72    public ConstantsSummaryWriter getConstantsSummaryWriter() throws Exception {
73        return new ConstantsSummaryWriterImpl(configuration);
74    }
75
76    /**
77     * {@inheritDoc}
78     */
79    @Override
80    public PackageSummaryWriter getPackageSummaryWriter(PackageElement packageElement,
81            PackageElement prevPkg, PackageElement nextPkg) throws Exception {
82        return new PackageWriterImpl(configuration, packageElement, prevPkg, nextPkg);
83    }
84
85    /**
86     * {@inheritDoc}
87     */
88    public ModuleSummaryWriter getModuleSummaryWriter(ModuleElement mdle,
89        ModuleElement prevModule, ModuleElement nextModule) throws Exception {
90        return new ModuleWriterImpl(configuration, mdle,
91            prevModule, nextModule);
92    }
93
94    /**
95     * {@inheritDoc}
96     */
97    @Override
98    public ClassWriter getClassWriter(TypeElement typeElement, TypeElement prevClass,
99            TypeElement nextClass, ClassTree classTree) throws IOException {
100        return new ClassWriterImpl(configuration, typeElement, prevClass, nextClass, classTree);
101    }
102
103    /**
104     * {@inheritDoc}
105     */
106    @Override
107    public AnnotationTypeWriter getAnnotationTypeWriter(TypeElement annotationType,
108            TypeMirror prevType, TypeMirror nextType) throws Exception {
109        return new AnnotationTypeWriterImpl(configuration, annotationType, prevType, nextType);
110    }
111
112    /**
113     * {@inheritDoc}
114     */
115    @Override
116    public AnnotationTypeFieldWriter
117            getAnnotationTypeFieldWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception {
118        TypeElement te = annotationTypeWriter.getAnnotationTypeElement();
119        return new AnnotationTypeFieldWriterImpl(
120            (SubWriterHolderWriter) annotationTypeWriter, te);
121    }
122
123    /**
124     * {@inheritDoc}
125     */
126    @Override
127    public AnnotationTypeOptionalMemberWriter
128            getAnnotationTypeOptionalMemberWriter(
129        AnnotationTypeWriter annotationTypeWriter) throws Exception {
130        TypeElement te = annotationTypeWriter.getAnnotationTypeElement();
131        return new AnnotationTypeOptionalMemberWriterImpl(
132            (SubWriterHolderWriter) annotationTypeWriter, te);
133    }
134
135    /**
136     * {@inheritDoc}
137     */
138    @Override
139    public AnnotationTypeRequiredMemberWriter
140            getAnnotationTypeRequiredMemberWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception {
141        TypeElement te = annotationTypeWriter.getAnnotationTypeElement();
142        return new AnnotationTypeRequiredMemberWriterImpl(
143            (SubWriterHolderWriter) annotationTypeWriter, te);
144    }
145
146    /**
147     * {@inheritDoc}
148     */
149    @Override
150    public EnumConstantWriterImpl getEnumConstantWriter(ClassWriter classWriter)
151            throws Exception {
152        return new EnumConstantWriterImpl((SubWriterHolderWriter) classWriter,
153                classWriter.getTypeElement());
154    }
155
156    /**
157     * {@inheritDoc}
158     */
159    @Override
160    public FieldWriterImpl getFieldWriter(ClassWriter classWriter)
161            throws Exception {
162        return new FieldWriterImpl((SubWriterHolderWriter) classWriter, classWriter.getTypeElement());
163    }
164
165    /**
166     * {@inheritDoc}
167     */
168    @Override
169    public PropertyWriterImpl getPropertyWriter(ClassWriter classWriter)
170            throws Exception {
171        return new PropertyWriterImpl((SubWriterHolderWriter) classWriter,
172                classWriter.getTypeElement());
173    }
174
175    /**
176     * {@inheritDoc}
177     */
178    @Override
179    public MethodWriterImpl getMethodWriter(ClassWriter classWriter)
180            throws Exception {
181        return new MethodWriterImpl((SubWriterHolderWriter) classWriter, classWriter.getTypeElement());
182    }
183
184    /**
185     * {@inheritDoc}
186     */
187    @Override
188    public ConstructorWriterImpl getConstructorWriter(ClassWriter classWriter)
189            throws Exception {
190        return new ConstructorWriterImpl((SubWriterHolderWriter) classWriter,
191                classWriter.getTypeElement());
192    }
193
194    /**
195     * {@inheritDoc}
196     */
197    @Override
198    public MemberSummaryWriter getMemberSummaryWriter(
199            ClassWriter classWriter, VisibleMemberMap.Kind memberType)
200            throws Exception {
201        switch (memberType) {
202            case CONSTRUCTORS:
203                return getConstructorWriter(classWriter);
204            case ENUM_CONSTANTS:
205                return getEnumConstantWriter(classWriter);
206            case FIELDS:
207                return getFieldWriter(classWriter);
208            case PROPERTIES:
209                return getPropertyWriter(classWriter);
210            case INNER_CLASSES:
211                return new NestedClassWriterImpl((SubWriterHolderWriter)
212                    classWriter, classWriter.getTypeElement());
213            case METHODS:
214                return getMethodWriter(classWriter);
215            default:
216                return null;
217        }
218    }
219
220    /**
221     * {@inheritDoc}
222     */
223    @Override
224    public MemberSummaryWriter getMemberSummaryWriter(
225        AnnotationTypeWriter annotationTypeWriter, VisibleMemberMap.Kind memberType)
226    throws Exception {
227        switch (memberType) {
228            case ANNOTATION_TYPE_FIELDS:
229                return (AnnotationTypeFieldWriterImpl)
230                    getAnnotationTypeFieldWriter(annotationTypeWriter);
231            case ANNOTATION_TYPE_MEMBER_OPTIONAL:
232                return (AnnotationTypeOptionalMemberWriterImpl)
233                    getAnnotationTypeOptionalMemberWriter(annotationTypeWriter);
234            case ANNOTATION_TYPE_MEMBER_REQUIRED:
235                return (AnnotationTypeRequiredMemberWriterImpl)
236                    getAnnotationTypeRequiredMemberWriter(annotationTypeWriter);
237            default:
238                return null;
239        }
240    }
241
242    /**
243     * {@inheritDoc}
244     */
245    @Override
246    public SerializedFormWriter getSerializedFormWriter() throws Exception {
247        return new SerializedFormWriterImpl(configuration);
248    }
249}
250