@Test(expected = ArgumentParserException.class) public void testConvert() throws ArgumentParserException { ArgumentParser ap = ArgumentParsers.newFor("argparse4j").build(); ConstructorArgumentType<Integer> at = new ConstructorArgumentType<Integer>(Integer.class); assertEquals((Integer)100, at.convert(null, null, "100")); at.convert(ap, new MockArgument(), "0x100"); }
@Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { T obj = null; try { obj = type_.getConstructor(String.class).newInstance(value); } catch (InstantiationException e) { handleInstantiationError(e); } catch (IllegalAccessException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } catch (NoSuchMethodException e) { handleInstantiationError(e); } return obj; }
ConstructorArgumentType implements ArgumentType<T> { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { T obj = null; try { obj = type_.getConstructor(String.class).newInstance(value); } catch (InstantiationException e) { handleInstantiationError(e); } catch (IllegalAccessException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } catch (NoSuchMethodException e) { handleInstantiationError(e); } return obj; } }
ConstructorArgumentType implements ArgumentType<T> { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { T obj = null; try { obj = type_.getConstructor(String.class).newInstance(value); } catch (InstantiationException e) { handleInstantiationError(e); } catch (IllegalAccessException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } catch (NoSuchMethodException e) { handleInstantiationError(e); } return obj; } ConstructorArgumentType(Class<T> type); }
ConstructorArgumentType implements ArgumentType<T> { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { T obj = null; try { obj = type_.getConstructor(String.class).newInstance(value); } catch (InstantiationException e) { handleInstantiationError(e); } catch (IllegalAccessException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } catch (NoSuchMethodException e) { handleInstantiationError(e); } return obj; } ConstructorArgumentType(Class<T> type); @Override T convert(ArgumentParser parser, Argument arg, String value); }
ConstructorArgumentType implements ArgumentType<T> { @Override public T convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException { T obj = null; try { obj = type_.getConstructor(String.class).newInstance(value); } catch (InstantiationException e) { handleInstantiationError(e); } catch (IllegalAccessException e) { handleInstantiationError(e); } catch (InvocationTargetException e) { String localizedTypeName = localizeTypeNameIfPossible(parser, type_); throw new ArgumentParserException( String.format(TextHelper.LOCALE_ROOT, MessageLocalization.localize( parser.getConfig().getResourceBundle(), "couldNotConvertToError"), value, localizedTypeName), e.getCause(), parser, arg); } catch (NoSuchMethodException e) { handleInstantiationError(e); } return obj; } ConstructorArgumentType(Class<T> type); @Override T convert(ArgumentParser parser, Argument arg, String value);  }