1/* 2 * Copyright (c) 2003, 2017, 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.toolkit.builders; 27 28import java.util.HashSet; 29import java.util.Set; 30 31import javax.lang.model.element.ModuleElement; 32import javax.lang.model.element.PackageElement; 33import javax.lang.model.element.TypeElement; 34import javax.lang.model.type.TypeMirror; 35 36import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter; 37import jdk.javadoc.internal.doclets.toolkit.ClassWriter; 38import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration; 39import jdk.javadoc.internal.doclets.toolkit.PropertyWriter; 40import jdk.javadoc.internal.doclets.toolkit.WriterFactory; 41import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; 42 43/** 44 * The factory for constructing builders. 45 * 46 * <p><b>This is NOT part of any supported API. 47 * If you write code that depends on this, you do so at your own risk. 48 * This code and its internal interfaces are subject to change or 49 * deletion without notice.</b> 50 * 51 * @author Jamie Ho 52 */ 53 54public class BuilderFactory { 55 56 /** 57 * The factory to retrieve the required writers from. 58 */ 59 private final WriterFactory writerFactory; 60 61 private final AbstractBuilder.Context context; 62 63 /** 64 * Construct a builder factory using the given configuration. 65 * @param configuration the configuration for the current doclet 66 * being executed. 67 */ 68 public BuilderFactory (BaseConfiguration configuration) { 69 this.writerFactory = configuration.getWriterFactory(); 70 71 Set<PackageElement> containingPackagesSeen = new HashSet<>(); 72 context = new AbstractBuilder.Context(configuration, containingPackagesSeen); 73 } 74 75 /** 76 * Return the builder that builds the constant summary. 77 * @return the builder that builds the constant summary. 78 */ 79 public AbstractBuilder getConstantsSummaryBuilder() { 80 return ConstantsSummaryBuilder.getInstance(context, 81 writerFactory.getConstantsSummaryWriter()); 82 } 83 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(PackageElement pkg, PackageElement prevPkg, 93 PackageElement nextPkg) { 94 return PackageSummaryBuilder.getInstance(context, pkg, 95 writerFactory.getPackageSummaryWriter(pkg, prevPkg, nextPkg)); 96 } 97 98 /** 99 * Return the builder that builds the module summary. 100 * 101 * @param mdle the module being documented. 102 * @param prevModule the previous module being documented. 103 * @param nextModule the next module being documented. 104 * @return the builder that builds the module summary. 105 */ 106 public AbstractBuilder getModuleSummaryBuilder(ModuleElement mdle, ModuleElement prevModule, 107 ModuleElement nextModule) { 108 return ModuleSummaryBuilder.getInstance(context, mdle, 109 writerFactory.getModuleSummaryWriter(mdle, prevModule, nextModule)); 110 } 111 112 /** 113 * Return the builder for the class. 114 * 115 * @param typeElement the class being documented. 116 * @param prevClass the previous class that was documented. 117 * @param nextClass the next class being documented. 118 * @param classTree the class tree. 119 * @return the writer for the class. Return null if this 120 * writer is not supported by the doclet. 121 */ 122 public AbstractBuilder getClassBuilder(TypeElement typeElement, 123 TypeElement prevClass, TypeElement nextClass, ClassTree classTree) { 124 return ClassBuilder.getInstance(context, typeElement, 125 writerFactory.getClassWriter(typeElement, prevClass, nextClass, classTree)); 126 } 127 128 /** 129 * Return the builder for the annotation type. 130 * 131 * @param annotationType the annotation type being documented. 132 * @param prevType the previous type that was documented. 133 * @param nextType the next type being documented. 134 * @return the writer for the annotation type. Return null if this 135 * writer is not supported by the doclet. 136 */ 137 public AbstractBuilder getAnnotationTypeBuilder( 138 TypeElement annotationType, TypeMirror prevType, TypeMirror nextType) { 139 return AnnotationTypeBuilder.getInstance(context, annotationType, 140 writerFactory.getAnnotationTypeWriter(annotationType, prevType, nextType)); 141 } 142 143 /** 144 * Return an instance of the method builder for the given class. 145 * 146 * @param classWriter the writer for the enclosing class 147 * @return an instance of the method builder for the given class. 148 */ 149 public AbstractMemberBuilder getMethodBuilder(ClassWriter classWriter) { 150 return MethodBuilder.getInstance(context, classWriter.getTypeElement(), 151 writerFactory.getMethodWriter(classWriter)); 152 } 153 154 /** 155 * Return an instance of the annotation type fields builder for the given 156 * class. 157 * 158 * @param annotationTypeWriter the writer for the enclosing annotation type 159 * @return an instance of the annotation type field builder for the given 160 * annotation type. 161 */ 162 public AbstractMemberBuilder getAnnotationTypeFieldsBuilder( 163 AnnotationTypeWriter annotationTypeWriter) { 164 return AnnotationTypeFieldBuilder.getInstance(context, 165 annotationTypeWriter.getAnnotationTypeElement(), 166 writerFactory.getAnnotationTypeFieldWriter(annotationTypeWriter)); 167 } 168 169 /** 170 * Return an instance of the annotation type member builder for the given 171 * class. 172 * 173 * @param annotationTypeWriter the writer for the enclosing annotation type 174 * @return an instance of the annotation type member builder for the given 175 * annotation type. 176 */ 177 public AbstractMemberBuilder getAnnotationTypeOptionalMemberBuilder( 178 AnnotationTypeWriter annotationTypeWriter) { 179 return AnnotationTypeOptionalMemberBuilder.getInstance(context, 180 annotationTypeWriter.getAnnotationTypeElement(), 181 writerFactory.getAnnotationTypeOptionalMemberWriter(annotationTypeWriter)); 182 } 183 184 /** 185 * Return an instance of the annotation type member builder for the given 186 * class. 187 * 188 * @param annotationTypeWriter the writer for the enclosing annotation type 189 * @return an instance of the annotation type member builder for the given 190 * annotation type. 191 */ 192 public AbstractMemberBuilder getAnnotationTypeRequiredMemberBuilder( 193 AnnotationTypeWriter annotationTypeWriter) { 194 return AnnotationTypeRequiredMemberBuilder.getInstance(context, 195 annotationTypeWriter.getAnnotationTypeElement(), 196 writerFactory.getAnnotationTypeRequiredMemberWriter(annotationTypeWriter)); 197 } 198 199 /** 200 * Return an instance of the enum constants builder for the given class. 201 * 202 * @param classWriter the writer for the enclosing class 203 * @return an instance of the enum constants builder for the given class. 204 */ 205 public AbstractMemberBuilder getEnumConstantsBuilder(ClassWriter classWriter) { 206 return EnumConstantBuilder.getInstance(context, classWriter.getTypeElement(), 207 writerFactory.getEnumConstantWriter(classWriter)); 208 } 209 210 /** 211 * Return an instance of the field builder for the given class. 212 * 213 * @param classWriter the writer for the enclosing class 214 * @return an instance of the field builder for the given class. 215 */ 216 public AbstractMemberBuilder getFieldBuilder(ClassWriter classWriter) { 217 return FieldBuilder.getInstance(context, classWriter.getTypeElement(), 218 writerFactory.getFieldWriter(classWriter)); 219 } 220 221 /** 222 * Return an instance of the property builder for the given class. 223 * 224 * @param classWriter the writer for the enclosing class 225 * @return an instance of the field builder for the given class. 226 */ 227 public AbstractMemberBuilder 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 * @param classWriter the writer for the enclosing class 239 * @return an instance of the constructor builder for the given class. 240 */ 241 public AbstractMemberBuilder getConstructorBuilder(ClassWriter classWriter) { 242 return ConstructorBuilder.getInstance(context, classWriter.getTypeElement(), 243 writerFactory.getConstructorWriter(classWriter)); 244 } 245 246 /** 247 * Return an instance of the member summary builder for the given class. 248 * 249 * @param classWriter the writer for the enclosing class 250 * @return an instance of the member summary builder for the given class. 251 */ 252 public MemberSummaryBuilder getMemberSummaryBuilder(ClassWriter classWriter) { 253 return MemberSummaryBuilder.getInstance(classWriter, context); 254 } 255 256 /** 257 * Return an instance of the member summary builder for the given annotation 258 * type. 259 * 260 * @param annotationTypeWriter the writer for the enclosing annotation type 261 * @return an instance of the member summary builder for the given 262 * annotation type. 263 */ 264 public MemberSummaryBuilder getMemberSummaryBuilder(AnnotationTypeWriter annotationTypeWriter) { 265 return MemberSummaryBuilder.getInstance(annotationTypeWriter, context); 266 } 267 268 /** 269 * Return the builder that builds the serialized form. 270 * 271 * @return the builder that builds the serialized form. 272 */ 273 public AbstractBuilder getSerializedFormBuilder() { 274 return SerializedFormBuilder.getInstance(context); 275 } 276} 277