aoqi@0: /* aoqi@0: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.doclets.internal.toolkit.builders; aoqi@0: aoqi@0: import java.util.HashSet; aoqi@0: import java.util.Set; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.javac.jvm.Profile; aoqi@0: import com.sun.tools.doclets.internal.toolkit.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*; aoqi@0: aoqi@0: /** aoqi@0: * The factory for constructing builders. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @author Jamie Ho aoqi@0: * @since 1.4 aoqi@0: */ aoqi@0: aoqi@0: public class BuilderFactory { aoqi@0: aoqi@0: /** aoqi@0: * The current configuration of the doclet. aoqi@0: */ aoqi@0: private final Configuration configuration; aoqi@0: aoqi@0: /** aoqi@0: * The factory to retrieve the required writers from. aoqi@0: */ aoqi@0: private final WriterFactory writerFactory; aoqi@0: aoqi@0: private final AbstractBuilder.Context context; aoqi@0: aoqi@0: /** aoqi@0: * Construct a builder factory using the given configuration. aoqi@0: * @param configuration the configuration for the current doclet aoqi@0: * being executed. aoqi@0: */ aoqi@0: public BuilderFactory (Configuration configuration) { aoqi@0: this.configuration = configuration; aoqi@0: this.writerFactory = configuration.getWriterFactory(); aoqi@0: aoqi@0: Set containingPackagesSeen = new HashSet(); aoqi@0: context = new AbstractBuilder.Context(configuration, containingPackagesSeen, aoqi@0: LayoutParser.getInstance(configuration)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the builder that builds the constant summary. aoqi@0: * @return the builder that builds the constant summary. aoqi@0: */ aoqi@0: public AbstractBuilder getConstantsSummaryBuider() throws Exception { aoqi@0: return ConstantsSummaryBuilder.getInstance(context, aoqi@0: writerFactory.getConstantsSummaryWriter()); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the builder that builds the package summary. aoqi@0: * aoqi@0: * @param pkg the package being documented. aoqi@0: * @param prevPkg the previous package being documented. aoqi@0: * @param nextPkg the next package being documented. aoqi@0: * @return the builder that builds the constant summary. aoqi@0: */ aoqi@0: public AbstractBuilder getPackageSummaryBuilder(PackageDoc pkg, PackageDoc prevPkg, aoqi@0: PackageDoc nextPkg) throws Exception { aoqi@0: return PackageSummaryBuilder.getInstance(context, pkg, aoqi@0: writerFactory.getPackageSummaryWriter(pkg, prevPkg, nextPkg)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the builder that builds the profile summary. aoqi@0: * aoqi@0: * @param profile the profile being documented. aoqi@0: * @param prevProfile the previous profile being documented. aoqi@0: * @param nextProfile the next profile being documented. aoqi@0: * @return the builder that builds the profile summary. aoqi@0: */ aoqi@0: public AbstractBuilder getProfileSummaryBuilder(Profile profile, Profile prevProfile, aoqi@0: Profile nextProfile) throws Exception { aoqi@0: return ProfileSummaryBuilder.getInstance(context, profile, aoqi@0: writerFactory.getProfileSummaryWriter(profile, prevProfile, nextProfile)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the builder that builds the profile package summary. aoqi@0: * aoqi@0: * @param pkg the profile package being documented. aoqi@0: * @param prevPkg the previous profile package being documented. aoqi@0: * @param nextPkg the next profile package being documented. aoqi@0: * @param profile the profile being documented. aoqi@0: * @return the builder that builds the profile package summary. aoqi@0: */ aoqi@0: public AbstractBuilder getProfilePackageSummaryBuilder(PackageDoc pkg, PackageDoc prevPkg, aoqi@0: PackageDoc nextPkg, Profile profile) throws Exception { aoqi@0: return ProfilePackageSummaryBuilder.getInstance(context, pkg, aoqi@0: writerFactory.getProfilePackageSummaryWriter(pkg, prevPkg, nextPkg, aoqi@0: profile), profile); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the builder for the class. aoqi@0: * aoqi@0: * @param classDoc the class being documented. aoqi@0: * @param prevClass the previous class that was documented. aoqi@0: * @param nextClass the next class being documented. aoqi@0: * @param classTree the class tree. aoqi@0: * @return the writer for the class. Return null if this aoqi@0: * writer is not supported by the doclet. aoqi@0: */ aoqi@0: public AbstractBuilder getClassBuilder(ClassDoc classDoc, aoqi@0: ClassDoc prevClass, ClassDoc nextClass, ClassTree classTree) aoqi@0: throws Exception { aoqi@0: return ClassBuilder.getInstance(context, classDoc, aoqi@0: writerFactory.getClassWriter(classDoc, prevClass, nextClass, aoqi@0: classTree)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the builder for the annotation type. aoqi@0: * aoqi@0: * @param annotationType the annotation type being documented. aoqi@0: * @param prevType the previous type that was documented. aoqi@0: * @param nextType the next type being documented. aoqi@0: * @return the writer for the annotation type. Return null if this aoqi@0: * writer is not supported by the doclet. aoqi@0: */ aoqi@0: public AbstractBuilder getAnnotationTypeBuilder( aoqi@0: AnnotationTypeDoc annotationType, aoqi@0: Type prevType, Type nextType) aoqi@0: throws Exception { aoqi@0: return AnnotationTypeBuilder.getInstance(context, annotationType, aoqi@0: writerFactory.getAnnotationTypeWriter(annotationType, prevType, nextType)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the method builder for the given class. aoqi@0: * aoqi@0: * @return an instance of the method builder for the given class. aoqi@0: */ aoqi@0: public AbstractBuilder getMethodBuilder(ClassWriter classWriter) aoqi@0: throws Exception { aoqi@0: return MethodBuilder.getInstance(context, aoqi@0: classWriter.getClassDoc(), aoqi@0: writerFactory.getMethodWriter(classWriter)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the annotation type fields builder for the given aoqi@0: * class. aoqi@0: * aoqi@0: * @return an instance of the annotation type field builder for the given aoqi@0: * annotation type. aoqi@0: */ aoqi@0: public AbstractBuilder getAnnotationTypeFieldsBuilder( aoqi@0: AnnotationTypeWriter annotationTypeWriter) aoqi@0: throws Exception { aoqi@0: return AnnotationTypeFieldBuilder.getInstance(context, aoqi@0: annotationTypeWriter.getAnnotationTypeDoc(), aoqi@0: writerFactory.getAnnotationTypeFieldWriter( aoqi@0: annotationTypeWriter)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the annotation type member builder for the given aoqi@0: * class. aoqi@0: * aoqi@0: * @return an instance of the annotation type member builder for the given aoqi@0: * annotation type. aoqi@0: */ aoqi@0: public AbstractBuilder getAnnotationTypeOptionalMemberBuilder( aoqi@0: AnnotationTypeWriter annotationTypeWriter) aoqi@0: throws Exception { aoqi@0: return AnnotationTypeOptionalMemberBuilder.getInstance(context, aoqi@0: annotationTypeWriter.getAnnotationTypeDoc(), aoqi@0: writerFactory.getAnnotationTypeOptionalMemberWriter( aoqi@0: annotationTypeWriter)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the annotation type member builder for the given aoqi@0: * class. aoqi@0: * aoqi@0: * @return an instance of the annotation type member builder for the given aoqi@0: * annotation type. aoqi@0: */ aoqi@0: public AbstractBuilder getAnnotationTypeRequiredMemberBuilder( aoqi@0: AnnotationTypeWriter annotationTypeWriter) aoqi@0: throws Exception { aoqi@0: return AnnotationTypeRequiredMemberBuilder.getInstance(context, aoqi@0: annotationTypeWriter.getAnnotationTypeDoc(), aoqi@0: writerFactory.getAnnotationTypeRequiredMemberWriter( aoqi@0: annotationTypeWriter)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the enum constants builder for the given class. aoqi@0: * aoqi@0: * @return an instance of the enum constants builder for the given class. aoqi@0: */ aoqi@0: public AbstractBuilder getEnumConstantsBuilder(ClassWriter classWriter) aoqi@0: throws Exception { aoqi@0: return EnumConstantBuilder.getInstance(context, classWriter.getClassDoc(), aoqi@0: writerFactory.getEnumConstantWriter(classWriter)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the field builder for the given class. aoqi@0: * aoqi@0: * @return an instance of the field builder for the given class. aoqi@0: */ aoqi@0: public AbstractBuilder getFieldBuilder(ClassWriter classWriter) aoqi@0: throws Exception { aoqi@0: return FieldBuilder.getInstance(context, classWriter.getClassDoc(), aoqi@0: writerFactory.getFieldWriter(classWriter)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the property builder for the given class. aoqi@0: * aoqi@0: * @return an instance of the field builder for the given class. aoqi@0: */ aoqi@0: public AbstractBuilder getPropertyBuilder(ClassWriter classWriter) throws Exception { aoqi@0: final PropertyWriter propertyWriter = aoqi@0: writerFactory.getPropertyWriter(classWriter); aoqi@0: return PropertyBuilder.getInstance(context, aoqi@0: classWriter.getClassDoc(), aoqi@0: propertyWriter); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the constructor builder for the given class. aoqi@0: * aoqi@0: * @return an instance of the constructor builder for the given class. aoqi@0: */ aoqi@0: public AbstractBuilder getConstructorBuilder(ClassWriter classWriter) aoqi@0: throws Exception { aoqi@0: return ConstructorBuilder.getInstance(context, aoqi@0: classWriter.getClassDoc(), aoqi@0: writerFactory.getConstructorWriter(classWriter)); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the member summary builder for the given class. aoqi@0: * aoqi@0: * @return an instance of the member summary builder for the given class. aoqi@0: */ aoqi@0: public AbstractBuilder getMemberSummaryBuilder(ClassWriter classWriter) aoqi@0: throws Exception { aoqi@0: return MemberSummaryBuilder.getInstance(classWriter, context); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return an instance of the member summary builder for the given annotation aoqi@0: * type. aoqi@0: * aoqi@0: * @return an instance of the member summary builder for the given aoqi@0: * annotation type. aoqi@0: */ aoqi@0: public AbstractBuilder getMemberSummaryBuilder( aoqi@0: AnnotationTypeWriter annotationTypeWriter) aoqi@0: throws Exception { aoqi@0: return MemberSummaryBuilder.getInstance(annotationTypeWriter, context); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the builder that builds the serialized form. aoqi@0: * aoqi@0: * @return the builder that builds the serialized form. aoqi@0: */ aoqi@0: public AbstractBuilder getSerializedFormBuilder() aoqi@0: throws Exception { aoqi@0: return SerializedFormBuilder.getInstance(context); aoqi@0: } aoqi@0: }