src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/FieldBuilder.java

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 74
5a9172b251dd
child 184
905e151a185a
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
xdono@117 2 * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit.builders;
duke@1 27
duke@1 28 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 29 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 30 import com.sun.javadoc.*;
duke@1 31 import java.util.*;
duke@1 32 import java.lang.reflect.*;
duke@1 33
duke@1 34 /**
duke@1 35 * Builds documentation for a field.
duke@1 36 *
duke@1 37 * This code is not part of an API.
duke@1 38 * It is implementation that is subject to change.
duke@1 39 * Do not use it as an API
duke@1 40 *
duke@1 41 * @author Jamie Ho
duke@1 42 * @since 1.5
duke@1 43 */
duke@1 44 public class FieldBuilder extends AbstractMemberBuilder {
duke@1 45
duke@1 46 /**
duke@1 47 * The class whose fields are being documented.
duke@1 48 */
duke@1 49 private ClassDoc classDoc;
duke@1 50
duke@1 51 /**
duke@1 52 * The visible fields for the given class.
duke@1 53 */
duke@1 54 private VisibleMemberMap visibleMemberMap;
duke@1 55
duke@1 56 /**
duke@1 57 * The writer to output the field documentation.
duke@1 58 */
duke@1 59 private FieldWriter writer;
duke@1 60
duke@1 61 /**
duke@1 62 * The list of fields being documented.
duke@1 63 */
jjg@74 64 private List<ProgramElementDoc> fields;
duke@1 65
duke@1 66 /**
duke@1 67 * The index of the current field that is being documented at this point
duke@1 68 * in time.
duke@1 69 */
duke@1 70 private int currentFieldIndex;
duke@1 71
duke@1 72 /**
duke@1 73 * Construct a new FieldBuilder.
duke@1 74 *
duke@1 75 * @param configuration the current configuration of the
duke@1 76 * doclet.
duke@1 77 */
duke@1 78 private FieldBuilder(Configuration configuration) {
duke@1 79 super(configuration);
duke@1 80 }
duke@1 81
duke@1 82 /**
duke@1 83 * Construct a new FieldBuilder.
duke@1 84 *
duke@1 85 * @param configuration the current configuration of the doclet.
duke@1 86 * @param classDoc the class whoses members are being documented.
duke@1 87 * @param writer the doclet specific writer.
duke@1 88 */
duke@1 89 public static FieldBuilder getInstance(
duke@1 90 Configuration configuration,
duke@1 91 ClassDoc classDoc,
duke@1 92 FieldWriter writer) {
duke@1 93 FieldBuilder builder = new FieldBuilder(configuration);
duke@1 94 builder.classDoc = classDoc;
duke@1 95 builder.writer = writer;
duke@1 96 builder.visibleMemberMap =
duke@1 97 new VisibleMemberMap(
duke@1 98 classDoc,
duke@1 99 VisibleMemberMap.FIELDS,
duke@1 100 configuration.nodeprecated);
duke@1 101 builder.fields =
jjg@74 102 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers(
jjg@74 103 configuration));
duke@1 104 if (configuration.getMemberComparator() != null) {
duke@1 105 Collections.sort(
duke@1 106 builder.fields,
duke@1 107 configuration.getMemberComparator());
duke@1 108 }
duke@1 109 return builder;
duke@1 110 }
duke@1 111
duke@1 112 /**
duke@1 113 * {@inheritDoc}
duke@1 114 */
duke@1 115 public String getName() {
duke@1 116 return "FieldDetails";
duke@1 117 }
duke@1 118
duke@1 119 /**
duke@1 120 * {@inheritDoc}
duke@1 121 */
duke@1 122 public void invokeMethod(
duke@1 123 String methodName,
duke@1 124 Class[] paramClasses,
duke@1 125 Object[] params)
duke@1 126 throws Exception {
duke@1 127 if (DEBUG) {
duke@1 128 configuration.root.printError(
duke@1 129 "DEBUG: " + this.getClass().getName() + "." + methodName);
duke@1 130 }
duke@1 131 Method method = this.getClass().getMethod(methodName, paramClasses);
duke@1 132 method.invoke(this, params);
duke@1 133 }
duke@1 134
duke@1 135 /**
duke@1 136 * Returns a list of fields that will be documented for the given class.
duke@1 137 * This information can be used for doclet specific documentation
duke@1 138 * generation.
duke@1 139 *
duke@1 140 * @param classDoc the {@link ClassDoc} we want to check.
duke@1 141 * @return a list of fields that will be documented.
duke@1 142 */
duke@1 143 public List members(ClassDoc classDoc) {
duke@1 144 return visibleMemberMap.getMembersFor(classDoc);
duke@1 145 }
duke@1 146
duke@1 147 /**
duke@1 148 * Returns the visible member map for the fields of this class.
duke@1 149 *
duke@1 150 * @return the visible member map for the fields of this class.
duke@1 151 */
duke@1 152 public VisibleMemberMap getVisibleMemberMap() {
duke@1 153 return visibleMemberMap;
duke@1 154 }
duke@1 155
duke@1 156 /**
duke@1 157 * summaryOrder.size()
duke@1 158 */
duke@1 159 public boolean hasMembersToDocument() {
duke@1 160 return fields.size() > 0;
duke@1 161 }
duke@1 162
duke@1 163 /**
duke@1 164 * Build the field documentation.
duke@1 165 *
duke@1 166 * @param elements the XML elements that specify how to construct this
duke@1 167 * documentation.
duke@1 168 */
duke@1 169 public void buildFieldDoc(List elements) {
duke@1 170 if (writer == null) {
duke@1 171 return;
duke@1 172 }
duke@1 173 for (currentFieldIndex = 0;
duke@1 174 currentFieldIndex < fields.size();
duke@1 175 currentFieldIndex++) {
duke@1 176 build(elements);
duke@1 177 }
duke@1 178 }
duke@1 179
duke@1 180 /**
duke@1 181 * Build the overall header.
duke@1 182 */
duke@1 183 public void buildHeader() {
duke@1 184 writer.writeHeader(
duke@1 185 classDoc,
duke@1 186 configuration.getText("doclet.Field_Detail"));
duke@1 187 }
duke@1 188
duke@1 189 /**
duke@1 190 * Build the header for the individual field.
duke@1 191 */
duke@1 192 public void buildFieldHeader() {
duke@1 193 writer.writeFieldHeader(
duke@1 194 (FieldDoc) fields.get(currentFieldIndex),
duke@1 195 currentFieldIndex == 0);
duke@1 196 }
duke@1 197
duke@1 198 /**
duke@1 199 * Build the signature.
duke@1 200 */
duke@1 201 public void buildSignature() {
duke@1 202 writer.writeSignature((FieldDoc) fields.get(currentFieldIndex));
duke@1 203 }
duke@1 204
duke@1 205 /**
duke@1 206 * Build the deprecation information.
duke@1 207 */
duke@1 208 public void buildDeprecationInfo() {
duke@1 209 writer.writeDeprecated((FieldDoc) fields.get(currentFieldIndex));
duke@1 210 }
duke@1 211
duke@1 212 /**
duke@1 213 * Build the comments for the field. Do nothing if
duke@1 214 * {@link Configuration#nocomment} is set to true.
duke@1 215 */
duke@1 216 public void buildFieldComments() {
duke@1 217 if (!configuration.nocomment) {
duke@1 218 writer.writeComments((FieldDoc) fields.get(currentFieldIndex));
duke@1 219 }
duke@1 220 }
duke@1 221
duke@1 222 /**
duke@1 223 * Build the tag information.
duke@1 224 */
duke@1 225 public void buildTagInfo() {
duke@1 226 writer.writeTags((FieldDoc) fields.get(currentFieldIndex));
duke@1 227 }
duke@1 228
duke@1 229 /**
duke@1 230 * Build the footer for the individual field.
duke@1 231 */
duke@1 232 public void buildFieldFooter() {
duke@1 233 writer.writeFieldFooter();
duke@1 234 }
duke@1 235
duke@1 236 /**
duke@1 237 * Build the overall footer.
duke@1 238 */
duke@1 239 public void buildFooter() {
duke@1 240 writer.writeFooter(classDoc);
duke@1 241 }
duke@1 242
duke@1 243 /**
duke@1 244 * Return the field writer for this builder.
duke@1 245 *
duke@1 246 * @return the field writer for this builder.
duke@1 247 */
duke@1 248 public FieldWriter getWriter() {
duke@1 249 return writer;
duke@1 250 }
duke@1 251 }

mercurial