From 483f7a87f76d799d7b5fab22d9ab7d4c26ef02e9 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Mon, 2 Mar 2015 09:53:13 -0500 Subject: [PATCH] ConfigBeanImpl.java: split up too-long getValue method --- .../typesafe/config/impl/ConfigBeanImpl.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/config/src/main/java/com/typesafe/config/impl/ConfigBeanImpl.java b/config/src/main/java/com/typesafe/config/impl/ConfigBeanImpl.java index 9d88f284..f23b946a 100644 --- a/config/src/main/java/com/typesafe/config/impl/ConfigBeanImpl.java +++ b/config/src/main/java/com/typesafe/config/impl/ConfigBeanImpl.java @@ -137,33 +137,7 @@ public class ConfigBeanImpl { } else if (parameterClass == Object.class) { return config.getAnyRef(configPropName); } else if (parameterClass == List.class) { - Type elementType = ((ParameterizedType)parameterType).getActualTypeArguments()[0]; - - if (elementType == Boolean.class) { - return config.getBooleanList(configPropName); - } else if (elementType == Integer.class) { - return config.getIntList(configPropName); - } else if (elementType == Double.class) { - return config.getDoubleList(configPropName); - } else if (elementType == Long.class) { - return config.getLongList(configPropName); - } else if (elementType == String.class) { - return config.getStringList(configPropName); - } else if (elementType == Duration.class) { - return config.getDurationList(configPropName); - } else if (elementType == ConfigMemorySize.class) { - return config.getMemorySizeList(configPropName); - } else if (elementType == Object.class) { - return config.getAnyRefList(configPropName); - } else if (elementType == Config.class) { - return config.getConfigList(configPropName); - } else if (elementType == ConfigObject.class) { - return config.getObjectList(configPropName); - } else if (elementType == ConfigValue.class) { - return config.getList(configPropName); - } else { - throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported list element type " + elementType); - } + return getListValue(beanClass, parameterType, parameterClass, config, configPropName); } else if (parameterClass == Map.class) { // we could do better here, but right now we don't. Type[] typeArgs = ((ParameterizedType)parameterType).getActualTypeArguments(); @@ -186,6 +160,36 @@ public class ConfigBeanImpl { } } + private static Object getListValue(Class beanClass, Type parameterType, Class parameterClass, Config config, String configPropName) { + Type elementType = ((ParameterizedType)parameterType).getActualTypeArguments()[0]; + + if (elementType == Boolean.class) { + return config.getBooleanList(configPropName); + } else if (elementType == Integer.class) { + return config.getIntList(configPropName); + } else if (elementType == Double.class) { + return config.getDoubleList(configPropName); + } else if (elementType == Long.class) { + return config.getLongList(configPropName); + } else if (elementType == String.class) { + return config.getStringList(configPropName); + } else if (elementType == Duration.class) { + return config.getDurationList(configPropName); + } else if (elementType == ConfigMemorySize.class) { + return config.getMemorySizeList(configPropName); + } else if (elementType == Object.class) { + return config.getAnyRefList(configPropName); + } else if (elementType == Config.class) { + return config.getConfigList(configPropName); + } else if (elementType == ConfigObject.class) { + return config.getObjectList(configPropName); + } else if (elementType == ConfigValue.class) { + return config.getList(configPropName); + } else { + throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported list element type " + elementType); + } + } + // null if we can't easily say; this is heuristic/best-effort private static ConfigValueType getValueTypeOrNull(Class parameterClass) { if (parameterClass == Boolean.class || parameterClass == boolean.class) {