src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/MethodBuilder.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 * Builds documentation for a method.
duke@1 35 *
duke@1 36 * This code is not part of an API.
duke@1 37 * It is implementation that is subject to change.
duke@1 38 * Do not use it as an API
duke@1 39 *
duke@1 40 * @author Jamie Ho
duke@1 41 * @since 1.5
duke@1 42 */
duke@1 43 public class MethodBuilder extends AbstractMemberBuilder {
duke@1 44
duke@1 45 /**
duke@1 46 * The index of the current field that is being documented at this point
duke@1 47 * in time.
duke@1 48 */
duke@1 49 private int currentMethodIndex;
duke@1 50
duke@1 51 /**
duke@1 52 * The class whose methods are being documented.
duke@1 53 */
duke@1 54 private ClassDoc classDoc;
duke@1 55
duke@1 56 /**
duke@1 57 * The visible methods for the given class.
duke@1 58 */
duke@1 59 private VisibleMemberMap visibleMemberMap;
duke@1 60
duke@1 61 /**
duke@1 62 * The writer to output the method documentation.
duke@1 63 */
duke@1 64 private MethodWriter writer;
duke@1 65
duke@1 66 /**
duke@1 67 * The methods being documented.
duke@1 68 */
jjg@74 69 private List<ProgramElementDoc> methods;
duke@1 70
duke@1 71 private MethodBuilder(Configuration configuration) {
duke@1 72 super(configuration);
duke@1 73 }
duke@1 74
duke@1 75 /**
duke@1 76 * Construct a new MethodBuilder.
duke@1 77 *
duke@1 78 * @param configuration the current configuration of the doclet.
duke@1 79 * @param classDoc the class whoses members are being documented.
duke@1 80 * @param writer the doclet specific writer.
duke@1 81 *
duke@1 82 * @return an instance of a MethodBuilder.
duke@1 83 */
duke@1 84 public static MethodBuilder getInstance(
duke@1 85 Configuration configuration,
duke@1 86 ClassDoc classDoc,
duke@1 87 MethodWriter writer) {
duke@1 88 MethodBuilder builder = new MethodBuilder(configuration);
duke@1 89 builder.classDoc = classDoc;
duke@1 90 builder.writer = writer;
duke@1 91 builder.visibleMemberMap =
duke@1 92 new VisibleMemberMap(
duke@1 93 classDoc,
duke@1 94 VisibleMemberMap.METHODS,
duke@1 95 configuration.nodeprecated);
duke@1 96 builder.methods =
jjg@74 97 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers(
duke@1 98 configuration));
duke@1 99 if (configuration.getMemberComparator() != null) {
duke@1 100 Collections.sort(
duke@1 101 builder.methods,
duke@1 102 configuration.getMemberComparator());
duke@1 103 }
duke@1 104 return builder;
duke@1 105 }
duke@1 106
duke@1 107 /**
duke@1 108 * {@inheritDoc}
duke@1 109 */
duke@1 110 public String getName() {
duke@1 111 return "MethodDetails";
duke@1 112 }
duke@1 113
duke@1 114 /**
duke@1 115 * {@inheritDoc}
duke@1 116 */
duke@1 117 public void invokeMethod(
duke@1 118 String methodName,
duke@1 119 Class[] paramClasses,
duke@1 120 Object[] params)
duke@1 121 throws Exception {
duke@1 122 if (DEBUG) {
duke@1 123 configuration.root.printError(
duke@1 124 "DEBUG: " + this.getClass().getName() + "." + methodName);
duke@1 125 }
duke@1 126 Method method = this.getClass().getMethod(methodName, paramClasses);
duke@1 127 method.invoke(this, params);
duke@1 128 }
duke@1 129
duke@1 130 /**
duke@1 131 * Returns a list of methods that will be documented for the given class.
duke@1 132 * This information can be used for doclet specific documentation
duke@1 133 * generation.
duke@1 134 *
duke@1 135 * @param classDoc the {@link ClassDoc} we want to check.
duke@1 136 * @return a list of methods that will be documented.
duke@1 137 */
duke@1 138 public List members(ClassDoc classDoc) {
duke@1 139 return visibleMemberMap.getMembersFor(classDoc);
duke@1 140 }
duke@1 141
duke@1 142 /**
duke@1 143 * Returns the visible member map for the methods of this class.
duke@1 144 *
duke@1 145 * @return the visible member map for the methods of this class.
duke@1 146 */
duke@1 147 public VisibleMemberMap getVisibleMemberMap() {
duke@1 148 return visibleMemberMap;
duke@1 149 }
duke@1 150
duke@1 151 /**
duke@1 152 * {@inheritDoc}
duke@1 153 */
duke@1 154 public boolean hasMembersToDocument() {
duke@1 155 return methods.size() > 0;
duke@1 156 }
duke@1 157
duke@1 158 /**
duke@1 159 * Build the method documentation.
duke@1 160 */
duke@1 161 public void buildMethodDoc(List elements) {
duke@1 162 if (writer == null) {
duke@1 163 return;
duke@1 164 }
duke@1 165 for (currentMethodIndex = 0;
duke@1 166 currentMethodIndex < methods.size();
duke@1 167 currentMethodIndex++) {
duke@1 168 build(elements);
duke@1 169 }
duke@1 170 }
duke@1 171
duke@1 172 /**
duke@1 173 * Build the overall header.
duke@1 174 */
duke@1 175 public void buildHeader() {
duke@1 176 writer.writeHeader(
duke@1 177 classDoc,
duke@1 178 configuration.getText("doclet.Method_Detail"));
duke@1 179 }
duke@1 180
duke@1 181 /**
duke@1 182 * Build the header for the individual method.
duke@1 183 */
duke@1 184 public void buildMethodHeader() {
duke@1 185 writer.writeMethodHeader(
duke@1 186 (MethodDoc) methods.get(currentMethodIndex),
duke@1 187 currentMethodIndex == 0);
duke@1 188 }
duke@1 189
duke@1 190 /**
duke@1 191 * Build the signature.
duke@1 192 */
duke@1 193 public void buildSignature() {
duke@1 194 writer.writeSignature((MethodDoc) methods.get(currentMethodIndex));
duke@1 195 }
duke@1 196
duke@1 197 /**
duke@1 198 * Build the deprecation information.
duke@1 199 */
duke@1 200 public void buildDeprecationInfo() {
duke@1 201 writer.writeDeprecated((MethodDoc) methods.get(currentMethodIndex));
duke@1 202 }
duke@1 203
duke@1 204 /**
duke@1 205 * Build the comments for the method. Do nothing if
duke@1 206 * {@link Configuration#nocomment} is set to true. If this method
duke@1 207 */
duke@1 208 public void buildMethodComments() {
duke@1 209 if (!configuration.nocomment) {
duke@1 210 MethodDoc method = (MethodDoc) methods.get(currentMethodIndex);
duke@1 211
duke@1 212 if (method.inlineTags().length == 0) {
duke@1 213 DocFinder.Output docs = DocFinder.search(
duke@1 214 new DocFinder.Input(method));
duke@1 215 method = docs.inlineTags != null && docs.inlineTags.length > 0 ?
duke@1 216 (MethodDoc) docs.holder : method;
duke@1 217
duke@1 218 }
duke@1 219 //NOTE: When we fix the bug where ClassDoc.interfaceTypes() does
duke@1 220 // not pass all implemented interfaces, holder will be the
duke@1 221 // interface type. For now, it is really the erasure.
duke@1 222 writer.writeComments(method.containingClass(), method);
duke@1 223 }
duke@1 224 }
duke@1 225
duke@1 226
duke@1 227
duke@1 228 /**
duke@1 229 * Build the tag information.
duke@1 230 */
duke@1 231 public void buildTagInfo() {
duke@1 232 writer.writeTags((MethodDoc) methods.get(currentMethodIndex));
duke@1 233 }
duke@1 234
duke@1 235 /**
duke@1 236 * Build the footer of the method.
duke@1 237 */
duke@1 238 public void buildMethodFooter() {
duke@1 239 writer.writeMethodFooter();
duke@1 240 }
duke@1 241
duke@1 242 /**
duke@1 243 * Build the overall footer.
duke@1 244 */
duke@1 245 public void buildFooter() {
duke@1 246 writer.writeFooter(classDoc);
duke@1 247 }
duke@1 248
duke@1 249 /**
duke@1 250 * Return the method writer for this builder.
duke@1 251 *
duke@1 252 * @return the method writer for this builder.
duke@1 253 */
duke@1 254 public MethodWriter getWriter() {
duke@1 255 return writer;
duke@1 256 }
duke@1 257 }

mercurial