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

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 554
9d9f26857129
permissions
-rw-r--r--

Initial load

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

mercurial