Wed, 18 Sep 2013 17:13:26 -0700
8015249: javadoc fails to document static final fields in annotation types
Reviewed-by: jjg
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.*; |
duke@1 | 33 | |
duke@1 | 34 | /** |
duke@1 | 35 | * Builds documentation for a constructor. |
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 ConstructorBuilder extends AbstractMemberBuilder { |
duke@1 | 47 | |
bpatel@766 | 48 | /** |
bpatel@766 | 49 | * The name of this builder. |
bpatel@766 | 50 | */ |
bpatel@766 | 51 | public static final String NAME = "ConstructorDetails"; |
duke@1 | 52 | |
bpatel@766 | 53 | /** |
bpatel@766 | 54 | * The index of the current field that is being documented at this point |
bpatel@766 | 55 | * in time. |
bpatel@766 | 56 | */ |
bpatel@766 | 57 | private int currentConstructorIndex; |
duke@1 | 58 | |
bpatel@766 | 59 | /** |
bpatel@766 | 60 | * The class whose constructors are being documented. |
bpatel@766 | 61 | */ |
jjg@1410 | 62 | private final ClassDoc classDoc; |
duke@1 | 63 | |
bpatel@766 | 64 | /** |
bpatel@766 | 65 | * The visible constructors for the given class. |
bpatel@766 | 66 | */ |
jjg@1410 | 67 | private final VisibleMemberMap visibleMemberMap; |
duke@1 | 68 | |
bpatel@766 | 69 | /** |
bpatel@766 | 70 | * The writer to output the constructor documentation. |
bpatel@766 | 71 | */ |
jjg@1410 | 72 | private final ConstructorWriter writer; |
duke@1 | 73 | |
bpatel@766 | 74 | /** |
bpatel@766 | 75 | * The constructors being documented. |
bpatel@766 | 76 | */ |
jjg@1410 | 77 | private final List<ProgramElementDoc> constructors; |
duke@1 | 78 | |
bpatel@766 | 79 | /** |
bpatel@766 | 80 | * Construct a new ConstructorBuilder. |
bpatel@766 | 81 | * |
jjg@1410 | 82 | * @param context the build context. |
jjg@1410 | 83 | * @param classDoc the class whoses members are being documented. |
jjg@1410 | 84 | * @param writer the doclet specific writer. |
bpatel@766 | 85 | */ |
jjg@1410 | 86 | private ConstructorBuilder(Context context, |
jjg@1410 | 87 | ClassDoc classDoc, |
jjg@1410 | 88 | ConstructorWriter writer) { |
jjg@1410 | 89 | super(context); |
jjg@1410 | 90 | this.classDoc = classDoc; |
jjg@1410 | 91 | this.writer = writer; |
jjg@1410 | 92 | visibleMemberMap = |
jjg@1410 | 93 | new VisibleMemberMap( |
jjg@1410 | 94 | classDoc, |
jjg@1410 | 95 | VisibleMemberMap.CONSTRUCTORS, |
jjg@1606 | 96 | configuration); |
jjg@1410 | 97 | constructors = |
jjg@1410 | 98 | new ArrayList<ProgramElementDoc>(visibleMemberMap.getMembersFor(classDoc)); |
jjg@1410 | 99 | for (int i = 0; i < constructors.size(); i++) { |
jjg@1410 | 100 | if (constructors.get(i).isProtected() |
jjg@1410 | 101 | || constructors.get(i).isPrivate()) { |
jjg@1410 | 102 | writer.setFoundNonPubConstructor(true); |
jjg@1410 | 103 | } |
jjg@1410 | 104 | } |
jjg@1410 | 105 | if (configuration.getMemberComparator() != null) { |
jjg@1410 | 106 | Collections.sort(constructors,configuration.getMemberComparator()); |
jjg@1410 | 107 | } |
bpatel@766 | 108 | } |
bpatel@766 | 109 | |
bpatel@766 | 110 | /** |
bpatel@766 | 111 | * Construct a new ConstructorBuilder. |
bpatel@766 | 112 | * |
jjg@1410 | 113 | * @param context the build context. |
bpatel@766 | 114 | * @param classDoc the class whoses members are being documented. |
bpatel@766 | 115 | * @param writer the doclet specific writer. |
bpatel@766 | 116 | */ |
jjg@1410 | 117 | public static ConstructorBuilder getInstance(Context context, |
jjg@1410 | 118 | ClassDoc classDoc, ConstructorWriter writer) { |
jjg@1410 | 119 | return new ConstructorBuilder(context, classDoc, writer); |
bpatel@766 | 120 | } |
duke@1 | 121 | |
bpatel@766 | 122 | /** |
bpatel@766 | 123 | * {@inheritDoc} |
bpatel@766 | 124 | */ |
bpatel@766 | 125 | public String getName() { |
bpatel@766 | 126 | return NAME; |
bpatel@766 | 127 | } |
bpatel@766 | 128 | |
bpatel@766 | 129 | /** |
bpatel@766 | 130 | * {@inheritDoc} |
bpatel@766 | 131 | */ |
bpatel@766 | 132 | public boolean hasMembersToDocument() { |
bpatel@766 | 133 | return constructors.size() > 0; |
bpatel@766 | 134 | } |
bpatel@766 | 135 | |
bpatel@766 | 136 | /** |
bpatel@766 | 137 | * Returns a list of constructors that will be documented for the given class. |
bpatel@766 | 138 | * This information can be used for doclet specific documentation |
bpatel@766 | 139 | * generation. |
bpatel@766 | 140 | * |
bpatel@766 | 141 | * @return a list of constructors that will be documented. |
bpatel@766 | 142 | */ |
bpatel@766 | 143 | public List<ProgramElementDoc> members(ClassDoc classDoc) { |
bpatel@766 | 144 | return visibleMemberMap.getMembersFor(classDoc); |
bpatel@766 | 145 | } |
bpatel@766 | 146 | |
bpatel@766 | 147 | /** |
bpatel@766 | 148 | * Return the constructor writer for this builder. |
bpatel@766 | 149 | * |
bpatel@766 | 150 | * @return the constructor writer for this builder. |
bpatel@766 | 151 | */ |
bpatel@766 | 152 | public ConstructorWriter getWriter() { |
bpatel@766 | 153 | return writer; |
bpatel@766 | 154 | } |
bpatel@766 | 155 | |
bpatel@766 | 156 | /** |
bpatel@766 | 157 | * Build the constructor documentation. |
bpatel@766 | 158 | * |
bpatel@766 | 159 | * @param node the XML element that specifies which components to document |
bpatel@766 | 160 | * @param memberDetailsTree the content tree to which the documentation will be added |
bpatel@766 | 161 | */ |
bpatel@766 | 162 | public void buildConstructorDoc(XMLNode node, Content memberDetailsTree) { |
bpatel@766 | 163 | if (writer == null) { |
bpatel@766 | 164 | return; |
duke@1 | 165 | } |
bpatel@766 | 166 | int size = constructors.size(); |
bpatel@766 | 167 | if (size > 0) { |
bpatel@766 | 168 | Content constructorDetailsTree = writer.getConstructorDetailsTreeHeader( |
bpatel@766 | 169 | classDoc, memberDetailsTree); |
bpatel@766 | 170 | for (currentConstructorIndex = 0; currentConstructorIndex < size; |
bpatel@766 | 171 | currentConstructorIndex++) { |
bpatel@766 | 172 | Content constructorDocTree = writer.getConstructorDocTreeHeader( |
bpatel@766 | 173 | (ConstructorDoc) constructors.get(currentConstructorIndex), |
bpatel@766 | 174 | constructorDetailsTree); |
bpatel@766 | 175 | buildChildren(node, constructorDocTree); |
bpatel@766 | 176 | constructorDetailsTree.addContent(writer.getConstructorDoc( |
bpatel@766 | 177 | constructorDocTree, (currentConstructorIndex == size - 1))); |
bpatel@766 | 178 | } |
bpatel@766 | 179 | memberDetailsTree.addContent( |
bpatel@766 | 180 | writer.getConstructorDetails(constructorDetailsTree)); |
bpatel@766 | 181 | } |
bpatel@766 | 182 | } |
duke@1 | 183 | |
bpatel@766 | 184 | /** |
bpatel@766 | 185 | * Build the signature. |
bpatel@766 | 186 | * |
bpatel@766 | 187 | * @param node the XML element that specifies which components to document |
bpatel@766 | 188 | * @param constructorDocTree the content tree to which the documentation will be added |
bpatel@766 | 189 | */ |
bpatel@766 | 190 | public void buildSignature(XMLNode node, Content constructorDocTree) { |
bpatel@766 | 191 | constructorDocTree.addContent( |
bpatel@766 | 192 | writer.getSignature( |
bpatel@766 | 193 | (ConstructorDoc) constructors.get(currentConstructorIndex))); |
bpatel@766 | 194 | } |
bpatel@766 | 195 | |
bpatel@766 | 196 | /** |
bpatel@766 | 197 | * Build the deprecation information. |
bpatel@766 | 198 | * |
bpatel@766 | 199 | * @param node the XML element that specifies which components to document |
bpatel@766 | 200 | * @param constructorDocTree the content tree to which the documentation will be added |
bpatel@766 | 201 | */ |
bpatel@766 | 202 | public void buildDeprecationInfo(XMLNode node, Content constructorDocTree) { |
bpatel@766 | 203 | writer.addDeprecated( |
bpatel@766 | 204 | (ConstructorDoc) constructors.get(currentConstructorIndex), constructorDocTree); |
bpatel@766 | 205 | } |
bpatel@766 | 206 | |
bpatel@766 | 207 | /** |
bpatel@766 | 208 | * Build the comments for the constructor. Do nothing if |
bpatel@766 | 209 | * {@link Configuration#nocomment} is set to true. |
bpatel@766 | 210 | * |
bpatel@766 | 211 | * @param node the XML element that specifies which components to document |
bpatel@766 | 212 | * @param constructorDocTree the content tree to which the documentation will be added |
bpatel@766 | 213 | */ |
bpatel@766 | 214 | public void buildConstructorComments(XMLNode node, Content constructorDocTree) { |
bpatel@766 | 215 | if (!configuration.nocomment) { |
bpatel@766 | 216 | writer.addComments( |
bpatel@766 | 217 | (ConstructorDoc) constructors.get(currentConstructorIndex), |
bpatel@766 | 218 | constructorDocTree); |
duke@1 | 219 | } |
bpatel@766 | 220 | } |
duke@1 | 221 | |
bpatel@766 | 222 | /** |
bpatel@766 | 223 | * Build the tag information. |
bpatel@766 | 224 | * |
bpatel@766 | 225 | * @param node the XML element that specifies which components to document |
bpatel@766 | 226 | * @param constructorDocTree the content tree to which the documentation will be added |
bpatel@766 | 227 | */ |
bpatel@766 | 228 | public void buildTagInfo(XMLNode node, Content constructorDocTree) { |
bpatel@766 | 229 | writer.addTags((ConstructorDoc) constructors.get(currentConstructorIndex), |
bpatel@766 | 230 | constructorDocTree); |
bpatel@766 | 231 | } |
duke@1 | 232 | } |