@Test public void getDriverClass() throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { List<Map<String, Object>> configs = PluginConfigFactory.getPluginConfigDefaultValues(TestConfigs.TestDefaultValueConfig.class); List<Map> mapList = Arrays.asList(MutableMap.of("key", "name", "description", "", "default", "sylph"), MutableMap.of("key", "age", "description", "this is age", "default", "")); Assert.assertEquals(configs, mapList); }
public static List<Map<String, Object>> getPluginConfigDefaultValues(Class<? extends PluginConfig> configClass) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { PluginConfig pluginConfig = pluginConfigInstance(configClass); List<Map<String, Object>> mapList = new ArrayList<>(); for (Field field : configClass.getDeclaredFields()) { Name name = field.getAnnotation(Name.class); if (name == null) { continue; } Description description = field.getAnnotation(Description.class); field.setAccessible(true); Object defaultValue = field.get(pluginConfig); Map<String, Object> fieldConfig = MutableMap.of( "key", name.value(), "description", description == null ? "" : description.value(), "default", defaultValue == null ? "" : defaultValue); mapList.add(fieldConfig); } return mapList; }
PluginConfigFactory { public static List<Map<String, Object>> getPluginConfigDefaultValues(Class<? extends PluginConfig> configClass) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { PluginConfig pluginConfig = pluginConfigInstance(configClass); List<Map<String, Object>> mapList = new ArrayList<>(); for (Field field : configClass.getDeclaredFields()) { Name name = field.getAnnotation(Name.class); if (name == null) { continue; } Description description = field.getAnnotation(Description.class); field.setAccessible(true); Object defaultValue = field.get(pluginConfig); Map<String, Object> fieldConfig = MutableMap.of( "key", name.value(), "description", description == null ? "" : description.value(), "default", defaultValue == null ? "" : defaultValue); mapList.add(fieldConfig); } return mapList; } }
PluginConfigFactory { public static List<Map<String, Object>> getPluginConfigDefaultValues(Class<? extends PluginConfig> configClass) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { PluginConfig pluginConfig = pluginConfigInstance(configClass); List<Map<String, Object>> mapList = new ArrayList<>(); for (Field field : configClass.getDeclaredFields()) { Name name = field.getAnnotation(Name.class); if (name == null) { continue; } Description description = field.getAnnotation(Description.class); field.setAccessible(true); Object defaultValue = field.get(pluginConfig); Map<String, Object> fieldConfig = MutableMap.of( "key", name.value(), "description", description == null ? "" : description.value(), "default", defaultValue == null ? "" : defaultValue); mapList.add(fieldConfig); } return mapList; } private  PluginConfigFactory(); }
PluginConfigFactory { public static List<Map<String, Object>> getPluginConfigDefaultValues(Class<? extends PluginConfig> configClass) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { PluginConfig pluginConfig = pluginConfigInstance(configClass); List<Map<String, Object>> mapList = new ArrayList<>(); for (Field field : configClass.getDeclaredFields()) { Name name = field.getAnnotation(Name.class); if (name == null) { continue; } Description description = field.getAnnotation(Description.class); field.setAccessible(true); Object defaultValue = field.get(pluginConfig); Map<String, Object> fieldConfig = MutableMap.of( "key", name.value(), "description", description == null ? "" : description.value(), "default", defaultValue == null ? "" : defaultValue); mapList.add(fieldConfig); } return mapList; } private  PluginConfigFactory(); T createPluginConfig(Class<T> type, Map<String, Object> config); static T pluginConfigInstance(Class<T> type); @SuppressWarnings("unchecked") static void injectConfig(T pluginConfig, Map<String, Object> config); static List<Map<String, Object>> getPluginConfigDefaultValues(Class<? extends PluginConfig> configClass); }
PluginConfigFactory { public static List<Map<String, Object>> getPluginConfigDefaultValues(Class<? extends PluginConfig> configClass) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { PluginConfig pluginConfig = pluginConfigInstance(configClass); List<Map<String, Object>> mapList = new ArrayList<>(); for (Field field : configClass.getDeclaredFields()) { Name name = field.getAnnotation(Name.class); if (name == null) { continue; } Description description = field.getAnnotation(Description.class); field.setAccessible(true); Object defaultValue = field.get(pluginConfig); Map<String, Object> fieldConfig = MutableMap.of( "key", name.value(), "description", description == null ? "" : description.value(), "default", defaultValue == null ? "" : defaultValue); mapList.add(fieldConfig); } return mapList; } private  PluginConfigFactory(); T createPluginConfig(Class<T> type, Map<String, Object> config); static T pluginConfigInstance(Class<T> type); @SuppressWarnings("unchecked") static void injectConfig(T pluginConfig, Map<String, Object> config); static List<Map<String, Object>> getPluginConfigDefaultValues(Class<? extends PluginConfig> configClass); static final PluginConfigFactory INSTANCE; }