public static String asLiteral(final Object value) throws IllegalArgumentException {
    final Class<?> clazz = value.getClass();

    if (clazz.isArray()) {
      final StringBuilder sb = new StringBuilder();
      final Object[] array = (Object[]) value;

      sb.append("new " + clazz.getComponentType().getCanonicalName() + "[] {");
      boolean first = true;
      for (final Object object : array) {
        if (first) {
          first = false;
        } else {
          sb.append(',');
        }
        sb.append(asLiteral(object));
      }
      sb.append('}');
      return sb.toString();
    }

    if (value instanceof Boolean) {
      return JBooleanLiteral.get(((Boolean) value).booleanValue()).toSource();
    } else if (value instanceof Byte) {
      return JIntLiteral.get(((Byte) value).byteValue()).toSource();
    } else if (value instanceof Character) {
      return JCharLiteral.get(((Character) value).charValue()).toSource();
    } else if (value instanceof Class<?>) {
      return ((Class<?>) (Class<?>) value).getCanonicalName() + ".class";
    } else if (value instanceof Double) {
      return JDoubleLiteral.get(((Double) value).doubleValue()).toSource();
    } else if (value instanceof Enum) {
      return value.getClass().getCanonicalName() + "." + ((Enum<?>) value).name();
    } else if (value instanceof Float) {
      return JFloatLiteral.get(((Float) value).floatValue()).toSource();
    } else if (value instanceof Integer) {
      return JIntLiteral.get(((Integer) value).intValue()).toSource();
    } else if (value instanceof Long) {
      return JLongLiteral.get(((Long) value).longValue()).toSource();
    } else if (value instanceof String) {
      return '"' + Generator.escape((String) value) + '"';
    } else {
      // TODO(nchalko) handle Annotation types
      throw new IllegalArgumentException(
          value.getClass() + " can not be represented as a Java Literal.");
    }
  }
public static String asLiteral ( final Object value ) throws IllegalArgumentException { final Class < ? > clazz = value . getClass ( ) ; if ( clazz . isArray ( ) ) { final StringBuilder sb = new StringBuilder ( ) ; final Object [ ] array = ( Object [ ] ) value ; sb . append ( "new " + clazz . getComponentType ( ) . getCanonicalName ( ) + "[] {" ) ; boolean first = true ; for ( final Object object : array ) { if ( first ) { first = false ; } else { sb . append ( ',' ) ; } sb . append ( asLiteral ( object ) ) ; } sb . append ( '}' ) ; return sb . toString ( ) ; } if ( value instanceof Boolean ) { return JBooleanLiteral . get ( ( ( Boolean ) value ) . booleanValue ( ) ) . toSource ( ) ; } else if ( value instanceof Byte ) { return JIntLiteral . get ( ( ( Byte ) value ) . byteValue ( ) ) . toSource ( ) ; } else if ( value instanceof Character ) { return JCharLiteral . get ( ( ( Character ) value ) . charValue ( ) ) . toSource ( ) ; } else if ( value instanceof Class < ? > ) { return ( ( Class < ? > ) ( Class < ? > ) value ) . getCanonicalName ( ) + ".class" ; } else if ( value instanceof Double ) { return JDoubleLiteral . get ( ( ( Double ) value ) . doubleValue ( ) ) . toSource ( ) ; } else if ( value instanceof Enum ) { return value . getClass ( ) . getCanonicalName ( ) + "." + ( ( Enum < ? > ) value ) . name ( ) ; } else if ( value instanceof Float ) { return JFloatLiteral . get ( ( ( Float ) value ) . floatValue ( ) ) . toSource ( ) ; } else if ( value instanceof Integer ) { return JIntLiteral . get ( ( ( Integer ) value ) . intValue ( ) ) . toSource ( ) ; } else if ( value instanceof Long ) { return JLongLiteral . get ( ( ( Long ) value ) . longValue ( ) ) . toSource ( ) ; } else if ( value instanceof String ) { return '"' + Generator . escape ( ( String ) value ) + '"' ; } else { throw new IllegalArgumentException ( value . getClass ( ) + " can not be represented as a Java Literal." ) ; } }
Returns the literal value of an object that is suitable for inclusion in Java Source code.

<p>
Supports all types that {@link Annotation} value can have.
</p>

@param value the object to handle
@return string of the literal
@throws IllegalArgumentException if the type of the object does not have a java literal form.