duke@1: /* duke@1: * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. Sun designates this duke@1: * particular file as subject to the "Classpath" exception as provided duke@1: * by Sun in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.internal.toolkit.builders; duke@1: duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.javadoc.*; duke@1: import java.util.*; duke@1: import java.lang.reflect.*; duke@1: /** duke@1: * Builds documentation for a method. duke@1: * duke@1: * This code is not part of an API. duke@1: * It is implementation that is subject to change. duke@1: * Do not use it as an API duke@1: * duke@1: * @author Jamie Ho duke@1: * @since 1.5 duke@1: */ duke@1: public class MethodBuilder extends AbstractMemberBuilder { duke@1: duke@1: /** duke@1: * The index of the current field that is being documented at this point duke@1: * in time. duke@1: */ duke@1: private int currentMethodIndex; duke@1: duke@1: /** duke@1: * The class whose methods are being documented. duke@1: */ duke@1: private ClassDoc classDoc; duke@1: duke@1: /** duke@1: * The visible methods for the given class. duke@1: */ duke@1: private VisibleMemberMap visibleMemberMap; duke@1: duke@1: /** duke@1: * The writer to output the method documentation. duke@1: */ duke@1: private MethodWriter writer; duke@1: duke@1: /** duke@1: * The methods being documented. duke@1: */ duke@1: private List methods; duke@1: duke@1: private MethodBuilder(Configuration configuration) { duke@1: super(configuration); duke@1: } duke@1: duke@1: /** duke@1: * Construct a new MethodBuilder. duke@1: * duke@1: * @param configuration the current configuration of the doclet. duke@1: * @param classDoc the class whoses members are being documented. duke@1: * @param writer the doclet specific writer. duke@1: * duke@1: * @return an instance of a MethodBuilder. duke@1: */ duke@1: public static MethodBuilder getInstance( duke@1: Configuration configuration, duke@1: ClassDoc classDoc, duke@1: MethodWriter writer) { duke@1: MethodBuilder builder = new MethodBuilder(configuration); duke@1: builder.classDoc = classDoc; duke@1: builder.writer = writer; duke@1: builder.visibleMemberMap = duke@1: new VisibleMemberMap( duke@1: classDoc, duke@1: VisibleMemberMap.METHODS, duke@1: configuration.nodeprecated); duke@1: builder.methods = duke@1: new ArrayList(builder.visibleMemberMap.getLeafClassMembers( duke@1: configuration)); duke@1: if (configuration.getMemberComparator() != null) { duke@1: Collections.sort( duke@1: builder.methods, duke@1: configuration.getMemberComparator()); duke@1: } duke@1: return builder; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public String getName() { duke@1: return "MethodDetails"; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public void invokeMethod( duke@1: String methodName, duke@1: Class[] paramClasses, duke@1: Object[] params) duke@1: throws Exception { duke@1: if (DEBUG) { duke@1: configuration.root.printError( duke@1: "DEBUG: " + this.getClass().getName() + "." + methodName); duke@1: } duke@1: Method method = this.getClass().getMethod(methodName, paramClasses); duke@1: method.invoke(this, params); duke@1: } duke@1: duke@1: /** duke@1: * Returns a list of methods that will be documented for the given class. duke@1: * This information can be used for doclet specific documentation duke@1: * generation. duke@1: * duke@1: * @param classDoc the {@link ClassDoc} we want to check. duke@1: * @return a list of methods that will be documented. duke@1: */ duke@1: public List members(ClassDoc classDoc) { duke@1: return visibleMemberMap.getMembersFor(classDoc); duke@1: } duke@1: duke@1: /** duke@1: * Returns the visible member map for the methods of this class. duke@1: * duke@1: * @return the visible member map for the methods of this class. duke@1: */ duke@1: public VisibleMemberMap getVisibleMemberMap() { duke@1: return visibleMemberMap; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public boolean hasMembersToDocument() { duke@1: return methods.size() > 0; duke@1: } duke@1: duke@1: /** duke@1: * Build the method documentation. duke@1: */ duke@1: public void buildMethodDoc(List elements) { duke@1: if (writer == null) { duke@1: return; duke@1: } duke@1: for (currentMethodIndex = 0; duke@1: currentMethodIndex < methods.size(); duke@1: currentMethodIndex++) { duke@1: build(elements); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Build the overall header. duke@1: */ duke@1: public void buildHeader() { duke@1: writer.writeHeader( duke@1: classDoc, duke@1: configuration.getText("doclet.Method_Detail")); duke@1: } duke@1: duke@1: /** duke@1: * Build the header for the individual method. duke@1: */ duke@1: public void buildMethodHeader() { duke@1: writer.writeMethodHeader( duke@1: (MethodDoc) methods.get(currentMethodIndex), duke@1: currentMethodIndex == 0); duke@1: } duke@1: duke@1: /** duke@1: * Build the signature. duke@1: */ duke@1: public void buildSignature() { duke@1: writer.writeSignature((MethodDoc) methods.get(currentMethodIndex)); duke@1: } duke@1: duke@1: /** duke@1: * Build the deprecation information. duke@1: */ duke@1: public void buildDeprecationInfo() { duke@1: writer.writeDeprecated((MethodDoc) methods.get(currentMethodIndex)); duke@1: } duke@1: duke@1: /** duke@1: * Build the comments for the method. Do nothing if duke@1: * {@link Configuration#nocomment} is set to true. If this method duke@1: */ duke@1: public void buildMethodComments() { duke@1: if (!configuration.nocomment) { duke@1: MethodDoc method = (MethodDoc) methods.get(currentMethodIndex); duke@1: duke@1: if (method.inlineTags().length == 0) { duke@1: DocFinder.Output docs = DocFinder.search( duke@1: new DocFinder.Input(method)); duke@1: method = docs.inlineTags != null && docs.inlineTags.length > 0 ? duke@1: (MethodDoc) docs.holder : method; duke@1: duke@1: } duke@1: //NOTE: When we fix the bug where ClassDoc.interfaceTypes() does duke@1: // not pass all implemented interfaces, holder will be the duke@1: // interface type. For now, it is really the erasure. duke@1: writer.writeComments(method.containingClass(), method); duke@1: } duke@1: } duke@1: duke@1: duke@1: duke@1: /** duke@1: * Build the tag information. duke@1: */ duke@1: public void buildTagInfo() { duke@1: writer.writeTags((MethodDoc) methods.get(currentMethodIndex)); duke@1: } duke@1: duke@1: /** duke@1: * Build the footer of the method. duke@1: */ duke@1: public void buildMethodFooter() { duke@1: writer.writeMethodFooter(); duke@1: } duke@1: duke@1: /** duke@1: * Build the overall footer. duke@1: */ duke@1: public void buildFooter() { duke@1: writer.writeFooter(classDoc); duke@1: } duke@1: duke@1: /** duke@1: * Return the method writer for this builder. duke@1: * duke@1: * @return the method writer for this builder. duke@1: */ duke@1: public MethodWriter getWriter() { duke@1: return writer; duke@1: } duke@1: }