コード例 #1
0
 public static Generic fromType(Type type) {
   Generic generic = new Generic();
   if (!(type instanceof ParameterizedType)) {
     ThriftType thriftType = ThriftType.fromJavaType(type);
     generic.setJavaClass(thriftType.getJavaClass());
     generic.setJavaTypeName(thriftType.getJavaTypeName());
     generic.setValue(thriftType.getValue());
     generic.setWarpperClassName(thriftType.getWarpperClassName());
     generic.setType(thriftType.getType());
     return generic;
   }
   ThriftType thriftType = ThriftType.fromJavaType(type);
   generic.setValue(thriftType.getValue());
   ParameterizedType parameterizedType = (ParameterizedType) type;
   Type[] types = parameterizedType.getActualTypeArguments();
   for (Type typeArgument : types) {
     if (typeArgument instanceof ParameterizedType) {
       generic.addGeneric(fromType(typeArgument));
       continue;
     }
     ThriftType typeArgumentThriftType = ThriftType.fromJavaType((Class<?>) typeArgument);
     if (typeArgumentThriftType.isStruct()) {
       typeArgumentThriftType = typeArgumentThriftType.clone();
       typeArgumentThriftType.setJavaClass((Class<?>) typeArgument);
       typeArgumentThriftType.setValue(((Class<?>) typeArgument).getSimpleName());
     }
     generic.addGeneric(typeArgumentThriftType);
   }
   return generic;
 }
コード例 #2
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder("<");
   for (Object type : types) {
     if (type instanceof Generic) {
       sb.append(type.toString());
     } else {
       ThriftType thriftType = (ThriftType) type;
       if (thriftType.isStruct()) {
         sb.append(thriftType.getValue());
       } else {
         sb.append(thriftType.getWarpperClassName());
       }
     }
   }
   sb.append(">");
   return sb.toString();
 }