< prev index next >

src/java.base/share/classes/java/io/ObjectStreamField.java

Print this page

        

*** 89,99 **** throw new NullPointerException(); } this.name = name; this.type = type; this.unshared = unshared; ! signature = getClassSignature(type).intern(); field = null; } /** * Creates an ObjectStreamField representing a field with the given name, --- 89,99 ---- throw new NullPointerException(); } this.name = name; this.type = type; this.unshared = unshared; ! signature = null; // will be lazily obtained from type field = null; } /** * Creates an ObjectStreamField representing a field with the given name,
*** 122,183 **** default: throw new IllegalArgumentException("illegal signature"); } } /** - * Returns JVM type signature for given primitive. - */ - private static String getPrimitiveSignature(Class<?> cl) { - if (cl == Integer.TYPE) - return "I"; - else if (cl == Byte.TYPE) - return "B"; - else if (cl == Long.TYPE) - return "J"; - else if (cl == Float.TYPE) - return "F"; - else if (cl == Double.TYPE) - return "D"; - else if (cl == Short.TYPE) - return "S"; - else if (cl == Character.TYPE) - return "C"; - else if (cl == Boolean.TYPE) - return "Z"; - else if (cl == Void.TYPE) - return "V"; - else - throw new InternalError(); - } - - /** - * Returns JVM type signature for given class. - */ - static String getClassSignature(Class<?> cl) { - if (cl.isPrimitive()) { - return getPrimitiveSignature(cl); - } else { - return appendClassSignature(new StringBuilder(), cl).toString(); - } - } - - static StringBuilder appendClassSignature(StringBuilder sbuf, Class<?> cl) { - while (cl.isArray()) { - sbuf.append('['); - cl = cl.getComponentType(); - } - - if (cl.isPrimitive()) { - sbuf.append(getPrimitiveSignature(cl)); - } else { - sbuf.append('L').append(cl.getName().replace('.', '/')).append(';'); - } - - return sbuf; - } - - /** * Creates an ObjectStreamField representing the given field with the * specified unshared setting. For compatibility with the behavior of * earlier serialization implementations, a "showType" parameter is * necessary to govern whether or not a getType() call on this * ObjectStreamField (if non-primitive) will return Object.class (as --- 122,131 ----
*** 186,197 **** ObjectStreamField(Field field, boolean unshared, boolean showType) { this.field = field; this.unshared = unshared; name = field.getName(); Class<?> ftype = field.getType(); ! type = (showType || ftype.isPrimitive()) ? ftype : Object.class; ! signature = getClassSignature(ftype).intern(); } /** * Get the name of this field. * --- 134,150 ---- ObjectStreamField(Field field, boolean unshared, boolean showType) { this.field = field; this.unshared = unshared; name = field.getName(); Class<?> ftype = field.getType(); ! if (showType || ftype.isPrimitive()) { ! type = ftype; ! signature = null; // will be lazily obtained from type ! } else { ! type = Object.class; ! signature = ftype.getJvmTypeSignature(); ! } } /** * Get the name of this field. *
*** 240,260 **** * * @return the typecode of the serializable field */ // REMIND: deprecate? public char getTypeCode() { ! return signature.charAt(0); } /** * Return the JVM type signature. * * @return null if this field has a primitive type. */ // REMIND: deprecate? public String getTypeString() { ! return isPrimitive() ? null : signature; } /** * Offset of field within instance data. * --- 193,213 ---- * * @return the typecode of the serializable field */ // REMIND: deprecate? public char getTypeCode() { ! return getSignature().charAt(0); } /** * Return the JVM type signature. * * @return null if this field has a primitive type. */ // REMIND: deprecate? public String getTypeString() { ! return isPrimitive() ? null : getSignature(); } /** * Offset of field within instance data. *
*** 282,292 **** * * @return true if and only if this field corresponds to a primitive type */ // REMIND: deprecate? public boolean isPrimitive() { ! char tcode = signature.charAt(0); return ((tcode != 'L') && (tcode != '[')); } /** * Returns boolean value indicating whether or not the serializable field --- 235,245 ---- * * @return true if and only if this field corresponds to a primitive type */ // REMIND: deprecate? public boolean isPrimitive() { ! char tcode = getSignature().charAt(0); return ((tcode != 'L') && (tcode != '[')); } /** * Returns boolean value indicating whether or not the serializable field
*** 318,328 **** /** * Return a string that describes this field. */ public String toString() { ! return signature + ' ' + name; } /** * Returns field represented by this ObjectStreamField, or null if * ObjectStreamField is not associated with an actual field. --- 271,281 ---- /** * Return a string that describes this field. */ public String toString() { ! return getSignature() + ' ' + name; } /** * Returns field represented by this ObjectStreamField, or null if * ObjectStreamField is not associated with an actual field.
*** 334,341 **** /** * Returns JVM type signature of field (similar to getTypeString, except * that signature strings are returned for primitive fields as well). */ String getSignature() { ! return signature; } } --- 287,294 ---- /** * Returns JVM type signature of field (similar to getTypeString, except * that signature strings are returned for primitive fields as well). */ String getSignature() { ! return signature == null ? type.getJvmTypeSignature() : signature; } }
< prev index next >