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