Esempio n. 1
0
 public static Object convertArrayElements(Class<?> arrayType, Object array) {
   Class<?> src = array.getClass().getComponentType();
   Class<?> dst = arrayType.getComponentType();
   if (src == null || dst == null) throw new IllegalArgumentException("not array type");
   Wrapper sw = (src.isPrimitive() ? Wrapper.forPrimitiveType(src) : null);
   Wrapper dw = (dst.isPrimitive() ? Wrapper.forPrimitiveType(dst) : null);
   int length;
   if (sw == null) {
     Object[] a = (Object[]) array;
     length = a.length;
     if (dw == null) return Arrays.copyOf(a, length, arrayType.asSubclass(Object[].class));
     Object res = dw.makeArray(length);
     dw.copyArrayUnboxing(a, 0, res, 0, length);
     return res;
   }
   length = j86.java.lang.reflect.Array.getLength(array);
   Object[] res;
   if (dw == null) {
     res = Arrays.copyOf(NO_ARGS_ARRAY, length, arrayType.asSubclass(Object[].class));
   } else {
     res = new Object[length];
   }
   sw.copyArrayBoxing(array, 0, res, 0, length);
   if (dw == null) return res;
   Object a = dw.makeArray(length);
   dw.copyArrayUnboxing(res, 0, a, 0, length);
   return a;
 }
Esempio n. 2
0
 public static MethodHandle convertPrimitive(Class<?> src, Class<?> dst) {
   return convertPrimitive(Wrapper.forPrimitiveType(src), Wrapper.forPrimitiveType(dst));
 }
Esempio n. 3
0
 public static MethodHandle unboxCast(Class<?> type) {
   return unbox(Wrapper.forPrimitiveType(type), true);
 }
Esempio n. 4
0
 public static MethodHandle box(Class<?> type) {
   boolean exact = false;
   // e.g., boxShort(short)Short if exact,
   // e.g., boxShort(short)Object if !exact
   return box(Wrapper.forPrimitiveType(type), exact);
 }
Esempio n. 5
0
 private static MethodHandle buildArrayProducer(Class<?> arrayType) {
   Class<?> elemType = arrayType.getComponentType();
   if (elemType.isPrimitive())
     return LazyStatics.COPY_AS_PRIMITIVE_ARRAY.bindTo(Wrapper.forPrimitiveType(elemType));
   else return LazyStatics.COPY_AS_REFERENCE_ARRAY.bindTo(arrayType);
 }