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