aoqi@0: /* aoqi@0: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.doclets.internal.toolkit.builders; aoqi@0: aoqi@0: import java.util.*; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*; aoqi@0: aoqi@0: /** aoqi@0: * Builds documentation for a method. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @author Jamie Ho aoqi@0: * @author Bhavesh Patel (Modified) aoqi@0: * @since 1.5 aoqi@0: */ aoqi@0: public class MethodBuilder extends AbstractMemberBuilder { aoqi@0: aoqi@0: /** aoqi@0: * The index of the current field that is being documented at this point aoqi@0: * in time. aoqi@0: */ aoqi@0: private int currentMethodIndex; aoqi@0: aoqi@0: /** aoqi@0: * The class whose methods are being documented. aoqi@0: */ aoqi@0: private final ClassDoc classDoc; aoqi@0: aoqi@0: /** aoqi@0: * The visible methods for the given class. aoqi@0: */ aoqi@0: private final VisibleMemberMap visibleMemberMap; aoqi@0: aoqi@0: /** aoqi@0: * The writer to output the method documentation. aoqi@0: */ aoqi@0: private final MethodWriter writer; aoqi@0: aoqi@0: /** aoqi@0: * The methods being documented. aoqi@0: */ aoqi@0: private List methods; aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Construct a new MethodBuilder. aoqi@0: * aoqi@0: * @param context the build context. aoqi@0: * @param classDoc the class whoses members are being documented. aoqi@0: * @param writer the doclet specific writer. aoqi@0: */ aoqi@0: private MethodBuilder(Context context, aoqi@0: ClassDoc classDoc, aoqi@0: MethodWriter writer) { aoqi@0: super(context); aoqi@0: this.classDoc = classDoc; aoqi@0: this.writer = writer; aoqi@0: visibleMemberMap = new VisibleMemberMap( aoqi@0: classDoc, aoqi@0: VisibleMemberMap.METHODS, aoqi@0: configuration); aoqi@0: methods = aoqi@0: new ArrayList(visibleMemberMap.getLeafClassMembers( aoqi@0: configuration)); aoqi@0: if (configuration.getMemberComparator() != null) { aoqi@0: Collections.sort(methods, configuration.getMemberComparator()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Construct a new MethodBuilder. aoqi@0: * aoqi@0: * @param context the build context. aoqi@0: * @param classDoc the class whoses members are being documented. aoqi@0: * @param writer the doclet specific writer. aoqi@0: * aoqi@0: * @return an instance of a MethodBuilder. aoqi@0: */ aoqi@0: public static MethodBuilder getInstance(Context context, aoqi@0: ClassDoc classDoc, MethodWriter writer) { aoqi@0: return new MethodBuilder(context, classDoc, writer); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public String getName() { aoqi@0: return "MethodDetails"; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns a list of methods that will be documented for the given class. aoqi@0: * This information can be used for doclet specific documentation aoqi@0: * generation. aoqi@0: * aoqi@0: * @param classDoc the {@link ClassDoc} we want to check. aoqi@0: * @return a list of methods that will be documented. aoqi@0: */ aoqi@0: public List members(ClassDoc classDoc) { aoqi@0: return visibleMemberMap.getMembersFor(classDoc); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Returns the visible member map for the methods of this class. aoqi@0: * aoqi@0: * @return the visible member map for the methods of this class. aoqi@0: */ aoqi@0: public VisibleMemberMap getVisibleMemberMap() { aoqi@0: return visibleMemberMap; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * {@inheritDoc} aoqi@0: */ aoqi@0: public boolean hasMembersToDocument() { aoqi@0: return methods.size() > 0; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the method documentation. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param memberDetailsTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildMethodDoc(XMLNode node, Content memberDetailsTree) { aoqi@0: if (writer == null) { aoqi@0: return; aoqi@0: } aoqi@0: int size = methods.size(); aoqi@0: if (size > 0) { aoqi@0: Content methodDetailsTree = writer.getMethodDetailsTreeHeader( aoqi@0: classDoc, memberDetailsTree); aoqi@0: for (currentMethodIndex = 0; currentMethodIndex < size; aoqi@0: currentMethodIndex++) { aoqi@0: Content methodDocTree = writer.getMethodDocTreeHeader( aoqi@0: (MethodDoc) methods.get(currentMethodIndex), aoqi@0: methodDetailsTree); aoqi@0: buildChildren(node, methodDocTree); aoqi@0: methodDetailsTree.addContent(writer.getMethodDoc( aoqi@0: methodDocTree, (currentMethodIndex == size - 1))); aoqi@0: } aoqi@0: memberDetailsTree.addContent( aoqi@0: writer.getMethodDetails(methodDetailsTree)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the signature. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param methodDocTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildSignature(XMLNode node, Content methodDocTree) { aoqi@0: methodDocTree.addContent( aoqi@0: writer.getSignature((MethodDoc) methods.get(currentMethodIndex))); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the deprecation information. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param methodDocTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildDeprecationInfo(XMLNode node, Content methodDocTree) { aoqi@0: writer.addDeprecated( aoqi@0: (MethodDoc) methods.get(currentMethodIndex), methodDocTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the comments for the method. Do nothing if aoqi@0: * {@link Configuration#nocomment} is set to true. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param methodDocTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildMethodComments(XMLNode node, Content methodDocTree) { aoqi@0: if (!configuration.nocomment) { aoqi@0: MethodDoc method = (MethodDoc) methods.get(currentMethodIndex); aoqi@0: aoqi@0: if (method.inlineTags().length == 0) { aoqi@0: DocFinder.Output docs = DocFinder.search( aoqi@0: new DocFinder.Input(method)); aoqi@0: method = docs.inlineTags != null && docs.inlineTags.length > 0 ? aoqi@0: (MethodDoc) docs.holder : method; aoqi@0: } aoqi@0: //NOTE: When we fix the bug where ClassDoc.interfaceTypes() does aoqi@0: // not pass all implemented interfaces, holder will be the aoqi@0: // interface type. For now, it is really the erasure. aoqi@0: writer.addComments(method.containingClass(), method, methodDocTree); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Build the tag information. aoqi@0: * aoqi@0: * @param node the XML element that specifies which components to document aoqi@0: * @param methodDocTree the content tree to which the documentation will be added aoqi@0: */ aoqi@0: public void buildTagInfo(XMLNode node, Content methodDocTree) { aoqi@0: writer.addTags((MethodDoc) methods.get(currentMethodIndex), aoqi@0: methodDocTree); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Return the method writer for this builder. aoqi@0: * aoqi@0: * @return the method writer for this builder. aoqi@0: */ aoqi@0: public MethodWriter getWriter() { aoqi@0: return writer; aoqi@0: } aoqi@0: }