langtools/src/share/classes/com/sun/tools/javac/util/Constants.java
changeset 3994 7df1ecd5eadb
parent 10 06bc494ca11e
child 5520 86e4b9a9da40
equal deleted inserted replaced
3897:fe8cc7e3a505 3994:7df1ecd5eadb
    81      * standard wrapped representation), quoted and formatted as in
    81      * standard wrapped representation), quoted and formatted as in
    82      * Java source.
    82      * Java source.
    83      */
    83      */
    84     public static String format(Object value) {
    84     public static String format(Object value) {
    85         if (value instanceof Byte)      return formatByte((Byte) value);
    85         if (value instanceof Byte)      return formatByte((Byte) value);
       
    86         if (value instanceof Short)     return formatShort((Short) value);
    86         if (value instanceof Long)      return formatLong((Long) value);
    87         if (value instanceof Long)      return formatLong((Long) value);
    87         if (value instanceof Float)     return formatFloat((Float) value);
    88         if (value instanceof Float)     return formatFloat((Float) value);
    88         if (value instanceof Double)    return formatDouble((Double) value);
    89         if (value instanceof Double)    return formatDouble((Double) value);
    89         if (value instanceof Character) return formatChar((Character) value);
    90         if (value instanceof Character) return formatChar((Character) value);
    90         if (value instanceof String)    return formatString((String) value);
    91         if (value instanceof String)    return formatString((String) value);
    91         return value + "";
    92         if (value instanceof Integer ||
       
    93             value instanceof Boolean)   return value.toString();
       
    94         else
       
    95             throw new IllegalArgumentException("Argument is not a primitive type or a string; it " +
       
    96                                                ((value == null) ?
       
    97                                                 "is a null value." :
       
    98                                                 "has class " +
       
    99                                                 value.getClass().getName()) + "." );
    92     }
   100     }
    93 
   101 
    94     private static String formatByte(byte b) {
   102     private static String formatByte(byte b) {
    95         return String.format("0x%02x", b);
   103         return String.format("(byte)0x%02x", b);
       
   104     }
       
   105 
       
   106     private static String formatShort(short s) {
       
   107         return String.format("(short)%d", s);
    96     }
   108     }
    97 
   109 
    98     private static String formatLong(long lng) {
   110     private static String formatLong(long lng) {
    99         return lng + "L";
   111         return lng + "L";
   100     }
   112     }