src/share/classes/com/sun/tools/javadoc/SerialFieldTagImpl.java

Mon, 25 Mar 2013 16:55:14 -0700

author
mfang
date
Mon, 25 Mar 2013 16:55:14 -0700
changeset 1658
fdf30b225e1c
parent 1359
25e14ad23cef
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8010521: jdk8 l10n resource file translation update 2
Reviewed-by: naoto, yhuang

duke@1 1 /*
jjg@1359 2 * Copyright (c) 1998, 2012, 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.javadoc;
duke@1 27
duke@1 28 import com.sun.javadoc.*;
duke@1 29
duke@1 30 /**
duke@1 31 * Documents a Serializable field defined by an ObjectStreamField.
duke@1 32 * <pre>
duke@1 33 * The class parses and stores the three serialField tag parameters:
duke@1 34 *
duke@1 35 * - field name
duke@1 36 * - field type name
duke@1 37 * (fully-qualified or visible from the current import context)
duke@1 38 * - description of the valid values for the field
duke@1 39
duke@1 40 * </pre>
duke@1 41 * This tag is only allowed in the javadoc for the special member
duke@1 42 * serialPersistentFields.
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>
jjg@1359 48 *
duke@1 49 * @author Joe Fialli
duke@1 50 * @author Neal Gafter
duke@1 51 *
duke@1 52 * @see java.io.ObjectStreamField
duke@1 53 */
duke@1 54 class SerialFieldTagImpl
duke@1 55 extends TagImpl
duke@1 56 implements SerialFieldTag, Comparable<Object>
duke@1 57 {
duke@1 58 //### These could be final, except that the constructor
duke@1 59 //### does not set them directly.
duke@1 60
duke@1 61 private String fieldName; // Required Argument 1 of serialField
duke@1 62 private String fieldType; // Required Argument 2 of serialField
duke@1 63 private String description; // Optional Remaining Arguments of serialField
duke@1 64
duke@1 65 private ClassDoc containingClass; // Class containing serialPersistentField member
duke@1 66 private ClassDoc fieldTypeDoc; // ClassDocImpl of fieldType
duke@1 67 private FieldDocImpl matchingField; // FieldDocImpl with same name as fieldName
duke@1 68
duke@1 69 /* Constructor. */
duke@1 70 SerialFieldTagImpl(DocImpl holder, String name, String text) {
duke@1 71 super(holder, name, text);
duke@1 72 parseSerialFieldString();
duke@1 73 if (holder instanceof MemberDoc) {
duke@1 74 containingClass = ((MemberDocImpl)holder).containingClass();
duke@1 75 }
duke@1 76 }
duke@1 77
duke@1 78 /*
duke@1 79 * The serialField tag is composed of three entities.
duke@1 80 *
duke@1 81 * serialField serializableFieldName serisliableFieldType
duke@1 82 * description of field.
duke@1 83 *
duke@1 84 * The fieldName and fieldType must be legal Java Identifiers.
duke@1 85 */
duke@1 86 private void parseSerialFieldString() {
duke@1 87 int len = text.length();
ksrini@1052 88 if (len == 0) {
ksrini@1052 89 return;
ksrini@1052 90 }
duke@1 91
duke@1 92 // if no white space found
duke@1 93 /* Skip white space. */
duke@1 94 int inx = 0;
duke@1 95 int cp;
duke@1 96 for (; inx < len; inx += Character.charCount(cp)) {
duke@1 97 cp = text.codePointAt(inx);
duke@1 98 if (!Character.isWhitespace(cp)) {
duke@1 99 break;
duke@1 100 }
duke@1 101 }
duke@1 102
duke@1 103 /* find first word. */
duke@1 104 int first = inx;
duke@1 105 int last = inx;
duke@1 106 cp = text.codePointAt(inx);
duke@1 107 if (! Character.isJavaIdentifierStart(cp)) {
duke@1 108 docenv().warning(holder,
duke@1 109 "tag.serialField.illegal_character",
duke@1 110 new String(Character.toChars(cp)), text);
duke@1 111 return;
duke@1 112 }
duke@1 113
duke@1 114 for (inx += Character.charCount(cp); inx < len; inx += Character.charCount(cp)) {
duke@1 115 cp = text.codePointAt(inx);
duke@1 116 if (!Character.isJavaIdentifierPart(cp)) {
duke@1 117 break;
duke@1 118 }
duke@1 119 }
duke@1 120
duke@1 121 if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) {
duke@1 122 docenv().warning(holder,
duke@1 123 "tag.serialField.illegal_character",
duke@1 124 new String(Character.toChars(cp)), text);
duke@1 125 return;
duke@1 126 }
duke@1 127
duke@1 128 last = inx;
duke@1 129 fieldName = text.substring(first, last);
duke@1 130
duke@1 131 /* Skip white space. */
duke@1 132 for (; inx < len; inx += Character.charCount(cp)) {
duke@1 133 cp = text.codePointAt(inx);
duke@1 134 if (!Character.isWhitespace(cp)) {
duke@1 135 break;
duke@1 136 }
duke@1 137 }
duke@1 138
duke@1 139 /* find second word. */
duke@1 140 first = inx;
duke@1 141 last = inx;
duke@1 142
duke@1 143 for (; inx < len; inx += Character.charCount(cp)) {
duke@1 144 cp = text.codePointAt(inx);
duke@1 145 if (Character.isWhitespace(cp)) {
duke@1 146 break;
duke@1 147 }
duke@1 148 }
duke@1 149 if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) {
duke@1 150 docenv().warning(holder,
duke@1 151 "tag.serialField.illegal_character",
duke@1 152 new String(Character.toChars(cp)), text);
duke@1 153 return;
duke@1 154 }
duke@1 155 last = inx;
duke@1 156 fieldType = text.substring(first, last);
duke@1 157
duke@1 158 /* Skip leading white space. Rest of string is description for serialField.*/
duke@1 159 for (; inx < len; inx += Character.charCount(cp)) {
duke@1 160 cp = text.codePointAt(inx);
duke@1 161 if (!Character.isWhitespace(cp)) {
duke@1 162 break;
duke@1 163 }
duke@1 164 }
duke@1 165 description = text.substring(inx);
duke@1 166 }
duke@1 167
duke@1 168 /**
duke@1 169 * return a key for sorting.
duke@1 170 */
duke@1 171 String key() {
duke@1 172 return fieldName;
duke@1 173 }
duke@1 174
duke@1 175 /*
duke@1 176 * Optional. Link this serialField tag to its corrsponding
duke@1 177 * field in the class. Note: there is no requirement that
duke@1 178 * there be a field in the class that matches serialField tag.
duke@1 179 */
duke@1 180 void mapToFieldDocImpl(FieldDocImpl fd) {
duke@1 181 matchingField = fd;
duke@1 182 }
duke@1 183
duke@1 184 /**
duke@1 185 * Return the serialziable field name.
duke@1 186 */
duke@1 187 public String fieldName() {
duke@1 188 return fieldName;
duke@1 189 }
duke@1 190
duke@1 191 /**
duke@1 192 * Return the field type string.
duke@1 193 */
duke@1 194 public String fieldType() {
duke@1 195 return fieldType;
duke@1 196 }
duke@1 197
duke@1 198 /**
duke@1 199 * Return the ClassDocImpl for field type.
duke@1 200 *
duke@1 201 * @returns null if no ClassDocImpl for field type is visible from
duke@1 202 * containingClass context.
duke@1 203 */
duke@1 204 public ClassDoc fieldTypeDoc() {
duke@1 205 if (fieldTypeDoc == null && containingClass != null) {
duke@1 206 fieldTypeDoc = containingClass.findClass(fieldType);
duke@1 207 }
duke@1 208 return fieldTypeDoc;
duke@1 209 }
duke@1 210
duke@1 211 /**
duke@1 212 * Return the corresponding FieldDocImpl for this SerialFieldTagImpl.
duke@1 213 *
duke@1 214 * @returns null if no matching FieldDocImpl.
duke@1 215 */
duke@1 216 FieldDocImpl getMatchingField() {
duke@1 217 return matchingField;
duke@1 218 }
duke@1 219
duke@1 220 /**
duke@1 221 * Return the field comment. If there is no serialField comment, return
duke@1 222 * javadoc comment of corresponding FieldDocImpl.
duke@1 223 */
duke@1 224 public String description() {
duke@1 225 if (description.length() == 0 && matchingField != null) {
duke@1 226
duke@1 227 //check for javadoc comment of corresponding field.
duke@1 228 Comment comment = matchingField.comment();
duke@1 229 if (comment != null) {
duke@1 230 return comment.commentText();
duke@1 231 }
duke@1 232 }
duke@1 233 return description;
duke@1 234 }
duke@1 235
duke@1 236 /**
duke@1 237 * Return the kind of this tag.
duke@1 238 */
duke@1 239 public String kind() {
duke@1 240 return "@serialField";
duke@1 241 }
duke@1 242
duke@1 243 /**
duke@1 244 * Convert this object to a string.
duke@1 245 */
duke@1 246 public String toString() {
duke@1 247 return name + ":" + text;
duke@1 248 }
duke@1 249
duke@1 250 /**
duke@1 251 * Compares this Object with the specified Object for order. Returns a
duke@1 252 * negative integer, zero, or a positive integer as this Object is less
duke@1 253 * than, equal to, or greater than the given Object.
duke@1 254 * <p>
duke@1 255 * Included to make SerialFieldTagImpl items java.lang.Comparable.
duke@1 256 *
duke@1 257 * @param obj the <code>Object</code> to be compared.
duke@1 258 * @return a negative integer, zero, or a positive integer as this Object
duke@1 259 * is less than, equal to, or greater than the given Object.
duke@1 260 * @exception ClassCastException the specified Object's type prevents it
duke@1 261 * from being compared to this Object.
duke@1 262 * @since 1.2
duke@1 263 */
duke@1 264 public int compareTo(Object obj) {
duke@1 265 return key().compareTo(((SerialFieldTagImpl)obj).key());
duke@1 266 }
duke@1 267 }

mercurial