String (@Nullable Object value, TypeInfo type, boolean anno, TypeInfoProvider mapping) { if (value == null) return null; if (value instanceof String) { return "\"" + StringUtil.escapeStringCharacters((String)value) + "\""; } if (value instanceof Boolean || value instanceof Short || value instanceof Byte) { return value.toString(); } if (value instanceof Character) { return "'" + StringUtil.escapeCharCharacters(value.toString()) + "'"; } if (value instanceof Long) { return value.toString() + 'L'; } if (value instanceof Integer) { if (type.getKind() == TypeInfo.TypeKind.BOOLEAN) { if (value.equals(0)) return "false"; if (value.equals(1)) return "true"; } if (type.getKind() == TypeInfo.TypeKind.CHAR) { char ch = (char)((Integer)value).intValue(); return "'" + StringUtil.escapeCharCharacters(String.valueOf(ch)) + "'"; } return value.toString(); } if (value instanceof Double) { double d = (Double)value; if (Double.isInfinite(d)) { return d > 0 ? DOUBLE_POSITIVE_INF : DOUBLE_NEGATIVE_INF; } if (Double.isNaN(d)) { return DOUBLE_NAN; } return Double.toString(d); } if (value instanceof Float) { float v = (Float)value; if (Float.isInfinite(v)) { return v > 0 ? FLOAT_POSITIVE_INF : FLOAT_NEGATIVE_INF; } else if (Float.isNaN(v)) { return FLOAT_NAN; } else { return Float.toString(v) + 'f'; } } if (value.getClass().isArray()) { StringBuilder buffer = new StringBuilder(); buffer.append('{'); for (int i = 0, length = Array.getLength(value); i < length; i++) { if (i > 0) buffer.append(", "); buffer.append(constToString(Array.get(value, i), type, anno, mapping)); } buffer.append('}'); return buffer.toString(); } if (anno && value instanceof Type) { return toJavaType((Type)value, mapping) + ".class"; } return null; }