@Test(expected = InternalException.class) public void make異常系() { try{ Reflects.make(ReflectsTestObject.class, "", ""); }catch (InternalException e) { assertThat(e.getCode(), is("E-UTIL#0026")); throw e; } }
public static <T> T make(Class<T> clazz, Object... args){ T t = null; try { Constructor<T> c = clazz.getDeclaredConstructor(toClassArray(args)); c.setAccessible(true); t= c.newInstance(args); } catch (InstantiationException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalAccessException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0027", replace, e); } catch (SecurityException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0028", replace, e); } catch (NoSuchMethodException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalArgumentException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0029", replace, e); } catch (InvocationTargetException e) { throw new TargetThrowsException(Reflects.class, "E-UTIL#0030", e.getCause()); } return t; }
Reflects { public static <T> T make(Class<T> clazz, Object... args){ T t = null; try { Constructor<T> c = clazz.getDeclaredConstructor(toClassArray(args)); c.setAccessible(true); t= c.newInstance(args); } catch (InstantiationException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalAccessException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0027", replace, e); } catch (SecurityException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0028", replace, e); } catch (NoSuchMethodException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalArgumentException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0029", replace, e); } catch (InvocationTargetException e) { throw new TargetThrowsException(Reflects.class, "E-UTIL#0030", e.getCause()); } return t; } }
Reflects { public static <T> T make(Class<T> clazz, Object... args){ T t = null; try { Constructor<T> c = clazz.getDeclaredConstructor(toClassArray(args)); c.setAccessible(true); t= c.newInstance(args); } catch (InstantiationException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalAccessException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0027", replace, e); } catch (SecurityException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0028", replace, e); } catch (NoSuchMethodException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalArgumentException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0029", replace, e); } catch (InvocationTargetException e) { throw new TargetThrowsException(Reflects.class, "E-UTIL#0030", e.getCause()); } return t; } private  Reflects(); }
Reflects { public static <T> T make(Class<T> clazz, Object... args){ T t = null; try { Constructor<T> c = clazz.getDeclaredConstructor(toClassArray(args)); c.setAccessible(true); t= c.newInstance(args); } catch (InstantiationException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalAccessException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0027", replace, e); } catch (SecurityException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0028", replace, e); } catch (NoSuchMethodException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalArgumentException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0029", replace, e); } catch (InvocationTargetException e) { throw new TargetThrowsException(Reflects.class, "E-UTIL#0030", e.getCause()); } return t; } private  Reflects(); static Method findMethodSigned(String name, Class<?> target, Class<?>... argumentTypes); static Method findMethodNamed(String name, Class<?> target); static Method findMethodNamed(Pattern pattern, Class<?> target); static Field findFieldNamed(String name, Class<?> target); static Field findFieldNamed(Pattern pattern, Class<?> target); static Constructor<T> findConstructorFor(Class<T> target, Class<?>... argumentTypes); static Object invoke(Method method, Object instance, Object... arguments); static Object read(Field field, Object instance); static void write(Field field, Object instance, Object newValue); static T invoke(Constructor<T> con, Object... arguments); static T make(Class<T> clazz, Object... args); static Method[] findAllMethods(Class<?> clazz); static Field[] findAllFields(Class<?> clazz); }
Reflects { public static <T> T make(Class<T> clazz, Object... args){ T t = null; try { Constructor<T> c = clazz.getDeclaredConstructor(toClassArray(args)); c.setAccessible(true); t= c.newInstance(args); } catch (InstantiationException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalAccessException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0027", replace, e); } catch (SecurityException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0028", replace, e); } catch (NoSuchMethodException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0026", replace, e); } catch (IllegalArgumentException e) { Map<String, String> replace = new HashMap<String, String>(1); replace.put("class", clazz.getName()); throw new InternalException(Reflects.class, "E-UTIL#0029", replace, e); } catch (InvocationTargetException e) { throw new TargetThrowsException(Reflects.class, "E-UTIL#0030", e.getCause()); } return t; } private  Reflects(); static Method findMethodSigned(String name, Class<?> target, Class<?>... argumentTypes); static Method findMethodNamed(String name, Class<?> target); static Method findMethodNamed(Pattern pattern, Class<?> target); static Field findFieldNamed(String name, Class<?> target); static Field findFieldNamed(Pattern pattern, Class<?> target); static Constructor<T> findConstructorFor(Class<T> target, Class<?>... argumentTypes); static Object invoke(Method method, Object instance, Object... arguments); static Object read(Field field, Object instance); static void write(Field field, Object instance, Object newValue); static T invoke(Constructor<T> con, Object... arguments); static T make(Class<T> clazz, Object... args); static Method[] findAllMethods(Class<?> clazz); static Field[] findAllFields(Class<?> clazz);  }