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.formats.html; 027 028import javax.lang.model.element.Element; 029import javax.lang.model.element.ModuleElement; 030import javax.lang.model.element.PackageElement; 031import javax.lang.model.element.TypeElement; 032 033import org.jdrupes.mdoclet.internal.doclets.toolkit.ClassWriter; 034import org.jdrupes.mdoclet.internal.doclets.toolkit.ConstantsSummaryWriter; 035import org.jdrupes.mdoclet.internal.doclets.toolkit.DocFilesHandler; 036import org.jdrupes.mdoclet.internal.doclets.toolkit.MemberSummaryWriter; 037import org.jdrupes.mdoclet.internal.doclets.toolkit.ModuleSummaryWriter; 038import org.jdrupes.mdoclet.internal.doclets.toolkit.PackageSummaryWriter; 039import org.jdrupes.mdoclet.internal.doclets.toolkit.SerializedFormWriter; 040import org.jdrupes.mdoclet.internal.doclets.toolkit.WriterFactory; 041import org.jdrupes.mdoclet.internal.doclets.toolkit.util.ClassTree; 042import org.jdrupes.mdoclet.internal.doclets.toolkit.util.VisibleMemberTable; 043 044/** 045 * The factory that returns HTML writers. 046 */ 047public class WriterFactoryImpl implements WriterFactory { 048 049 private final HtmlConfiguration configuration; 050 051 public WriterFactoryImpl(HtmlConfiguration configuration) { 052 this.configuration = configuration; 053 } 054 055 @Override 056 public ConstantsSummaryWriter getConstantsSummaryWriter() { 057 return new ConstantsSummaryWriterImpl(configuration); 058 } 059 060 @Override 061 public PackageSummaryWriter 062 getPackageSummaryWriter(PackageElement packageElement) { 063 return new PackageWriterImpl(configuration, packageElement); 064 } 065 066 @Override 067 public ModuleSummaryWriter getModuleSummaryWriter(ModuleElement mdle) { 068 return new ModuleWriterImpl(configuration, mdle); 069 } 070 071 @Override 072 public ClassWriter getClassWriter(TypeElement typeElement, 073 ClassTree classTree) { 074 return new ClassWriterImpl(configuration, typeElement, classTree); 075 } 076 077 @Override 078 public AnnotationTypeMemberWriterImpl getAnnotationTypeMemberWriter( 079 ClassWriter classWriter) { 080 TypeElement te = classWriter.getTypeElement(); 081 return new AnnotationTypeMemberWriterImpl( 082 (ClassWriterImpl) classWriter, te, 083 AnnotationTypeMemberWriterImpl.Kind.ANY); 084 } 085 086 @Override 087 public AnnotationTypeMemberWriterImpl getAnnotationTypeOptionalMemberWriter( 088 ClassWriter classWriter) { 089 TypeElement te = classWriter.getTypeElement(); 090 return new AnnotationTypeMemberWriterImpl( 091 (ClassWriterImpl) classWriter, te, 092 AnnotationTypeMemberWriterImpl.Kind.OPTIONAL); 093 } 094 095 @Override 096 public AnnotationTypeMemberWriterImpl getAnnotationTypeRequiredMemberWriter( 097 ClassWriter classWriter) { 098 TypeElement te = classWriter.getTypeElement(); 099 return new AnnotationTypeMemberWriterImpl( 100 (ClassWriterImpl) classWriter, te, 101 AnnotationTypeMemberWriterImpl.Kind.REQUIRED); 102 } 103 104 @Override 105 public EnumConstantWriterImpl 106 getEnumConstantWriter(ClassWriter classWriter) { 107 return new EnumConstantWriterImpl((ClassWriterImpl) classWriter, 108 classWriter.getTypeElement()); 109 } 110 111 @Override 112 public FieldWriterImpl getFieldWriter(ClassWriter classWriter) { 113 return new FieldWriterImpl((ClassWriterImpl) classWriter, 114 classWriter.getTypeElement()); 115 } 116 117 @Override 118 public PropertyWriterImpl getPropertyWriter(ClassWriter classWriter) { 119 return new PropertyWriterImpl((ClassWriterImpl) classWriter, 120 classWriter.getTypeElement()); 121 } 122 123 @Override 124 public MethodWriterImpl getMethodWriter(ClassWriter classWriter) { 125 return new MethodWriterImpl((ClassWriterImpl) classWriter, 126 classWriter.getTypeElement()); 127 } 128 129 @Override 130 public ConstructorWriterImpl getConstructorWriter(ClassWriter classWriter) { 131 return new ConstructorWriterImpl((ClassWriterImpl) classWriter, 132 classWriter.getTypeElement()); 133 } 134 135 @Override 136 public MemberSummaryWriter getMemberSummaryWriter(ClassWriter classWriter, 137 VisibleMemberTable.Kind memberType) { 138 switch (memberType) { 139 case CONSTRUCTORS: 140 return getConstructorWriter(classWriter); 141 case ENUM_CONSTANTS: 142 return getEnumConstantWriter(classWriter); 143 case ANNOTATION_TYPE_MEMBER_OPTIONAL: 144 return getAnnotationTypeOptionalMemberWriter(classWriter); 145 case ANNOTATION_TYPE_MEMBER_REQUIRED: 146 return getAnnotationTypeRequiredMemberWriter(classWriter); 147 case FIELDS: 148 return getFieldWriter(classWriter); 149 case PROPERTIES: 150 return getPropertyWriter(classWriter); 151 case NESTED_CLASSES: 152 return new NestedClassWriterImpl( 153 (SubWriterHolderWriter) classWriter, 154 classWriter.getTypeElement()); 155 case METHODS: 156 return getMethodWriter(classWriter); 157 default: 158 return null; 159 } 160 } 161 162 @Override 163 public SerializedFormWriter getSerializedFormWriter() { 164 return new SerializedFormWriterImpl(configuration); 165 } 166 167 @Override 168 public DocFilesHandler getDocFilesHandler(Element element) { 169 return new DocFilesHandlerImpl(configuration, element); 170 } 171}