WriterFactoryImpl.java revision 3233:b5d08bc0d224
1/* 2 * Copyright (c) 2003, 2016, 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 26package jdk.javadoc.internal.doclets.formats.html; 27 28import java.io.IOException; 29 30import javax.lang.model.element.PackageElement; 31import javax.lang.model.element.TypeElement; 32import javax.lang.model.type.TypeMirror; 33 34import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeFieldWriter; 35import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeOptionalMemberWriter; 36import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter; 37import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter; 38import jdk.javadoc.internal.doclets.toolkit.ClassWriter; 39import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter; 40import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter; 41import jdk.javadoc.internal.doclets.toolkit.PackageSummaryWriter; 42import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; 43import jdk.javadoc.internal.doclets.toolkit.WriterFactory; 44import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; 45import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap; 46 47import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap.Kind.*; 48 49/** 50 * The factory that returns HTML writers. 51 * 52 * <p><b>This is NOT part of any supported API. 53 * If you write code that depends on this, you do so at your own risk. 54 * This code and its internal interfaces are subject to change or 55 * deletion without notice.</b> 56 * 57 * @author Jamie Ho 58 */ 59public class WriterFactoryImpl implements WriterFactory { 60 61 private final ConfigurationImpl configuration; 62 public WriterFactoryImpl(ConfigurationImpl configuration) { 63 this.configuration = configuration; 64 } 65 66 /** 67 * {@inheritDoc} 68 */ 69 @Override 70 public ConstantsSummaryWriter getConstantsSummaryWriter() throws Exception { 71 return new ConstantsSummaryWriterImpl(configuration); 72 } 73 74 /** 75 * {@inheritDoc} 76 */ 77 @Override 78 public PackageSummaryWriter getPackageSummaryWriter(PackageElement packageElement, 79 PackageElement prevPkg, PackageElement nextPkg) throws Exception { 80 return new PackageWriterImpl(configuration, packageElement, prevPkg, nextPkg); 81 } 82 83 /** 84 * {@inheritDoc} 85 */ 86 @Override 87 public ClassWriter getClassWriter(TypeElement typeElement, TypeElement prevClass, 88 TypeElement nextClass, ClassTree classTree) throws IOException { 89 return new ClassWriterImpl(configuration, typeElement, prevClass, nextClass, classTree); 90 } 91 92 /** 93 * {@inheritDoc} 94 */ 95 @Override 96 public AnnotationTypeWriter getAnnotationTypeWriter(TypeElement annotationType, 97 TypeMirror prevType, TypeMirror nextType) throws Exception { 98 return new AnnotationTypeWriterImpl(configuration, annotationType, prevType, nextType); 99 } 100 101 /** 102 * {@inheritDoc} 103 */ 104 @Override 105 public AnnotationTypeFieldWriter 106 getAnnotationTypeFieldWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception { 107 TypeElement te = annotationTypeWriter.getAnnotationTypeElement(); 108 return new AnnotationTypeFieldWriterImpl( 109 (SubWriterHolderWriter) annotationTypeWriter, te); 110 } 111 112 /** 113 * {@inheritDoc} 114 */ 115 @Override 116 public AnnotationTypeOptionalMemberWriter 117 getAnnotationTypeOptionalMemberWriter( 118 AnnotationTypeWriter annotationTypeWriter) throws Exception { 119 TypeElement te = annotationTypeWriter.getAnnotationTypeElement(); 120 return new AnnotationTypeOptionalMemberWriterImpl( 121 (SubWriterHolderWriter) annotationTypeWriter, te); 122 } 123 124 /** 125 * {@inheritDoc} 126 */ 127 @Override 128 public AnnotationTypeRequiredMemberWriter 129 getAnnotationTypeRequiredMemberWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception { 130 TypeElement te = annotationTypeWriter.getAnnotationTypeElement(); 131 return new AnnotationTypeRequiredMemberWriterImpl( 132 (SubWriterHolderWriter) annotationTypeWriter, te); 133 } 134 135 /** 136 * {@inheritDoc} 137 */ 138 @Override 139 public EnumConstantWriterImpl getEnumConstantWriter(ClassWriter classWriter) 140 throws Exception { 141 return new EnumConstantWriterImpl((SubWriterHolderWriter) classWriter, 142 classWriter.getTypeElement()); 143 } 144 145 /** 146 * {@inheritDoc} 147 */ 148 @Override 149 public FieldWriterImpl getFieldWriter(ClassWriter classWriter) 150 throws Exception { 151 return new FieldWriterImpl((SubWriterHolderWriter) classWriter, classWriter.getTypeElement()); 152 } 153 154 /** 155 * {@inheritDoc} 156 */ 157 @Override 158 public PropertyWriterImpl getPropertyWriter(ClassWriter classWriter) 159 throws Exception { 160 return new PropertyWriterImpl((SubWriterHolderWriter) classWriter, 161 classWriter.getTypeElement()); 162 } 163 164 /** 165 * {@inheritDoc} 166 */ 167 @Override 168 public MethodWriterImpl getMethodWriter(ClassWriter classWriter) 169 throws Exception { 170 return new MethodWriterImpl((SubWriterHolderWriter) classWriter, classWriter.getTypeElement()); 171 } 172 173 /** 174 * {@inheritDoc} 175 */ 176 @Override 177 public ConstructorWriterImpl getConstructorWriter(ClassWriter classWriter) 178 throws Exception { 179 return new ConstructorWriterImpl((SubWriterHolderWriter) classWriter, 180 classWriter.getTypeElement()); 181 } 182 183 /** 184 * {@inheritDoc} 185 */ 186 @Override 187 public MemberSummaryWriter getMemberSummaryWriter( 188 ClassWriter classWriter, VisibleMemberMap.Kind memberType) 189 throws Exception { 190 switch (memberType) { 191 case CONSTRUCTORS: 192 return getConstructorWriter(classWriter); 193 case ENUM_CONSTANTS: 194 return getEnumConstantWriter(classWriter); 195 case FIELDS: 196 return getFieldWriter(classWriter); 197 case PROPERTIES: 198 return getPropertyWriter(classWriter); 199 case INNER_CLASSES: 200 return new NestedClassWriterImpl((SubWriterHolderWriter) 201 classWriter, classWriter.getTypeElement()); 202 case METHODS: 203 return getMethodWriter(classWriter); 204 default: 205 return null; 206 } 207 } 208 209 /** 210 * {@inheritDoc} 211 */ 212 @Override 213 public MemberSummaryWriter getMemberSummaryWriter( 214 AnnotationTypeWriter annotationTypeWriter, VisibleMemberMap.Kind memberType) 215 throws Exception { 216 switch (memberType) { 217 case ANNOTATION_TYPE_FIELDS: 218 return (AnnotationTypeFieldWriterImpl) 219 getAnnotationTypeFieldWriter(annotationTypeWriter); 220 case ANNOTATION_TYPE_MEMBER_OPTIONAL: 221 return (AnnotationTypeOptionalMemberWriterImpl) 222 getAnnotationTypeOptionalMemberWriter(annotationTypeWriter); 223 case ANNOTATION_TYPE_MEMBER_REQUIRED: 224 return (AnnotationTypeRequiredMemberWriterImpl) 225 getAnnotationTypeRequiredMemberWriter(annotationTypeWriter); 226 default: 227 return null; 228 } 229 } 230 231 /** 232 * {@inheritDoc} 233 */ 234 @Override 235 public SerializedFormWriter getSerializedFormWriter() throws Exception { 236 return new SerializedFormWriterImpl(configuration); 237 } 238} 239