public static String toCodeString(Object value){
  if (value == null) {
    return "null";
  }
  Type valueType=Type.forClass(value.getClass());
  assert TypedOperation.isNonreceiverType(valueType) : "expecting nonreceiver type, have " + valueType;
  if (valueType.isString()) {
    String escaped=StringEscapeUtils.escapeJava(value.toString());
    if (escaped.length() > GenInputsAbstract.string_maxlen) {
      throw new Error("String too long, length = " + escaped.length());
    }
    return "\"" + escaped + "\"";
  }
  if (valueType.getRuntimeClass().equals(Class.class)) {
    return ((Class<?>)value).getName() + ".class";
  }
  if (valueType.isBoxedPrimitive()) {
    valueType=((NonParameterizedType)valueType).toPrimitive();
  }
  if (valueType.equals(JavaTypes.CHAR_TYPE)) {
    if (value.equals(' ')) {
      return "' '";
    }
    return "\'" + StringEscapeUtils.escapeJavaStyleString(value.toString(),true) + "\'";
  }
  if (valueType.equals(JavaTypes.BOOLEAN_TYPE)) {
    return value.toString();
  }
  String rep;
  if (valueType.equals(JavaTypes.DOUBLE_TYPE)) {
    Double d=(Double)value;
    if (d.isNaN()) {
      return "Double.NaN";
    }
 else     if (d.equals(Double.POSITIVE_INFINITY)) {
      return "Double.POSITIVE_INFINITY";
    }
 else     if (d.equals(Double.NEGATIVE_INFINITY)) {
      return "Double.NEGATIVE_INFINITY";
    }
    rep=d.toString();
    assert rep != null;
    rep=rep + "d";
  }
 else   if (valueType.equals(JavaTypes.FLOAT_TYPE)) {
    Float f=(Float)value;
    if (f.isNaN()) {
      return "Float.NaN";
    }
 else     if (f.equals(Float.POSITIVE_INFINITY)) {
      return "Float.POSITIVE_INFINITY";
    }
 else     if (f == Float.NEGATIVE_INFINITY) {
      return "Float.NEGATIVE_INFINITY";
    }
    rep=f.toString();
    assert rep != null;
    rep=rep + "f";
  }
 else   if (valueType.equals(JavaTypes.LONG_TYPE)) {
    rep=value.toString() + "L";
  }
 else   if (valueType.equals(JavaTypes.BYTE_TYPE)) {
    rep="(byte)" + value.toString();
  }
 else   if (valueType.equals(JavaTypes.SHORT_TYPE)) {
    rep="(short)" + value.toString();
  }
 else   if (valueType.equals(JavaTypes.INT_TYPE)) {
    rep=value.toString();
  }
 else {
    throw new BugInRandoopException("type should be a nonreceiver type: " + valueType);
  }
  if (rep.charAt(0) == '-') {
    rep="(" + rep + ")";
  }
  return rep;
}

public static String toCodeString ( Object value ) { if ( value == null ) { return "null" ; } Type valueType = Type . forClass ( value . getClass ( ) ) ; assert TypedOperation . isNonreceiverType ( valueType ) : "expecting nonreceiver type, have " + valueType ; if ( valueType . isString ( ) ) { String escaped = StringEscapeUtils . escapeJava ( value . toString ( ) ) ; if ( escaped . length ( ) > GenInputsAbstract . string_maxlen ) { throw new Error ( "String too long, length = " + escaped . length ( ) ) ; } return "\"" + escaped + "\"" ; } if ( valueType . getRuntimeClass ( ) . equals ( Class . class ) ) { return ( ( Class < ? > ) value ) . getName ( ) + ".class" ; } if ( valueType . isBoxedPrimitive ( ) ) { valueType = ( ( NonParameterizedType ) valueType ) . toPrimitive ( ) ; } if ( valueType . equals ( JavaTypes . CHAR_TYPE ) ) { if ( value . equals ( ' ' ) ) { return "' '" ; } return "\'" + StringEscapeUtils . escapeJavaStyleString ( value . toString ( ) , true ) + "\'" ; } if ( valueType . equals ( JavaTypes . BOOLEAN_TYPE ) ) { return value . toString ( ) ; } String rep ; if ( valueType . equals ( JavaTypes . DOUBLE_TYPE ) ) { Double d = ( Double ) value ; if ( d . isNaN ( ) ) { return "Double.NaN" ; } else if ( d . equals ( Double . POSITIVE_INFINITY ) ) { return "Double.POSITIVE_INFINITY" ; } else if ( d . equals ( Double . NEGATIVE_INFINITY ) ) { return "Double.NEGATIVE_INFINITY" ; } rep = d . toString ( ) ; assert rep != null ; rep = rep + "d" ; } else if ( valueType . equals ( JavaTypes . FLOAT_TYPE ) ) { Float f = ( Float ) value ; if ( f . isNaN ( ) ) { return "Float.NaN" ; } else if ( f . equals ( Float . POSITIVE_INFINITY ) ) { return "Float.POSITIVE_INFINITY" ; } else if ( f == Float . NEGATIVE_INFINITY ) { return "Float.NEGATIVE_INFINITY" ; } rep = f . toString ( ) ; assert rep != null ; rep = rep + "f" ; } else if ( valueType . equals ( JavaTypes . LONG_TYPE ) ) { rep = value . toString ( ) + "L" ; } else if ( valueType . equals ( JavaTypes . BYTE_TYPE ) ) { rep = "(byte)" + value . toString ( ) ; } else if ( valueType . equals ( JavaTypes . SHORT_TYPE ) ) { rep = "(short)" + value . toString ( ) ; } else if ( valueType . equals ( JavaTypes . INT_TYPE ) ) { rep = value . toString ( ) ; } else { throw new BugInRandoopException ( "type should be a nonreceiver type: " + valueType ) ; } if ( rep . charAt ( 0 ) == '-' ) { rep = "(" + rep + ")" ; } return rep ; }
given a primitive , boxed primitive , or string , returns a string that can be used in java source to represent it .
