@Test public void testConvertNonStringValueOf() throws ArgumentParserException { ReflectArgumentType<NonStringValueOf> at = createRA(NonStringValueOf.class); assertEquals("Good", at.convert(null, null, "Good").arg_); }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (type_.isEnum()) { try { return (T) Enum.valueOf((Class<Enum>) type_, value); } catch (IllegalArgumentException e) { throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); } } Method m = null; try { m = type_.getMethod("valueOf", String.class); } catch (NoSuchMethodException e) { return convertUsingConstructor(parser, arg, value); } catch (SecurityException e) { handleInstantiationError(e); } if (!Modifier.isStatic(m.getModifiers()) || !type_.isAssignableFrom(m.getReturnType())) { return convertUsingConstructor(parser, arg, value); } Object obj = null; try { obj = m.invoke(null, value); } catch (IllegalAccessException e) { return convertUsingConstructor(parser, arg, value); } catch (IllegalArgumentException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { throwArgumentParserException(parser, arg, value, e.getCause() == null ? e : e.getCause()); } return (T) obj; }
ReflectArgumentType implements ArgumentType<T>,
        MetavarInference { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (type_.isEnum()) { try { return (T) Enum.valueOf((Class<Enum>) type_, value); } catch (IllegalArgumentException e) { throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); } } Method m = null; try { m = type_.getMethod("valueOf", String.class); } catch (NoSuchMethodException e) { return convertUsingConstructor(parser, arg, value); } catch (SecurityException e) { handleInstantiationError(e); } if (!Modifier.isStatic(m.getModifiers()) || !type_.isAssignableFrom(m.getReturnType())) { return convertUsingConstructor(parser, arg, value); } Object obj = null; try { obj = m.invoke(null, value); } catch (IllegalAccessException e) { return convertUsingConstructor(parser, arg, value); } catch (IllegalArgumentException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { throwArgumentParserException(parser, arg, value, e.getCause() == null ? e : e.getCause()); } return (T) obj; } }
ReflectArgumentType implements ArgumentType<T>,
        MetavarInference { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (type_.isEnum()) { try { return (T) Enum.valueOf((Class<Enum>) type_, value); } catch (IllegalArgumentException e) { throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); } } Method m = null; try { m = type_.getMethod("valueOf", String.class); } catch (NoSuchMethodException e) { return convertUsingConstructor(parser, arg, value); } catch (SecurityException e) { handleInstantiationError(e); } if (!Modifier.isStatic(m.getModifiers()) || !type_.isAssignableFrom(m.getReturnType())) { return convertUsingConstructor(parser, arg, value); } Object obj = null; try { obj = m.invoke(null, value); } catch (IllegalAccessException e) { return convertUsingConstructor(parser, arg, value); } catch (IllegalArgumentException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { throwArgumentParserException(parser, arg, value, e.getCause() == null ? e : e.getCause()); } return (T) obj; } ReflectArgumentType(Class<T> type); }
ReflectArgumentType implements ArgumentType<T>,
        MetavarInference { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (type_.isEnum()) { try { return (T) Enum.valueOf((Class<Enum>) type_, value); } catch (IllegalArgumentException e) { throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); } } Method m = null; try { m = type_.getMethod("valueOf", String.class); } catch (NoSuchMethodException e) { return convertUsingConstructor(parser, arg, value); } catch (SecurityException e) { handleInstantiationError(e); } if (!Modifier.isStatic(m.getModifiers()) || !type_.isAssignableFrom(m.getReturnType())) { return convertUsingConstructor(parser, arg, value); } Object obj = null; try { obj = m.invoke(null, value); } catch (IllegalAccessException e) { return convertUsingConstructor(parser, arg, value); } catch (IllegalArgumentException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { throwArgumentParserException(parser, arg, value, e.getCause() == null ? e : e.getCause()); } return (T) obj; } ReflectArgumentType(Class<T> type); @Override T convert(ArgumentParser parser, Argument arg, String value); @Override String[] inferMetavar(); }
ReflectArgumentType implements ArgumentType<T>,
        MetavarInference { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { if (type_.isEnum()) { try { return (T) Enum.valueOf((Class<Enum>) type_, value); } catch (IllegalArgumentException e) { throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertChooseFromError"), value, inferMetavar()[0]), parser, arg); } } Method m = null; try { m = type_.getMethod("valueOf", String.class); } catch (NoSuchMethodException e) { return convertUsingConstructor(parser, arg, value); } catch (SecurityException e) { handleInstantiationError(e); } if (!Modifier.isStatic(m.getModifiers()) || !type_.isAssignableFrom(m.getReturnType())) { return convertUsingConstructor(parser, arg, value); } Object obj = null; try { obj = m.invoke(null, value); } catch (IllegalAccessException e) { return convertUsingConstructor(parser, arg, value); } catch (IllegalArgumentException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { throwArgumentParserException(parser, arg, value, e.getCause() == null ? e : e.getCause()); } return (T) obj; } ReflectArgumentType(Class<T> type); @Override T convert(ArgumentParser parser, Argument arg, String value); @Override String[] inferMetavar();  }