Thu, 02 Oct 2008 19:58:40 -0700
6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell
duke@1 | 1 | /* |
duke@1 | 2 | * Copyright 2001-2003 Sun Microsystems, Inc. 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 |
duke@1 | 7 | * published by the Free Software Foundation. Sun designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
duke@1 | 9 | * by Sun 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 | * |
duke@1 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@1 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@1 | 23 | * have any questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.internal.toolkit.taglets; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.javadoc.*; |
duke@1 | 29 | import com.sun.tools.doclets.internal.toolkit.Configuration; |
duke@1 | 30 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 31 | import java.util.*; |
duke@1 | 32 | |
duke@1 | 33 | /** |
duke@1 | 34 | * An inline Taglet representing the value tag. This tag should only be used with |
duke@1 | 35 | * constant fields that have a value. It is used to access the value of constant |
duke@1 | 36 | * fields. This inline tag has an optional field name parameter. If the name is |
duke@1 | 37 | * specified, the constant value is retrieved from the specified field. A link |
duke@1 | 38 | * is also created to the specified field. If a name is not specified, the value |
duke@1 | 39 | * is retrieved for the field that the inline tag appears on. The name is specifed |
duke@1 | 40 | * in the following format: [fully qualified class name]#[constant field name]. |
duke@1 | 41 | * |
duke@1 | 42 | * This code is not part of an API. |
duke@1 | 43 | * It is implementation that is subject to change. |
duke@1 | 44 | * Do not use it as an API |
duke@1 | 45 | * |
duke@1 | 46 | * @author Jamie Ho |
duke@1 | 47 | * @since 1.4 |
duke@1 | 48 | */ |
duke@1 | 49 | |
duke@1 | 50 | public class ValueTaglet extends BaseInlineTaglet { |
duke@1 | 51 | |
duke@1 | 52 | /** |
duke@1 | 53 | * Construct a new ValueTaglet. |
duke@1 | 54 | */ |
duke@1 | 55 | public ValueTaglet() { |
duke@1 | 56 | name = "value"; |
duke@1 | 57 | } |
duke@1 | 58 | |
duke@1 | 59 | /** |
duke@1 | 60 | * Will return false because this inline tag may |
duke@1 | 61 | * only appear in Fields. |
duke@1 | 62 | * @return false since this is not a method. |
duke@1 | 63 | */ |
duke@1 | 64 | public boolean inMethod() { |
duke@1 | 65 | return true; |
duke@1 | 66 | } |
duke@1 | 67 | |
duke@1 | 68 | /** |
duke@1 | 69 | * Will return false because this inline tag may |
duke@1 | 70 | * only appear in Fields. |
duke@1 | 71 | * @return false since this is not a method. |
duke@1 | 72 | */ |
duke@1 | 73 | public boolean inConstructor() { |
duke@1 | 74 | return true; |
duke@1 | 75 | } |
duke@1 | 76 | |
duke@1 | 77 | /** |
duke@1 | 78 | * Will return false because this inline tag may |
duke@1 | 79 | * only appear in Fields. |
duke@1 | 80 | * @return false since this is not a method. |
duke@1 | 81 | */ |
duke@1 | 82 | public boolean inOverview() { |
duke@1 | 83 | return true; |
duke@1 | 84 | } |
duke@1 | 85 | |
duke@1 | 86 | /** |
duke@1 | 87 | * Will return false because this inline tag may |
duke@1 | 88 | * only appear in Fields. |
duke@1 | 89 | * @return false since this is not a method. |
duke@1 | 90 | */ |
duke@1 | 91 | public boolean inPackage() { |
duke@1 | 92 | return true; |
duke@1 | 93 | } |
duke@1 | 94 | |
duke@1 | 95 | /** |
duke@1 | 96 | * Will return false because this inline tag may |
duke@1 | 97 | * only appear in Fields. |
duke@1 | 98 | * @return false since this is not a method. |
duke@1 | 99 | */ |
duke@1 | 100 | public boolean inType() { |
duke@1 | 101 | return true; |
duke@1 | 102 | } |
duke@1 | 103 | |
duke@1 | 104 | /** |
duke@1 | 105 | * Given the name of the field, return the corresponding FieldDoc. |
duke@1 | 106 | * |
duke@1 | 107 | * @param config the current configuration of the doclet. |
duke@1 | 108 | * @param tag the value tag. |
duke@1 | 109 | * @param name the name of the field to search for. The name should be in |
duke@1 | 110 | * <qualified class name>#<field name> format. If the class name is omitted, |
duke@1 | 111 | * it is assumed that the field is in the current class. |
duke@1 | 112 | * |
duke@1 | 113 | * @return the corresponding FieldDoc. If the name is null or empty string, |
duke@1 | 114 | * return field that the value tag was used in. |
duke@1 | 115 | * |
duke@1 | 116 | * @throws DocletAbortException if the value tag does not specify a name to |
duke@1 | 117 | * a value field and it is not used within the comments of a valid field. |
duke@1 | 118 | */ |
duke@1 | 119 | private FieldDoc getFieldDoc(Configuration config, Tag tag, String name) { |
duke@1 | 120 | if (name == null || name.length() == 0) { |
duke@1 | 121 | //Base case: no label. |
duke@1 | 122 | if (tag.holder() instanceof FieldDoc) { |
duke@1 | 123 | return (FieldDoc) tag.holder(); |
duke@1 | 124 | } else { |
duke@1 | 125 | //This should never ever happen. |
duke@1 | 126 | throw new DocletAbortException(); |
duke@1 | 127 | } |
duke@1 | 128 | } |
duke@1 | 129 | StringTokenizer st = new StringTokenizer(name, "#"); |
duke@1 | 130 | String memberName = null; |
duke@1 | 131 | ClassDoc cd = null; |
duke@1 | 132 | if (st.countTokens() == 1) { |
duke@1 | 133 | //Case 2: @value in same class. |
duke@1 | 134 | Doc holder = tag.holder(); |
duke@1 | 135 | if (holder instanceof MemberDoc) { |
duke@1 | 136 | cd = ((MemberDoc) holder).containingClass(); |
duke@1 | 137 | } else if (holder instanceof ClassDoc) { |
duke@1 | 138 | cd = (ClassDoc) holder; |
duke@1 | 139 | } |
duke@1 | 140 | memberName = st.nextToken(); |
duke@1 | 141 | } else { |
duke@1 | 142 | //Case 3: @value in different class. |
duke@1 | 143 | cd = config.root.classNamed(st.nextToken()); |
duke@1 | 144 | memberName = st.nextToken(); |
duke@1 | 145 | } |
duke@1 | 146 | if (cd == null) { |
duke@1 | 147 | return null; |
duke@1 | 148 | } |
duke@1 | 149 | FieldDoc[] fields = cd.fields(); |
duke@1 | 150 | for (int i = 0; i < fields.length; i++) { |
duke@1 | 151 | if (fields[i].name().equals(memberName)) { |
duke@1 | 152 | return fields[i]; |
duke@1 | 153 | } |
duke@1 | 154 | } |
duke@1 | 155 | return null; |
duke@1 | 156 | } |
duke@1 | 157 | |
duke@1 | 158 | /** |
duke@1 | 159 | * {@inheritDoc} |
duke@1 | 160 | */ |
duke@1 | 161 | public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) { |
duke@1 | 162 | FieldDoc field = getFieldDoc( |
duke@1 | 163 | writer.configuration(), tag, tag.text()); |
duke@1 | 164 | if (field == null) { |
duke@1 | 165 | //Reference is unknown. |
duke@1 | 166 | writer.getMsgRetriever().warning(tag.holder().position(), |
duke@1 | 167 | "doclet.value_tag_invalid_reference", tag.text()); |
duke@1 | 168 | } else if (field.constantValue() != null) { |
duke@1 | 169 | return writer.valueTagOutput(field, |
duke@1 | 170 | Util.escapeHtmlChars(field.constantValueExpression()), |
duke@1 | 171 | ! field.equals(tag.holder())); |
duke@1 | 172 | } else { |
duke@1 | 173 | //Referenced field is not a constant. |
duke@1 | 174 | writer.getMsgRetriever().warning(tag.holder().position(), |
duke@1 | 175 | "doclet.value_tag_invalid_constant", field.name()); |
duke@1 | 176 | } |
duke@1 | 177 | return writer.getOutputInstance(); |
duke@1 | 178 | } |
duke@1 | 179 | } |