Tue, 14 May 2013 10:14:55 -0700
8012178: Cleanup use of Util.escapeHtmlChars
Reviewed-by: darcy
duke@1 | 1 | /* |
jjg@1746 | 2 | * Copyright (c) 2001, 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.taglets; |
duke@1 | 27 | |
jjg@1357 | 28 | import java.util.*; |
jjg@1357 | 29 | |
duke@1 | 30 | import com.sun.javadoc.*; |
jjg@1746 | 31 | import com.sun.tools.doclets.formats.html.markup.StringContent; |
duke@1 | 32 | import com.sun.tools.doclets.internal.toolkit.Configuration; |
duke@1 | 33 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * An inline Taglet representing the value tag. This tag should only be used with |
duke@1 | 37 | * constant fields that have a value. It is used to access the value of constant |
duke@1 | 38 | * fields. This inline tag has an optional field name parameter. If the name is |
duke@1 | 39 | * specified, the constant value is retrieved from the specified field. A link |
duke@1 | 40 | * is also created to the specified field. If a name is not specified, the value |
duke@1 | 41 | * is retrieved for the field that the inline tag appears on. The name is specifed |
duke@1 | 42 | * in the following format: [fully qualified class name]#[constant field name]. |
duke@1 | 43 | * |
jjg@1359 | 44 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 45 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 46 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 47 | * deletion without notice.</b> |
duke@1 | 48 | * |
duke@1 | 49 | * @author Jamie Ho |
duke@1 | 50 | * @since 1.4 |
duke@1 | 51 | */ |
duke@1 | 52 | |
duke@1 | 53 | public class ValueTaglet extends BaseInlineTaglet { |
duke@1 | 54 | |
duke@1 | 55 | /** |
duke@1 | 56 | * Construct a new ValueTaglet. |
duke@1 | 57 | */ |
duke@1 | 58 | public ValueTaglet() { |
duke@1 | 59 | name = "value"; |
duke@1 | 60 | } |
duke@1 | 61 | |
duke@1 | 62 | /** |
duke@1 | 63 | * Will return false because this inline tag may |
duke@1 | 64 | * only appear in Fields. |
duke@1 | 65 | * @return false since this is not a method. |
duke@1 | 66 | */ |
duke@1 | 67 | public boolean inMethod() { |
duke@1 | 68 | return true; |
duke@1 | 69 | } |
duke@1 | 70 | |
duke@1 | 71 | /** |
duke@1 | 72 | * Will return false because this inline tag may |
duke@1 | 73 | * only appear in Fields. |
duke@1 | 74 | * @return false since this is not a method. |
duke@1 | 75 | */ |
duke@1 | 76 | public boolean inConstructor() { |
duke@1 | 77 | return true; |
duke@1 | 78 | } |
duke@1 | 79 | |
duke@1 | 80 | /** |
duke@1 | 81 | * Will return false because this inline tag may |
duke@1 | 82 | * only appear in Fields. |
duke@1 | 83 | * @return false since this is not a method. |
duke@1 | 84 | */ |
duke@1 | 85 | public boolean inOverview() { |
duke@1 | 86 | return true; |
duke@1 | 87 | } |
duke@1 | 88 | |
duke@1 | 89 | /** |
duke@1 | 90 | * Will return false because this inline tag may |
duke@1 | 91 | * only appear in Fields. |
duke@1 | 92 | * @return false since this is not a method. |
duke@1 | 93 | */ |
duke@1 | 94 | public boolean inPackage() { |
duke@1 | 95 | return true; |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | /** |
duke@1 | 99 | * Will return false because this inline tag may |
duke@1 | 100 | * only appear in Fields. |
duke@1 | 101 | * @return false since this is not a method. |
duke@1 | 102 | */ |
duke@1 | 103 | public boolean inType() { |
duke@1 | 104 | return true; |
duke@1 | 105 | } |
duke@1 | 106 | |
duke@1 | 107 | /** |
duke@1 | 108 | * Given the name of the field, return the corresponding FieldDoc. |
duke@1 | 109 | * |
duke@1 | 110 | * @param config the current configuration of the doclet. |
duke@1 | 111 | * @param tag the value tag. |
duke@1 | 112 | * @param name the name of the field to search for. The name should be in |
jjg@1358 | 113 | * {@code <qualified class name>#<field name>} format. If the class name is omitted, |
duke@1 | 114 | * it is assumed that the field is in the current class. |
duke@1 | 115 | * |
duke@1 | 116 | * @return the corresponding FieldDoc. If the name is null or empty string, |
duke@1 | 117 | * return field that the value tag was used in. |
duke@1 | 118 | * |
duke@1 | 119 | * @throws DocletAbortException if the value tag does not specify a name to |
duke@1 | 120 | * a value field and it is not used within the comments of a valid field. |
duke@1 | 121 | */ |
duke@1 | 122 | private FieldDoc getFieldDoc(Configuration config, Tag tag, String name) { |
duke@1 | 123 | if (name == null || name.length() == 0) { |
duke@1 | 124 | //Base case: no label. |
duke@1 | 125 | if (tag.holder() instanceof FieldDoc) { |
duke@1 | 126 | return (FieldDoc) tag.holder(); |
duke@1 | 127 | } else { |
duke@1 | 128 | //This should never ever happen. |
duke@1 | 129 | throw new DocletAbortException(); |
duke@1 | 130 | } |
duke@1 | 131 | } |
duke@1 | 132 | StringTokenizer st = new StringTokenizer(name, "#"); |
duke@1 | 133 | String memberName = null; |
duke@1 | 134 | ClassDoc cd = null; |
duke@1 | 135 | if (st.countTokens() == 1) { |
duke@1 | 136 | //Case 2: @value in same class. |
duke@1 | 137 | Doc holder = tag.holder(); |
duke@1 | 138 | if (holder instanceof MemberDoc) { |
duke@1 | 139 | cd = ((MemberDoc) holder).containingClass(); |
duke@1 | 140 | } else if (holder instanceof ClassDoc) { |
duke@1 | 141 | cd = (ClassDoc) holder; |
duke@1 | 142 | } |
duke@1 | 143 | memberName = st.nextToken(); |
duke@1 | 144 | } else { |
duke@1 | 145 | //Case 3: @value in different class. |
duke@1 | 146 | cd = config.root.classNamed(st.nextToken()); |
duke@1 | 147 | memberName = st.nextToken(); |
duke@1 | 148 | } |
duke@1 | 149 | if (cd == null) { |
duke@1 | 150 | return null; |
duke@1 | 151 | } |
duke@1 | 152 | FieldDoc[] fields = cd.fields(); |
duke@1 | 153 | for (int i = 0; i < fields.length; i++) { |
duke@1 | 154 | if (fields[i].name().equals(memberName)) { |
duke@1 | 155 | return fields[i]; |
duke@1 | 156 | } |
duke@1 | 157 | } |
duke@1 | 158 | return null; |
duke@1 | 159 | } |
duke@1 | 160 | |
duke@1 | 161 | /** |
duke@1 | 162 | * {@inheritDoc} |
duke@1 | 163 | */ |
duke@1 | 164 | public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) { |
duke@1 | 165 | FieldDoc field = getFieldDoc( |
duke@1 | 166 | writer.configuration(), tag, tag.text()); |
duke@1 | 167 | if (field == null) { |
duke@1 | 168 | //Reference is unknown. |
duke@1 | 169 | writer.getMsgRetriever().warning(tag.holder().position(), |
duke@1 | 170 | "doclet.value_tag_invalid_reference", tag.text()); |
duke@1 | 171 | } else if (field.constantValue() != null) { |
duke@1 | 172 | return writer.valueTagOutput(field, |
jjg@1746 | 173 | field.constantValueExpression(), |
duke@1 | 174 | ! field.equals(tag.holder())); |
duke@1 | 175 | } else { |
duke@1 | 176 | //Referenced field is not a constant. |
duke@1 | 177 | writer.getMsgRetriever().warning(tag.holder().position(), |
duke@1 | 178 | "doclet.value_tag_invalid_constant", field.name()); |
duke@1 | 179 | } |
duke@1 | 180 | return writer.getOutputInstance(); |
duke@1 | 181 | } |
duke@1 | 182 | } |