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

Sun, 24 Feb 2013 11:36:58 -0800

author
jjg
date
Sun, 24 Feb 2013 11:36:58 -0800
changeset 1606
ccbe7ffdd867
parent 1410
bfec2a1cc869
child 2525
2eb010b6cb22
permissions
-rw-r--r--

7112427: The doclet needs to be able to generate JavaFX documentation.
Reviewed-by: jjg
Contributed-by: jan.valenta@oracle.com

duke@1 1 /*
jjg@1606 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. 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
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle 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 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.internal.toolkit.builders;
duke@1 27
bpatel@766 28 import java.util.*;
jjg@1357 29
jjg@1357 30 import com.sun.javadoc.*;
jjg@1357 31 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 32 import com.sun.tools.doclets.internal.toolkit.util.*;
jjg@589 33
duke@1 34 /**
duke@1 35 * Builds documentation for a method.
duke@1 36 *
jjg@1359 37 * <p><b>This is NOT part of any supported API.
jjg@1359 38 * If you write code that depends on this, you do so at your own risk.
jjg@1359 39 * This code and its internal interfaces are subject to change or
jjg@1359 40 * deletion without notice.</b>
duke@1 41 *
duke@1 42 * @author Jamie Ho
bpatel@766 43 * @author Bhavesh Patel (Modified)
duke@1 44 * @since 1.5
duke@1 45 */
duke@1 46 public class MethodBuilder extends AbstractMemberBuilder {
duke@1 47
bpatel@766 48 /**
bpatel@766 49 * The index of the current field that is being documented at this point
bpatel@766 50 * in time.
bpatel@766 51 */
bpatel@766 52 private int currentMethodIndex;
duke@1 53
bpatel@766 54 /**
bpatel@766 55 * The class whose methods are being documented.
bpatel@766 56 */
jjg@1410 57 private final ClassDoc classDoc;
duke@1 58
bpatel@766 59 /**
bpatel@766 60 * The visible methods for the given class.
bpatel@766 61 */
jjg@1410 62 private final VisibleMemberMap visibleMemberMap;
duke@1 63
bpatel@766 64 /**
bpatel@766 65 * The writer to output the method documentation.
bpatel@766 66 */
jjg@1410 67 private final MethodWriter writer;
duke@1 68
bpatel@766 69 /**
bpatel@766 70 * The methods being documented.
bpatel@766 71 */
bpatel@766 72 private List<ProgramElementDoc> methods;
duke@1 73
jjg@1410 74
jjg@1410 75 /**
jjg@1410 76 * Construct a new MethodBuilder.
jjg@1410 77 *
jjg@1410 78 * @param context the build context.
jjg@1410 79 * @param classDoc the class whoses members are being documented.
jjg@1410 80 * @param writer the doclet specific writer.
jjg@1410 81 */
jjg@1410 82 private MethodBuilder(Context context,
jjg@1410 83 ClassDoc classDoc,
jjg@1410 84 MethodWriter writer) {
jjg@1410 85 super(context);
jjg@1410 86 this.classDoc = classDoc;
jjg@1410 87 this.writer = writer;
jjg@1410 88 visibleMemberMap = new VisibleMemberMap(
jjg@1410 89 classDoc,
jjg@1410 90 VisibleMemberMap.METHODS,
jjg@1606 91 configuration);
jjg@1410 92 methods =
jjg@1410 93 new ArrayList<ProgramElementDoc>(visibleMemberMap.getLeafClassMembers(
jjg@1410 94 configuration));
jjg@1410 95 if (configuration.getMemberComparator() != null) {
jjg@1410 96 Collections.sort(methods, configuration.getMemberComparator());
jjg@1410 97 }
bpatel@766 98 }
bpatel@766 99
bpatel@766 100 /**
bpatel@766 101 * Construct a new MethodBuilder.
bpatel@766 102 *
jjg@1410 103 * @param context the build context.
bpatel@766 104 * @param classDoc the class whoses members are being documented.
bpatel@766 105 * @param writer the doclet specific writer.
bpatel@766 106 *
bpatel@766 107 * @return an instance of a MethodBuilder.
bpatel@766 108 */
jjg@1410 109 public static MethodBuilder getInstance(Context context,
jjg@1410 110 ClassDoc classDoc, MethodWriter writer) {
jjg@1410 111 return new MethodBuilder(context, classDoc, writer);
bpatel@766 112 }
duke@1 113
bpatel@766 114 /**
bpatel@766 115 * {@inheritDoc}
bpatel@766 116 */
bpatel@766 117 public String getName() {
bpatel@766 118 return "MethodDetails";
bpatel@766 119 }
bpatel@766 120
bpatel@766 121 /**
bpatel@766 122 * Returns a list of methods that will be documented for the given class.
bpatel@766 123 * This information can be used for doclet specific documentation
bpatel@766 124 * generation.
bpatel@766 125 *
bpatel@766 126 * @param classDoc the {@link ClassDoc} we want to check.
bpatel@766 127 * @return a list of methods that will be documented.
bpatel@766 128 */
bpatel@766 129 public List<ProgramElementDoc> members(ClassDoc classDoc) {
bpatel@766 130 return visibleMemberMap.getMembersFor(classDoc);
bpatel@766 131 }
bpatel@766 132
bpatel@766 133 /**
bpatel@766 134 * Returns the visible member map for the methods of this class.
bpatel@766 135 *
bpatel@766 136 * @return the visible member map for the methods of this class.
bpatel@766 137 */
bpatel@766 138 public VisibleMemberMap getVisibleMemberMap() {
bpatel@766 139 return visibleMemberMap;
bpatel@766 140 }
bpatel@766 141
bpatel@766 142 /**
bpatel@766 143 * {@inheritDoc}
bpatel@766 144 */
bpatel@766 145 public boolean hasMembersToDocument() {
bpatel@766 146 return methods.size() > 0;
bpatel@766 147 }
bpatel@766 148
bpatel@766 149 /**
bpatel@766 150 * Build the method documentation.
bpatel@766 151 *
bpatel@766 152 * @param node the XML element that specifies which components to document
bpatel@766 153 * @param memberDetailsTree the content tree to which the documentation will be added
bpatel@766 154 */
bpatel@766 155 public void buildMethodDoc(XMLNode node, Content memberDetailsTree) {
bpatel@766 156 if (writer == null) {
bpatel@766 157 return;
duke@1 158 }
bpatel@766 159 int size = methods.size();
bpatel@766 160 if (size > 0) {
bpatel@766 161 Content methodDetailsTree = writer.getMethodDetailsTreeHeader(
bpatel@766 162 classDoc, memberDetailsTree);
bpatel@766 163 for (currentMethodIndex = 0; currentMethodIndex < size;
bpatel@766 164 currentMethodIndex++) {
bpatel@766 165 Content methodDocTree = writer.getMethodDocTreeHeader(
bpatel@766 166 (MethodDoc) methods.get(currentMethodIndex),
bpatel@766 167 methodDetailsTree);
bpatel@766 168 buildChildren(node, methodDocTree);
bpatel@766 169 methodDetailsTree.addContent(writer.getMethodDoc(
bpatel@766 170 methodDocTree, (currentMethodIndex == size - 1)));
bpatel@766 171 }
bpatel@766 172 memberDetailsTree.addContent(
bpatel@766 173 writer.getMethodDetails(methodDetailsTree));
bpatel@766 174 }
bpatel@766 175 }
duke@1 176
bpatel@766 177 /**
bpatel@766 178 * Build the signature.
bpatel@766 179 *
bpatel@766 180 * @param node the XML element that specifies which components to document
bpatel@766 181 * @param methodDocTree the content tree to which the documentation will be added
bpatel@766 182 */
bpatel@766 183 public void buildSignature(XMLNode node, Content methodDocTree) {
bpatel@766 184 methodDocTree.addContent(
bpatel@766 185 writer.getSignature((MethodDoc) methods.get(currentMethodIndex)));
bpatel@766 186 }
duke@1 187
bpatel@766 188 /**
bpatel@766 189 * Build the deprecation information.
bpatel@766 190 *
bpatel@766 191 * @param node the XML element that specifies which components to document
bpatel@766 192 * @param methodDocTree the content tree to which the documentation will be added
bpatel@766 193 */
bpatel@766 194 public void buildDeprecationInfo(XMLNode node, Content methodDocTree) {
bpatel@766 195 writer.addDeprecated(
bpatel@766 196 (MethodDoc) methods.get(currentMethodIndex), methodDocTree);
bpatel@766 197 }
duke@1 198
bpatel@766 199 /**
bpatel@766 200 * Build the comments for the method. Do nothing if
bpatel@766 201 * {@link Configuration#nocomment} is set to true.
bpatel@766 202 *
bpatel@766 203 * @param node the XML element that specifies which components to document
bpatel@766 204 * @param methodDocTree the content tree to which the documentation will be added
bpatel@766 205 */
bpatel@766 206 public void buildMethodComments(XMLNode node, Content methodDocTree) {
bpatel@766 207 if (!configuration.nocomment) {
duke@1 208 MethodDoc method = (MethodDoc) methods.get(currentMethodIndex);
duke@1 209
duke@1 210 if (method.inlineTags().length == 0) {
duke@1 211 DocFinder.Output docs = DocFinder.search(
bpatel@766 212 new DocFinder.Input(method));
duke@1 213 method = docs.inlineTags != null && docs.inlineTags.length > 0 ?
duke@1 214 (MethodDoc) docs.holder : method;
duke@1 215 }
duke@1 216 //NOTE: When we fix the bug where ClassDoc.interfaceTypes() does
duke@1 217 // not pass all implemented interfaces, holder will be the
duke@1 218 // interface type. For now, it is really the erasure.
bpatel@766 219 writer.addComments(method.containingClass(), method, methodDocTree);
duke@1 220 }
bpatel@766 221 }
duke@1 222
bpatel@766 223 /**
bpatel@766 224 * Build the tag information.
bpatel@766 225 *
bpatel@766 226 * @param node the XML element that specifies which components to document
bpatel@766 227 * @param methodDocTree the content tree to which the documentation will be added
bpatel@766 228 */
bpatel@766 229 public void buildTagInfo(XMLNode node, Content methodDocTree) {
bpatel@766 230 writer.addTags((MethodDoc) methods.get(currentMethodIndex),
bpatel@766 231 methodDocTree);
bpatel@766 232 }
duke@1 233
bpatel@766 234 /**
bpatel@766 235 * Return the method writer for this builder.
bpatel@766 236 *
bpatel@766 237 * @return the method writer for this builder.
bpatel@766 238 */
bpatel@766 239 public MethodWriter getWriter() {
bpatel@766 240 return writer;
bpatel@766 241 }
duke@1 242 }

mercurial