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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.javadoc;
aoqi@0 27
aoqi@0 28 import com.sun.javadoc.*;
aoqi@0 29
aoqi@0 30 /**
aoqi@0 31 * Documents a Serializable field defined by an ObjectStreamField.
aoqi@0 32 * <pre>
aoqi@0 33 * The class parses and stores the three serialField tag parameters:
aoqi@0 34 *
aoqi@0 35 * - field name
aoqi@0 36 * - field type name
aoqi@0 37 * (fully-qualified or visible from the current import context)
aoqi@0 38 * - description of the valid values for the field
aoqi@0 39
aoqi@0 40 * </pre>
aoqi@0 41 * This tag is only allowed in the javadoc for the special member
aoqi@0 42 * serialPersistentFields.
aoqi@0 43 *
aoqi@0 44 * <p><b>This is NOT part of any supported API.
aoqi@0 45 * If you write code that depends on this, you do so at your own risk.
aoqi@0 46 * This code and its internal interfaces are subject to change or
aoqi@0 47 * deletion without notice.</b>
aoqi@0 48 *
aoqi@0 49 * @author Joe Fialli
aoqi@0 50 * @author Neal Gafter
aoqi@0 51 *
aoqi@0 52 * @see java.io.ObjectStreamField
aoqi@0 53 */
aoqi@0 54 class SerialFieldTagImpl
aoqi@0 55 extends TagImpl
aoqi@0 56 implements SerialFieldTag, Comparable<Object>
aoqi@0 57 {
aoqi@0 58 //### These could be final, except that the constructor
aoqi@0 59 //### does not set them directly.
aoqi@0 60
aoqi@0 61 private String fieldName; // Required Argument 1 of serialField
aoqi@0 62 private String fieldType; // Required Argument 2 of serialField
aoqi@0 63 private String description; // Optional Remaining Arguments of serialField
aoqi@0 64
aoqi@0 65 private ClassDoc containingClass; // Class containing serialPersistentField member
aoqi@0 66 private ClassDoc fieldTypeDoc; // ClassDocImpl of fieldType
aoqi@0 67 private FieldDocImpl matchingField; // FieldDocImpl with same name as fieldName
aoqi@0 68
aoqi@0 69 /* Constructor. */
aoqi@0 70 SerialFieldTagImpl(DocImpl holder, String name, String text) {
aoqi@0 71 super(holder, name, text);
aoqi@0 72 parseSerialFieldString();
aoqi@0 73 if (holder instanceof MemberDoc) {
aoqi@0 74 containingClass = ((MemberDocImpl)holder).containingClass();
aoqi@0 75 }
aoqi@0 76 }
aoqi@0 77
aoqi@0 78 /*
aoqi@0 79 * The serialField tag is composed of three entities.
aoqi@0 80 *
aoqi@0 81 * serialField serializableFieldName serisliableFieldType
aoqi@0 82 * description of field.
aoqi@0 83 *
aoqi@0 84 * The fieldName and fieldType must be legal Java Identifiers.
aoqi@0 85 */
aoqi@0 86 private void parseSerialFieldString() {
aoqi@0 87 int len = text.length();
aoqi@0 88 if (len == 0) {
aoqi@0 89 return;
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 // if no white space found
aoqi@0 93 /* Skip white space. */
aoqi@0 94 int inx = 0;
aoqi@0 95 int cp;
aoqi@0 96 for (; inx < len; inx += Character.charCount(cp)) {
aoqi@0 97 cp = text.codePointAt(inx);
aoqi@0 98 if (!Character.isWhitespace(cp)) {
aoqi@0 99 break;
aoqi@0 100 }
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 /* find first word. */
aoqi@0 104 int first = inx;
aoqi@0 105 int last = inx;
aoqi@0 106 cp = text.codePointAt(inx);
aoqi@0 107 if (! Character.isJavaIdentifierStart(cp)) {
aoqi@0 108 docenv().warning(holder,
aoqi@0 109 "tag.serialField.illegal_character",
aoqi@0 110 new String(Character.toChars(cp)), text);
aoqi@0 111 return;
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 for (inx += Character.charCount(cp); inx < len; inx += Character.charCount(cp)) {
aoqi@0 115 cp = text.codePointAt(inx);
aoqi@0 116 if (!Character.isJavaIdentifierPart(cp)) {
aoqi@0 117 break;
aoqi@0 118 }
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) {
aoqi@0 122 docenv().warning(holder,
aoqi@0 123 "tag.serialField.illegal_character",
aoqi@0 124 new String(Character.toChars(cp)), text);
aoqi@0 125 return;
aoqi@0 126 }
aoqi@0 127
aoqi@0 128 last = inx;
aoqi@0 129 fieldName = text.substring(first, last);
aoqi@0 130
aoqi@0 131 /* Skip white space. */
aoqi@0 132 for (; inx < len; inx += Character.charCount(cp)) {
aoqi@0 133 cp = text.codePointAt(inx);
aoqi@0 134 if (!Character.isWhitespace(cp)) {
aoqi@0 135 break;
aoqi@0 136 }
aoqi@0 137 }
aoqi@0 138
aoqi@0 139 /* find second word. */
aoqi@0 140 first = inx;
aoqi@0 141 last = inx;
aoqi@0 142
aoqi@0 143 for (; inx < len; inx += Character.charCount(cp)) {
aoqi@0 144 cp = text.codePointAt(inx);
aoqi@0 145 if (Character.isWhitespace(cp)) {
aoqi@0 146 break;
aoqi@0 147 }
aoqi@0 148 }
aoqi@0 149 if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) {
aoqi@0 150 docenv().warning(holder,
aoqi@0 151 "tag.serialField.illegal_character",
aoqi@0 152 new String(Character.toChars(cp)), text);
aoqi@0 153 return;
aoqi@0 154 }
aoqi@0 155 last = inx;
aoqi@0 156 fieldType = text.substring(first, last);
aoqi@0 157
aoqi@0 158 /* Skip leading white space. Rest of string is description for serialField.*/
aoqi@0 159 for (; inx < len; inx += Character.charCount(cp)) {
aoqi@0 160 cp = text.codePointAt(inx);
aoqi@0 161 if (!Character.isWhitespace(cp)) {
aoqi@0 162 break;
aoqi@0 163 }
aoqi@0 164 }
aoqi@0 165 description = text.substring(inx);
aoqi@0 166 }
aoqi@0 167
aoqi@0 168 /**
aoqi@0 169 * return a key for sorting.
aoqi@0 170 */
aoqi@0 171 String key() {
aoqi@0 172 return fieldName;
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 /*
aoqi@0 176 * Optional. Link this serialField tag to its corrsponding
aoqi@0 177 * field in the class. Note: there is no requirement that
aoqi@0 178 * there be a field in the class that matches serialField tag.
aoqi@0 179 */
aoqi@0 180 void mapToFieldDocImpl(FieldDocImpl fd) {
aoqi@0 181 matchingField = fd;
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 /**
aoqi@0 185 * Return the serialziable field name.
aoqi@0 186 */
aoqi@0 187 public String fieldName() {
aoqi@0 188 return fieldName;
aoqi@0 189 }
aoqi@0 190
aoqi@0 191 /**
aoqi@0 192 * Return the field type string.
aoqi@0 193 */
aoqi@0 194 public String fieldType() {
aoqi@0 195 return fieldType;
aoqi@0 196 }
aoqi@0 197
aoqi@0 198 /**
aoqi@0 199 * Return the ClassDocImpl for field type.
aoqi@0 200 *
aoqi@0 201 * @returns null if no ClassDocImpl for field type is visible from
aoqi@0 202 * containingClass context.
aoqi@0 203 */
aoqi@0 204 public ClassDoc fieldTypeDoc() {
aoqi@0 205 if (fieldTypeDoc == null && containingClass != null) {
aoqi@0 206 fieldTypeDoc = containingClass.findClass(fieldType);
aoqi@0 207 }
aoqi@0 208 return fieldTypeDoc;
aoqi@0 209 }
aoqi@0 210
aoqi@0 211 /**
aoqi@0 212 * Return the corresponding FieldDocImpl for this SerialFieldTagImpl.
aoqi@0 213 *
aoqi@0 214 * @returns null if no matching FieldDocImpl.
aoqi@0 215 */
aoqi@0 216 FieldDocImpl getMatchingField() {
aoqi@0 217 return matchingField;
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 /**
aoqi@0 221 * Return the field comment. If there is no serialField comment, return
aoqi@0 222 * javadoc comment of corresponding FieldDocImpl.
aoqi@0 223 */
aoqi@0 224 public String description() {
aoqi@0 225 if (description.length() == 0 && matchingField != null) {
aoqi@0 226
aoqi@0 227 //check for javadoc comment of corresponding field.
aoqi@0 228 Comment comment = matchingField.comment();
aoqi@0 229 if (comment != null) {
aoqi@0 230 return comment.commentText();
aoqi@0 231 }
aoqi@0 232 }
aoqi@0 233 return description;
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 /**
aoqi@0 237 * Return the kind of this tag.
aoqi@0 238 */
aoqi@0 239 public String kind() {
aoqi@0 240 return "@serialField";
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 /**
aoqi@0 244 * Convert this object to a string.
aoqi@0 245 */
aoqi@0 246 public String toString() {
aoqi@0 247 return name + ":" + text;
aoqi@0 248 }
aoqi@0 249
aoqi@0 250 /**
aoqi@0 251 * Compares this Object with the specified Object for order. Returns a
aoqi@0 252 * negative integer, zero, or a positive integer as this Object is less
aoqi@0 253 * than, equal to, or greater than the given Object.
aoqi@0 254 * <p>
aoqi@0 255 * Included to make SerialFieldTagImpl items java.lang.Comparable.
aoqi@0 256 *
aoqi@0 257 * @param obj the <code>Object</code> to be compared.
aoqi@0 258 * @return a negative integer, zero, or a positive integer as this Object
aoqi@0 259 * is less than, equal to, or greater than the given Object.
aoqi@0 260 * @exception ClassCastException the specified Object's type prevents it
aoqi@0 261 * from being compared to this Object.
aoqi@0 262 * @since 1.2
aoqi@0 263 */
aoqi@0 264 public int compareTo(Object obj) {
aoqi@0 265 return key().compareTo(((SerialFieldTagImpl)obj).key());
aoqi@0 266 }
aoqi@0 267 }

mercurial