001/* 002 * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package org.jdrupes.mdoclet.internal.doclets.toolkit.builders; 027 028import java.util.HashSet; 029import java.util.Set; 030 031import javax.lang.model.element.ModuleElement; 032import javax.lang.model.element.PackageElement; 033import javax.lang.model.element.TypeElement; 034 035import org.jdrupes.mdoclet.internal.doclets.toolkit.BaseConfiguration; 036import org.jdrupes.mdoclet.internal.doclets.toolkit.ClassWriter; 037import org.jdrupes.mdoclet.internal.doclets.toolkit.PropertyWriter; 038import org.jdrupes.mdoclet.internal.doclets.toolkit.WriterFactory; 039import org.jdrupes.mdoclet.internal.doclets.toolkit.util.ClassTree; 040 041/** 042 * The factory for constructing builders. 043 */ 044public class BuilderFactory { 045 046 /** 047 * The factory to retrieve the required writers from. 048 */ 049 private final WriterFactory writerFactory; 050 051 private final AbstractBuilder.Context context; 052 053 /** 054 * Construct a builder factory using the given configuration. 055 * @param configuration the configuration for the current doclet 056 * being executed. 057 */ 058 public BuilderFactory(BaseConfiguration configuration) { 059 this.writerFactory = configuration.getWriterFactory(); 060 061 Set<PackageElement> containingPackagesSeen = new HashSet<>(); 062 context = new AbstractBuilder.Context(configuration, 063 containingPackagesSeen); 064 } 065 066 /** 067 * Return the builder that builds the constant summary. 068 * @return the builder that builds the constant summary. 069 */ 070 public AbstractBuilder getConstantsSummaryBuilder() { 071 return ConstantsSummaryBuilder.getInstance(context); 072 } 073 074 /** 075 * Return the builder that builds the package summary. 076 * 077 * @param pkg the package being documented. 078 * @return the builder that builds the package summary. 079 */ 080 public AbstractBuilder getPackageSummaryBuilder(PackageElement pkg) { 081 return PackageSummaryBuilder.getInstance(context, pkg, 082 writerFactory.getPackageSummaryWriter(pkg)); 083 } 084 085 /** 086 * Return the builder that builds the module summary. 087 * 088 * @param mdle the module being documented. 089 * @return the builder that builds the module summary. 090 */ 091 public AbstractBuilder getModuleSummaryBuilder(ModuleElement mdle) { 092 return ModuleSummaryBuilder.getInstance(context, mdle, 093 writerFactory.getModuleSummaryWriter(mdle)); 094 } 095 096 /** 097 * Return the builder for the class. 098 * 099 * @param typeElement the class being documented. 100 * @param classTree the class tree. 101 * @return the writer for the class. Return null if this 102 * writer is not supported by the doclet. 103 */ 104 public AbstractBuilder getClassBuilder(TypeElement typeElement, 105 ClassTree classTree) { 106 return ClassBuilder.getInstance(context, typeElement, 107 writerFactory.getClassWriter(typeElement, classTree)); 108 } 109 110 /** 111 * Return an instance of the method builder for the given class. 112 * 113 * @param classWriter the writer for the enclosing class 114 * @return an instance of the method builder for the given class. 115 */ 116 public AbstractMemberBuilder getMethodBuilder(ClassWriter classWriter) { 117 return MethodBuilder.getInstance(context, classWriter.getTypeElement(), 118 writerFactory.getMethodWriter(classWriter)); 119 } 120 121 /** 122 * Return an instance of the annotation type member builder for the given 123 * class. 124 * 125 * @param classWriter the writer for the enclosing annotation type 126 * @return an instance of the annotation type member builder for the given 127 * annotation type. 128 */ 129 public AbstractMemberBuilder getAnnotationTypeMemberBuilder( 130 ClassWriter classWriter) { 131 return AnnotationTypeMemberBuilder.getInstance(context, 132 classWriter.getTypeElement(), 133 writerFactory.getAnnotationTypeMemberWriter(classWriter)); 134 } 135 136 /** 137 * Return an instance of the enum constants builder for the given class. 138 * 139 * @param classWriter the writer for the enclosing class 140 * @return an instance of the enum constants builder for the given class. 141 */ 142 public AbstractMemberBuilder 143 getEnumConstantsBuilder(ClassWriter classWriter) { 144 return EnumConstantBuilder.getInstance(context, 145 classWriter.getTypeElement(), 146 writerFactory.getEnumConstantWriter(classWriter)); 147 } 148 149 /** 150 * Return an instance of the field builder for the given class. 151 * 152 * @param classWriter the writer for the enclosing class 153 * @return an instance of the field builder for the given class. 154 */ 155 public AbstractMemberBuilder getFieldBuilder(ClassWriter classWriter) { 156 return FieldBuilder.getInstance(context, classWriter.getTypeElement(), 157 writerFactory.getFieldWriter(classWriter)); 158 } 159 160 /** 161 * Return an instance of the property builder for the given class. 162 * 163 * @param classWriter the writer for the enclosing class 164 * @return an instance of the field builder for the given class. 165 */ 166 public AbstractMemberBuilder getPropertyBuilder(ClassWriter classWriter) { 167 final PropertyWriter propertyWriter 168 = writerFactory.getPropertyWriter(classWriter); 169 return PropertyBuilder.getInstance(context, 170 classWriter.getTypeElement(), 171 propertyWriter); 172 } 173 174 /** 175 * Return an instance of the constructor builder for the given class. 176 * 177 * @param classWriter the writer for the enclosing class 178 * @return an instance of the constructor builder for the given class. 179 */ 180 public AbstractMemberBuilder 181 getConstructorBuilder(ClassWriter classWriter) { 182 return ConstructorBuilder.getInstance(context, 183 classWriter.getTypeElement(), 184 writerFactory.getConstructorWriter(classWriter)); 185 } 186 187 /** 188 * Return an instance of the member summary builder for the given class. 189 * 190 * @param classWriter the writer for the enclosing class 191 * @return an instance of the member summary builder for the given class. 192 */ 193 public MemberSummaryBuilder 194 getMemberSummaryBuilder(ClassWriter classWriter) { 195 return MemberSummaryBuilder.getInstance(classWriter, context); 196 } 197 198 /** 199 * Return the builder that builds the serialized form. 200 * 201 * @return the builder that builds the serialized form. 202 */ 203 public AbstractBuilder getSerializedFormBuilder() { 204 return SerializedFormBuilder.getInstance(context); 205 } 206}