src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/WriterFactoryImpl.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2013, 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 com.sun.tools.doclets.formats.html;
  27 
  28 import java.io.IOException;
  29 
  30 import com.sun.javadoc.*;
  31 import com.sun.tools.javac.jvm.Profile;
  32 import com.sun.tools.doclets.internal.toolkit.*;
  33 import com.sun.tools.doclets.internal.toolkit.util.*;
  34 















  35 /**
  36  * The factory that returns HTML writers.
  37  *
  38  *  <p><b>This is NOT part of any supported API.
  39  *  If you write code that depends on this, you do so at your own risk.
  40  *  This code and its internal interfaces are subject to change or
  41  *  deletion without notice.</b>
  42  *
  43  * @author Jamie Ho
  44  * @since 1.5
  45  */
  46 public class WriterFactoryImpl implements WriterFactory {
  47 
  48     private final ConfigurationImpl configuration;
  49 
  50     public WriterFactoryImpl(ConfigurationImpl configuration) {
  51         this.configuration = configuration;
  52     }
  53 
  54     /**
  55      * {@inheritDoc}
  56      */

  57     public ConstantsSummaryWriter getConstantsSummaryWriter() throws Exception {
  58         return new ConstantsSummaryWriterImpl(configuration);
  59     }
  60 
  61     /**
  62      * {@inheritDoc}
  63      */
  64     public PackageSummaryWriter getPackageSummaryWriter(PackageDoc packageDoc,
  65         PackageDoc prevPkg, PackageDoc nextPkg) throws Exception {
  66         return new PackageWriterImpl(configuration, packageDoc,
  67             prevPkg, nextPkg);
  68     }
  69 
  70     /**
  71      * {@inheritDoc}
  72      */
  73     public ProfileSummaryWriter getProfileSummaryWriter(Profile profile,
  74         Profile prevProfile, Profile nextProfile) throws Exception {
  75         return new ProfileWriterImpl(configuration, profile,
  76             prevProfile, nextProfile);
  77     }
  78 
  79     /**
  80      * {@inheritDoc}
  81      */
  82     public ProfilePackageSummaryWriter getProfilePackageSummaryWriter(PackageDoc packageDoc,
  83         PackageDoc prevPkg, PackageDoc nextPkg, Profile profile) throws Exception {
  84         return new ProfilePackageWriterImpl(configuration, packageDoc,
  85             prevPkg, nextPkg, profile);
  86     }
  87 
  88     /**
  89      * {@inheritDoc}
  90      */
  91     public ClassWriter getClassWriter(ClassDoc classDoc, ClassDoc prevClass,
  92             ClassDoc nextClass, ClassTree classTree) throws IOException {
  93         return new ClassWriterImpl(configuration, classDoc,
  94                 prevClass, nextClass, classTree);
  95     }
  96 
  97     /**
  98      * {@inheritDoc}
  99      */
 100     public AnnotationTypeWriter getAnnotationTypeWriter(
 101         AnnotationTypeDoc annotationType, Type prevType, Type nextType)
 102     throws Exception {
 103         return new AnnotationTypeWriterImpl(configuration,
 104                 annotationType, prevType, nextType);
 105     }
 106 
 107     /**
 108      * {@inheritDoc}
 109      */
 110     public AnnotationTypeFieldWriter
 111             getAnnotationTypeFieldWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception {

 112         return new AnnotationTypeFieldWriterImpl(
 113             (SubWriterHolderWriter) annotationTypeWriter,
 114             annotationTypeWriter.getAnnotationTypeDoc());
 115     }
 116 
 117     /**
 118      * {@inheritDoc}
 119      */

 120     public AnnotationTypeOptionalMemberWriter
 121             getAnnotationTypeOptionalMemberWriter(
 122         AnnotationTypeWriter annotationTypeWriter) throws Exception {

 123         return new AnnotationTypeOptionalMemberWriterImpl(
 124             (SubWriterHolderWriter) annotationTypeWriter,
 125             annotationTypeWriter.getAnnotationTypeDoc());
 126     }
 127 
 128     /**
 129      * {@inheritDoc}
 130      */

 131     public AnnotationTypeRequiredMemberWriter
 132             getAnnotationTypeRequiredMemberWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception {

 133         return new AnnotationTypeRequiredMemberWriterImpl(
 134             (SubWriterHolderWriter) annotationTypeWriter,
 135             annotationTypeWriter.getAnnotationTypeDoc());
 136     }
 137 
 138     /**
 139      * {@inheritDoc}
 140      */

 141     public EnumConstantWriterImpl getEnumConstantWriter(ClassWriter classWriter)
 142             throws Exception {
 143         return new EnumConstantWriterImpl((SubWriterHolderWriter) classWriter,
 144             classWriter.getClassDoc());
 145     }
 146 
 147     /**
 148      * {@inheritDoc}
 149      */

 150     public FieldWriterImpl getFieldWriter(ClassWriter classWriter)
 151             throws Exception {
 152         return new FieldWriterImpl((SubWriterHolderWriter) classWriter,
 153             classWriter.getClassDoc());
 154     }
 155 
 156     /**
 157      * {@inheritDoc}
 158      */

 159     public PropertyWriterImpl getPropertyWriter(ClassWriter classWriter)
 160             throws Exception {
 161         return new PropertyWriterImpl((SubWriterHolderWriter) classWriter,
 162             classWriter.getClassDoc());
 163     }
 164 
 165     /**
 166      * {@inheritDoc}
 167      */

 168     public MethodWriterImpl getMethodWriter(ClassWriter classWriter)
 169             throws Exception {
 170         return new MethodWriterImpl((SubWriterHolderWriter) classWriter,
 171             classWriter.getClassDoc());
 172     }
 173 
 174     /**
 175      * {@inheritDoc}
 176      */

 177     public ConstructorWriterImpl getConstructorWriter(ClassWriter classWriter)
 178             throws Exception {
 179         return new ConstructorWriterImpl((SubWriterHolderWriter) classWriter,
 180             classWriter.getClassDoc());
 181     }
 182 
 183     /**
 184      * {@inheritDoc}
 185      */

 186     public MemberSummaryWriter getMemberSummaryWriter(
 187             ClassWriter classWriter, int memberType)
 188             throws Exception {
 189         switch (memberType) {
 190             case VisibleMemberMap.CONSTRUCTORS:
 191                 return getConstructorWriter(classWriter);
 192             case VisibleMemberMap.ENUM_CONSTANTS:
 193                 return getEnumConstantWriter(classWriter);
 194             case VisibleMemberMap.FIELDS:
 195                 return getFieldWriter(classWriter);
 196             case VisibleMemberMap.PROPERTIES:
 197                 return getPropertyWriter(classWriter);
 198             case VisibleMemberMap.INNERCLASSES:
 199                 return new NestedClassWriterImpl((SubWriterHolderWriter)
 200                     classWriter, classWriter.getClassDoc());
 201             case VisibleMemberMap.METHODS:
 202                 return getMethodWriter(classWriter);
 203             default:
 204                 return null;
 205         }
 206     }
 207 
 208     /**
 209      * {@inheritDoc}
 210      */

 211     public MemberSummaryWriter getMemberSummaryWriter(
 212         AnnotationTypeWriter annotationTypeWriter, int memberType)
 213     throws Exception {
 214         switch (memberType) {
 215             case VisibleMemberMap.ANNOTATION_TYPE_FIELDS:
 216                 return (AnnotationTypeFieldWriterImpl)
 217                     getAnnotationTypeFieldWriter(annotationTypeWriter);
 218             case VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL:
 219                 return (AnnotationTypeOptionalMemberWriterImpl)
 220                     getAnnotationTypeOptionalMemberWriter(annotationTypeWriter);
 221             case VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED:
 222                 return (AnnotationTypeRequiredMemberWriterImpl)
 223                     getAnnotationTypeRequiredMemberWriter(annotationTypeWriter);
 224             default:
 225                 return null;
 226         }
 227     }
 228 
 229     /**
 230      * {@inheritDoc}
 231      */

 232     public SerializedFormWriter getSerializedFormWriter() throws Exception {
 233         return new SerializedFormWriterImpl(configuration);
 234     }
 235 }
   1 /*
   2  * Copyright (c) 2003, 2016, 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.formats.html;
  27 
  28 import java.io.IOException;
  29 
  30 import javax.lang.model.element.PackageElement;
  31 import javax.lang.model.element.TypeElement;
  32 import javax.lang.model.type.TypeMirror;

  33 
  34 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeFieldWriter;
  35 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeOptionalMemberWriter;
  36 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter;
  37 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter;
  38 import jdk.javadoc.internal.doclets.toolkit.ClassWriter;
  39 import jdk.javadoc.internal.doclets.toolkit.ConstantsSummaryWriter;
  40 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
  41 import jdk.javadoc.internal.doclets.toolkit.PackageSummaryWriter;
  42 import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter;
  43 import jdk.javadoc.internal.doclets.toolkit.WriterFactory;
  44 import jdk.javadoc.internal.doclets.toolkit.util.ClassTree;
  45 import jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap;
  46 
  47 import static jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap.Kind.*;
  48 
  49 /**
  50  * The factory that returns HTML writers.
  51  *
  52  *  <p><b>This is NOT part of any supported API.
  53  *  If you write code that depends on this, you do so at your own risk.
  54  *  This code and its internal interfaces are subject to change or
  55  *  deletion without notice.</b>
  56  *
  57  * @author Jamie Ho
  58  * @since 1.5
  59  */
  60 public class WriterFactoryImpl implements WriterFactory {
  61 
  62     private final ConfigurationImpl configuration;

  63     public WriterFactoryImpl(ConfigurationImpl configuration) {
  64         this.configuration = configuration;
  65     }
  66 
  67     /**
  68      * {@inheritDoc}
  69      */
  70     @Override
  71     public ConstantsSummaryWriter getConstantsSummaryWriter() throws Exception {
  72         return new ConstantsSummaryWriterImpl(configuration);
  73     }
  74 
  75     /**
  76      * {@inheritDoc}
  77      */
  78     @Override
  79     public PackageSummaryWriter getPackageSummaryWriter(PackageElement packageElement,
  80             PackageElement prevPkg, PackageElement nextPkg) throws Exception {
  81         return new PackageWriterImpl(configuration, packageElement, prevPkg, nextPkg);
  82     }
  83 
  84     /**
  85      * {@inheritDoc}
  86      */
  87     @Override
  88     public ClassWriter getClassWriter(TypeElement typeElement, TypeElement prevClass,
  89             TypeElement nextClass, ClassTree classTree) throws IOException {
  90         return new ClassWriterImpl(configuration, typeElement, prevClass, nextClass, classTree);
  91     }
  92 
  93     /**
  94      * {@inheritDoc}
  95      */
  96     @Override
  97     public AnnotationTypeWriter getAnnotationTypeWriter(TypeElement annotationType,
  98             TypeMirror prevType, TypeMirror nextType) throws Exception {
  99         return new AnnotationTypeWriterImpl(configuration, annotationType, prevType, nextType);
 100     }
 101 
 102     /**
 103      * {@inheritDoc}
 104      */
 105     @Override


















 106     public AnnotationTypeFieldWriter
 107             getAnnotationTypeFieldWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception {
 108         TypeElement te = annotationTypeWriter.getAnnotationTypeElement();
 109         return new AnnotationTypeFieldWriterImpl(
 110             (SubWriterHolderWriter) annotationTypeWriter, te);

 111     }
 112 
 113     /**
 114      * {@inheritDoc}
 115      */
 116     @Override
 117     public AnnotationTypeOptionalMemberWriter
 118             getAnnotationTypeOptionalMemberWriter(
 119         AnnotationTypeWriter annotationTypeWriter) throws Exception {
 120         TypeElement te = annotationTypeWriter.getAnnotationTypeElement();
 121         return new AnnotationTypeOptionalMemberWriterImpl(
 122             (SubWriterHolderWriter) annotationTypeWriter, te);

 123     }
 124 
 125     /**
 126      * {@inheritDoc}
 127      */
 128     @Override
 129     public AnnotationTypeRequiredMemberWriter
 130             getAnnotationTypeRequiredMemberWriter(AnnotationTypeWriter annotationTypeWriter) throws Exception {
 131         TypeElement te = annotationTypeWriter.getAnnotationTypeElement();
 132         return new AnnotationTypeRequiredMemberWriterImpl(
 133             (SubWriterHolderWriter) annotationTypeWriter, te);

 134     }
 135 
 136     /**
 137      * {@inheritDoc}
 138      */
 139     @Override
 140     public EnumConstantWriterImpl getEnumConstantWriter(ClassWriter classWriter)
 141             throws Exception {
 142         return new EnumConstantWriterImpl((SubWriterHolderWriter) classWriter,
 143                 classWriter.getTypeElement());
 144     }
 145 
 146     /**
 147      * {@inheritDoc}
 148      */
 149     @Override
 150     public FieldWriterImpl getFieldWriter(ClassWriter classWriter)
 151             throws Exception {
 152         return new FieldWriterImpl((SubWriterHolderWriter) classWriter, classWriter.getTypeElement());

 153     }
 154 
 155     /**
 156      * {@inheritDoc}
 157      */
 158     @Override
 159     public PropertyWriterImpl getPropertyWriter(ClassWriter classWriter)
 160             throws Exception {
 161         return new PropertyWriterImpl((SubWriterHolderWriter) classWriter,
 162                 classWriter.getTypeElement());
 163     }
 164 
 165     /**
 166      * {@inheritDoc}
 167      */
 168     @Override
 169     public MethodWriterImpl getMethodWriter(ClassWriter classWriter)
 170             throws Exception {
 171         return new MethodWriterImpl((SubWriterHolderWriter) classWriter, classWriter.getTypeElement());

 172     }
 173 
 174     /**
 175      * {@inheritDoc}
 176      */
 177     @Override
 178     public ConstructorWriterImpl getConstructorWriter(ClassWriter classWriter)
 179             throws Exception {
 180         return new ConstructorWriterImpl((SubWriterHolderWriter) classWriter,
 181                 classWriter.getTypeElement());
 182     }
 183 
 184     /**
 185      * {@inheritDoc}
 186      */
 187     @Override
 188     public MemberSummaryWriter getMemberSummaryWriter(
 189             ClassWriter classWriter, VisibleMemberMap.Kind memberType)
 190             throws Exception {
 191         switch (memberType) {
 192             case CONSTRUCTORS:
 193                 return getConstructorWriter(classWriter);
 194             case ENUM_CONSTANTS:
 195                 return getEnumConstantWriter(classWriter);
 196             case FIELDS:
 197                 return getFieldWriter(classWriter);
 198             case PROPERTIES:
 199                 return getPropertyWriter(classWriter);
 200             case INNER_CLASSES:
 201                 return new NestedClassWriterImpl((SubWriterHolderWriter)
 202                     classWriter, classWriter.getTypeElement());
 203             case METHODS:
 204                 return getMethodWriter(classWriter);
 205             default:
 206                 return null;
 207         }
 208     }
 209 
 210     /**
 211      * {@inheritDoc}
 212      */
 213     @Override
 214     public MemberSummaryWriter getMemberSummaryWriter(
 215         AnnotationTypeWriter annotationTypeWriter, VisibleMemberMap.Kind memberType)
 216     throws Exception {
 217         switch (memberType) {
 218             case ANNOTATION_TYPE_FIELDS:
 219                 return (AnnotationTypeFieldWriterImpl)
 220                     getAnnotationTypeFieldWriter(annotationTypeWriter);
 221             case ANNOTATION_TYPE_MEMBER_OPTIONAL:
 222                 return (AnnotationTypeOptionalMemberWriterImpl)
 223                     getAnnotationTypeOptionalMemberWriter(annotationTypeWriter);
 224             case ANNOTATION_TYPE_MEMBER_REQUIRED:
 225                 return (AnnotationTypeRequiredMemberWriterImpl)
 226                     getAnnotationTypeRequiredMemberWriter(annotationTypeWriter);
 227             default:
 228                 return null;
 229         }
 230     }
 231 
 232     /**
 233      * {@inheritDoc}
 234      */
 235     @Override
 236     public SerializedFormWriter getSerializedFormWriter() throws Exception {
 237         return new SerializedFormWriterImpl(configuration);
 238     }
 239 }