BuilderFactory.java revision 3294:9adfb22ff08f
152419Sjulian/* 252419Sjulian * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. 352419Sjulian * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 452419Sjulian * 552419Sjulian * This code is free software; you can redistribute it and/or modify it 652419Sjulian * under the terms of the GNU General Public License version 2 only, as 752419Sjulian * published by the Free Software Foundation. Oracle designates this 852419Sjulian * particular file as subject to the "Classpath" exception as provided 952419Sjulian * by Oracle in the LICENSE file that accompanied this code. 1052419Sjulian * 1152419Sjulian * This code is distributed in the hope that it will be useful, but WITHOUT 1252419Sjulian * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1352419Sjulian * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1452419Sjulian * version 2 for more details (a copy is included in the LICENSE file that 1552419Sjulian * accompanied this code). 1652419Sjulian * 1752419Sjulian * You should have received a copy of the GNU General Public License version 1852419Sjulian * 2 along with this work; if not, write to the Free Software Foundation, 1952419Sjulian * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2052419Sjulian * 2152419Sjulian * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2252419Sjulian * or visit www.oracle.com if you need additional information or have any 2352419Sjulian * questions. 2452419Sjulian */ 2552419Sjulian 2652419Sjulianpackage jdk.javadoc.internal.doclets.toolkit.builders; 2752419Sjulian 2852419Sjulianimport java.util.HashSet; 2952419Sjulianimport java.util.Set; 3052419Sjulian 3152419Sjulianimport javax.lang.model.element.ModuleElement; 3252419Sjulianimport javax.lang.model.element.PackageElement; 3352419Sjulianimport javax.lang.model.element.TypeElement; 3452419Sjulianimport javax.lang.model.type.TypeMirror; 3552419Sjulian 3652419Sjulianimport jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter; 3752419Sjulianimport jdk.javadoc.internal.doclets.toolkit.ClassWriter; 3852419Sjulianimport jdk.javadoc.internal.doclets.toolkit.Configuration; 3952419Sjulianimport jdk.javadoc.internal.doclets.toolkit.PropertyWriter; 40158882Sglebiusimport jdk.javadoc.internal.doclets.toolkit.WriterFactory; 41158882Sglebiusimport jdk.javadoc.internal.doclets.toolkit.util.ClassTree; 42158882Sglebius 43158882Sglebius/** 44158882Sglebius * The factory for constructing builders. 4552419Sjulian * 4652419Sjulian * <p><b>This is NOT part of any supported API. 4752419Sjulian * If you write code that depends on this, you do so at your own risk. 4852419Sjulian * This code and its internal interfaces are subject to change or 4952419Sjulian * deletion without notice.</b> 5052419Sjulian * 5152419Sjulian * @author Jamie Ho 5252419Sjulian */ 5352419Sjulian 5452419Sjulianpublic class BuilderFactory { 5552419Sjulian 56125011Sru /** 57160423Sstefanf * The current configuration of the doclet. 5852419Sjulian */ 5952419Sjulian private final Configuration configuration; 6052419Sjulian 6152419Sjulian /** 6252419Sjulian * The factory to retrieve the required writers from. 6352419Sjulian */ 6452419Sjulian private final WriterFactory writerFactory; 6552419Sjulian 6652419Sjulian private final AbstractBuilder.Context context; 6752419Sjulian 6852419Sjulian /** 6952419Sjulian * Construct a builder factory using the given configuration. 7052419Sjulian * @param configuration the configuration for the current doclet 7152419Sjulian * being executed. 7252419Sjulian */ 73160002Sglebius public BuilderFactory (Configuration configuration) { 7452419Sjulian this.configuration = configuration; 7552419Sjulian this.writerFactory = configuration.getWriterFactory(); 7652419Sjulian 7752419Sjulian Set<PackageElement> containingPackagesSeen = new HashSet<>(); 7852419Sjulian context = new AbstractBuilder.Context(configuration, containingPackagesSeen, 7952419Sjulian LayoutParser.getInstance(configuration)); 80160002Sglebius } 8152419Sjulian 82160002Sglebius /** 8352419Sjulian * Return the builder that builds the constant summary. 8452419Sjulian * @return the builder that builds the constant summary. 85 */ 86 public AbstractBuilder getConstantsSummaryBuilder() throws Exception { 87 return ConstantsSummaryBuilder.getInstance(context, 88 writerFactory.getConstantsSummaryWriter()); 89 } 90 91 /** 92 * Return the builder that builds the package summary. 93 * 94 * @param pkg the package being documented. 95 * @param prevPkg the previous package being documented. 96 * @param nextPkg the next package being documented. 97 * @return the builder that builds the constant summary. 98 */ 99 public AbstractBuilder getPackageSummaryBuilder(PackageElement pkg, PackageElement prevPkg, 100 PackageElement nextPkg) throws Exception { 101 return PackageSummaryBuilder.getInstance(context, pkg, 102 writerFactory.getPackageSummaryWriter(pkg, prevPkg, nextPkg)); 103 } 104 105 /** 106 * Return the builder that builds the module summary. 107 * 108 * @param mdle the module being documented. 109 * @param prevModule the previous module being documented. 110 * @param nextModule the next module being documented. 111 * @return the builder that builds the module summary. 112 */ 113 public AbstractBuilder getModuleSummaryBuilder(ModuleElement mdle, ModuleElement prevModule, 114 ModuleElement nextModule) throws Exception { 115 return ModuleSummaryBuilder.getInstance(context, mdle, 116 writerFactory.getModuleSummaryWriter(mdle, prevModule, nextModule)); 117 } 118 119 /** 120 * Return the builder for the class. 121 * 122 * @param typeElement the class being documented. 123 * @param prevClass the previous class that was documented. 124 * @param nextClass the next class being documented. 125 * @param classTree the class tree. 126 * @return the writer for the class. Return null if this 127 * writer is not supported by the doclet. 128 */ 129 public AbstractBuilder getClassBuilder(TypeElement typeElement, 130 TypeElement prevClass, TypeElement nextClass, ClassTree classTree) 131 throws Exception { 132 return ClassBuilder.getInstance(context, typeElement, 133 writerFactory.getClassWriter(typeElement, prevClass, nextClass, classTree)); 134 } 135 136 /** 137 * Return the builder for the annotation type. 138 * 139 * @param annotationType the annotation type being documented. 140 * @param prevType the previous type that was documented. 141 * @param nextType the next type being documented. 142 * @return the writer for the annotation type. Return null if this 143 * writer is not supported by the doclet. 144 */ 145 public AbstractBuilder getAnnotationTypeBuilder( 146 TypeElement annotationType, TypeMirror prevType, TypeMirror nextType) 147 throws Exception { 148 return AnnotationTypeBuilder.getInstance(context, annotationType, 149 writerFactory.getAnnotationTypeWriter(annotationType, prevType, nextType)); 150 } 151 152 /** 153 * Return an instance of the method builder for the given class. 154 * 155 * @return an instance of the method builder for the given class. 156 */ 157 public AbstractBuilder getMethodBuilder(ClassWriter classWriter) 158 throws Exception { 159 return MethodBuilder.getInstance(context, classWriter.getTypeElement(), 160 writerFactory.getMethodWriter(classWriter)); 161 } 162 163 /** 164 * Return an instance of the annotation type fields builder for the given 165 * class. 166 * 167 * @return an instance of the annotation type field builder for the given 168 * annotation type. 169 */ 170 public AbstractBuilder getAnnotationTypeFieldsBuilder( 171 AnnotationTypeWriter annotationTypeWriter) 172 throws Exception { 173 return AnnotationTypeFieldBuilder.getInstance(context, 174 annotationTypeWriter.getAnnotationTypeElement(), 175 writerFactory.getAnnotationTypeFieldWriter(annotationTypeWriter)); 176 } 177 178 /** 179 * Return an instance of the annotation type member builder for the given 180 * class. 181 * 182 * @return an instance of the annotation type member builder for the given 183 * annotation type. 184 */ 185 public AbstractBuilder getAnnotationTypeOptionalMemberBuilder( 186 AnnotationTypeWriter annotationTypeWriter) 187 throws Exception { 188 return AnnotationTypeOptionalMemberBuilder.getInstance(context, 189 annotationTypeWriter.getAnnotationTypeElement(), 190 writerFactory.getAnnotationTypeOptionalMemberWriter(annotationTypeWriter)); 191 } 192 193 /** 194 * Return an instance of the annotation type member builder for the given 195 * class. 196 * 197 * @return an instance of the annotation type member builder for the given 198 * annotation type. 199 */ 200 public AbstractBuilder getAnnotationTypeRequiredMemberBuilder( 201 AnnotationTypeWriter annotationTypeWriter) 202 throws Exception { 203 return AnnotationTypeRequiredMemberBuilder.getInstance(context, 204 annotationTypeWriter.getAnnotationTypeElement(), 205 writerFactory.getAnnotationTypeRequiredMemberWriter(annotationTypeWriter)); 206 } 207 208 /** 209 * Return an instance of the enum constants builder for the given class. 210 * 211 * @return an instance of the enum constants builder for the given class. 212 */ 213 public AbstractBuilder getEnumConstantsBuilder(ClassWriter classWriter) 214 throws Exception { 215 return EnumConstantBuilder.getInstance(context, classWriter.getTypeElement(), 216 writerFactory.getEnumConstantWriter(classWriter)); 217 } 218 219 /** 220 * Return an instance of the field builder for the given class. 221 * 222 * @return an instance of the field builder for the given class. 223 */ 224 public AbstractBuilder getFieldBuilder(ClassWriter classWriter) throws Exception { 225 return FieldBuilder.getInstance(context, classWriter.getTypeElement(), 226 writerFactory.getFieldWriter(classWriter)); 227 } 228 229 /** 230 * Return an instance of the property builder for the given class. 231 * 232 * @return an instance of the field builder for the given class. 233 */ 234 public AbstractBuilder getPropertyBuilder(ClassWriter classWriter) throws Exception { 235 final PropertyWriter propertyWriter = 236 writerFactory.getPropertyWriter(classWriter); 237 return PropertyBuilder.getInstance(context, 238 classWriter.getTypeElement(), 239 propertyWriter); 240 } 241 242 /** 243 * Return an instance of the constructor builder for the given class. 244 * 245 * @return an instance of the constructor builder for the given class. 246 */ 247 public AbstractBuilder getConstructorBuilder(ClassWriter classWriter) 248 throws Exception { 249 return ConstructorBuilder.getInstance(context, classWriter.getTypeElement(), 250 writerFactory.getConstructorWriter(classWriter)); 251 } 252 253 /** 254 * Return an instance of the member summary builder for the given class. 255 * 256 * @return an instance of the member summary builder for the given class. 257 */ 258 public AbstractBuilder getMemberSummaryBuilder(ClassWriter classWriter) 259 throws Exception { 260 return MemberSummaryBuilder.getInstance(classWriter, context); 261 } 262 263 /** 264 * Return an instance of the member summary builder for the given annotation 265 * type. 266 * 267 * @return an instance of the member summary builder for the given 268 * annotation type. 269 */ 270 public AbstractBuilder getMemberSummaryBuilder( 271 AnnotationTypeWriter annotationTypeWriter) 272 throws Exception { 273 return MemberSummaryBuilder.getInstance(annotationTypeWriter, context); 274 } 275 276 /** 277 * Return the builder that builds the serialized form. 278 * 279 * @return the builder that builds the serialized form. 280 */ 281 public AbstractBuilder getSerializedFormBuilder() 282 throws Exception { 283 return SerializedFormBuilder.getInstance(context); 284 } 285} 286