private static byte getTTypeFromJavaType()

in core/src/main/java/com/twitter/elephantbird/thrift/TStructDescriptor.java [330:362]


  private static byte getTTypeFromJavaType(Type jType) {

    // check primitive types and final classes
    if (jType == Boolean.TYPE || jType == Boolean.class)   return TType.BOOL;
    if (jType == Byte.TYPE    || jType == Byte.class)      return TType.BYTE;
    if (jType == Short.TYPE   || jType == Short.class)     return TType.I16;
    if (jType == Integer.TYPE || jType == Integer.class)   return TType.I32;
    if (jType == Long.TYPE    || jType == Long.class)      return TType.I64;
    if (jType == Double.TYPE  || jType == Double.class)    return TType.DOUBLE;
    if (jType == String.class)                             return TType.STRING;
    if (jType == byte[].class)                             return TType.STRING; // buffer
    if (jType == Void.class)                               return TType.VOID;

    // non-generic simple classes
    if (jType instanceof Class) {
      Class<?> klass = (Class<?>) jType;

      if (TEnum.class.isAssignableFrom(klass))      return TType.ENUM;
      if (ByteBuffer.class.isAssignableFrom(klass)) return TType.STRING; // buffer (ByteBuffer)
      if (TBase.class.isAssignableFrom(klass))      return TType.STRUCT;
    }

    // generic types
    if (jType instanceof ParameterizedType) {
      Class<?> klass = (Class<?>) ((ParameterizedType)jType).getRawType();

      if (Map.class.isAssignableFrom(klass))    return TType.MAP;
      if (Set.class.isAssignableFrom(klass))    return TType.SET;
      if (List.class.isAssignableFrom(klass))   return TType.LIST;
    }

    throw new IllegalArgumentException("cannot convert java type '" + jType + "'  to thrift type");
  }