1 /* 2 * Copyright (c) 2003, 2019, 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.BaseConfiguration; 37 import jdk.javadoc.internal.doclets.toolkit.ClassWriter; 38 import jdk.javadoc.internal.doclets.toolkit.PropertyWriter; 39 import jdk.javadoc.internal.doclets.toolkit.WriterFactory; 40 import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; 41 42 43 44 45 /** 46 * The factory for constructing builders. 47 * 48 * <p><b>This is NOT part of any supported API. 49 * If you write code that depends on this, you do so at your own risk. 50 * This code and its internal interfaces are subject to change or 51 * deletion without notice.</b> 52 */ 53 54 public 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 */ BuilderFactory(BaseConfiguration configuration)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 */ getConstantsSummaryBuilder()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 * @return the builder that builds the package summary. 89 */ getPackageSummaryBuilder(PackageElement pkg)90 public AbstractBuilder getPackageSummaryBuilder(PackageElement pkg) { 91 return PackageSummaryBuilder.getInstance(context, pkg, 92 writerFactory.getPackageSummaryWriter(pkg)); 93 } 94 95 /** 96 * Return the builder that builds the module summary. 97 * 98 * @param mdle the module being documented. 99 * @return the builder that builds the module summary. 100 */ getModuleSummaryBuilder(ModuleElement mdle)101 public AbstractBuilder getModuleSummaryBuilder(ModuleElement mdle) { 102 return ModuleSummaryBuilder.getInstance(context, mdle, 103 writerFactory.getModuleSummaryWriter(mdle)); 104 } 105 106 /** 107 * Return the builder for the class. 108 * 109 * @param typeElement the class being documented. 110 * @param classTree the class tree. 111 * @return the writer for the class. Return null if this 112 * writer is not supported by the doclet. 113 */ getClassBuilder(TypeElement typeElement, ClassTree classTree)114 public AbstractBuilder getClassBuilder(TypeElement typeElement, ClassTree classTree) { 115 return ClassBuilder.getInstance(context, typeElement, 116 writerFactory.getClassWriter(typeElement, classTree)); 117 } 118 119 /** 120 * Return an instance of the method builder for the given class. 121 * 122 * @param classWriter the writer for the enclosing class 123 * @return an instance of the method builder for the given class. 124 */ getMethodBuilder(ClassWriter classWriter)125 public AbstractMemberBuilder getMethodBuilder(ClassWriter classWriter) { 126 return MethodBuilder.getInstance(context, classWriter.getTypeElement(), 127 writerFactory.getMethodWriter(classWriter)); 128 } 129 130 /** 131 * Return an instance of the annotation type member builder for the given 132 * class. 133 * 134 * @param classWriter the writer for the enclosing annotation type 135 * @return an instance of the annotation type member builder for the given 136 * annotation type. 137 */ getAnnotationTypeOptionalMemberBuilder( ClassWriter classWriter)138 public AbstractMemberBuilder getAnnotationTypeOptionalMemberBuilder( 139 ClassWriter classWriter) { 140 return AnnotationTypeOptionalMemberBuilder.getInstance(context, 141 classWriter.getTypeElement(), 142 writerFactory.getAnnotationTypeOptionalMemberWriter(classWriter)); 143 } 144 145 /** 146 * Return an instance of the annotation type member builder for the given 147 * class. 148 * 149 * @param classWriter the writer for the enclosing annotation type 150 * @return an instance of the annotation type member builder for the given 151 * annotation type. 152 */ getAnnotationTypeRequiredMemberBuilder( ClassWriter classWriter)153 public AbstractMemberBuilder getAnnotationTypeRequiredMemberBuilder( 154 ClassWriter classWriter) { 155 return AnnotationTypeRequiredMemberBuilder.getInstance(context, 156 classWriter.getTypeElement(), 157 writerFactory.getAnnotationTypeRequiredMemberWriter(classWriter)); 158 } 159 160 /** 161 * Return an instance of the enum constants builder for the given class. 162 * 163 * @param classWriter the writer for the enclosing class 164 * @return an instance of the enum constants builder for the given class. 165 */ getEnumConstantsBuilder(ClassWriter classWriter)166 public AbstractMemberBuilder getEnumConstantsBuilder(ClassWriter classWriter) { 167 return EnumConstantBuilder.getInstance(context, classWriter.getTypeElement(), 168 writerFactory.getEnumConstantWriter(classWriter)); 169 } 170 171 /** 172 * Return an instance of the field builder for the given class. 173 * 174 * @param classWriter the writer for the enclosing class 175 * @return an instance of the field builder for the given class. 176 */ getFieldBuilder(ClassWriter classWriter)177 public AbstractMemberBuilder getFieldBuilder(ClassWriter classWriter) { 178 return FieldBuilder.getInstance(context, classWriter.getTypeElement(), 179 writerFactory.getFieldWriter(classWriter)); 180 } 181 182 /** 183 * Return an instance of the property builder for the given class. 184 * 185 * @param classWriter the writer for the enclosing class 186 * @return an instance of the field builder for the given class. 187 */ getPropertyBuilder(ClassWriter classWriter)188 public AbstractMemberBuilder getPropertyBuilder(ClassWriter classWriter) { 189 final PropertyWriter propertyWriter = 190 writerFactory.getPropertyWriter(classWriter); 191 return PropertyBuilder.getInstance(context, 192 classWriter.getTypeElement(), 193 propertyWriter); 194 } 195 196 /** 197 * Return an instance of the constructor builder for the given class. 198 * 199 * @param classWriter the writer for the enclosing class 200 * @return an instance of the constructor builder for the given class. 201 */ getConstructorBuilder(ClassWriter classWriter)202 public AbstractMemberBuilder getConstructorBuilder(ClassWriter classWriter) { 203 return ConstructorBuilder.getInstance(context, classWriter.getTypeElement(), 204 writerFactory.getConstructorWriter(classWriter)); 205 } 206 207 /** 208 * Return an instance of the member summary builder for the given class. 209 * 210 * @param classWriter the writer for the enclosing class 211 * @return an instance of the member summary builder for the given class. 212 */ getMemberSummaryBuilder(ClassWriter classWriter)213 public MemberSummaryBuilder getMemberSummaryBuilder(ClassWriter classWriter) { 214 return MemberSummaryBuilder.getInstance(classWriter, context); 215 } 216 217 /** 218 * Return the builder that builds the serialized form. 219 * 220 * @return the builder that builds the serialized form. 221 */ getSerializedFormBuilder()222 public AbstractBuilder getSerializedFormBuilder() { 223 return SerializedFormBuilder.getInstance(context); 224 } 225 } 226