public OptionHandler<?> getHandler(CmdLineParser parser, OptionDef o, Setter setter) { try { return cons.newInstance(parser, o, setter); } catch (InstantiationException e) { throw new IllegalAnnotationError(e); } catch (IllegalAccessException e) { throw new IllegalAnnotationError(e); } catch (InvocationTargetException e) { throw new IllegalAnnotationError(e); } } }
public OptionHandler<?> getHandler(CmdLineParser parser, OptionDef o, Setter setter) { try { return cons.newInstance(parser, o, setter); } catch (InstantiationException e) { throw new IllegalAnnotationError(e); } catch (IllegalAccessException e) { throw new IllegalAnnotationError(e); } catch (InvocationTargetException e) { throw new IllegalAnnotationError(e); } } }
private void doAddValue(Object bean, Object value) throws IllegalAccessException { Object o = f.get(bean); if(o==null) { o = new ArrayList(); f.set(bean,o); } if(!(o instanceof List)) throw new IllegalAnnotationError(Messages.ILLEGAL_LIST.format(f)); ((List)o).add(value); }
private void doAddValue(Object bean, Object value) throws IllegalAccessException { Object o = f.get(bean); if(o==null) { o = new ArrayList(); f.set(bean,o); } if(!(o instanceof List)) throw new IllegalAnnotationError(Messages.ILLEGAL_LIST.format(f)); ((List)o).add(value); }
public MethodSetter(CmdLineParser parser, Object bean, Method m) { this.parser = parser; this.bean = bean; this.m = m; if(m.getParameterTypes().length!=1) throw new IllegalAnnotationError(Messages.ILLEGAL_METHOD_SIGNATURE.format(m)); }
public MethodSetter(CmdLineParser parser, Object bean, Method m) { this.parser = parser; this.bean = bean; this.m = m; if(m.getParameterTypes().length!=1) throw new IllegalAnnotationError(Messages.ILLEGAL_METHOD_SIGNATURE.format(m)); }
public MultiValueFieldSetter(Object bean, Field f) { this.bean = bean; this.f = f; if(!List.class.isAssignableFrom(f.getType())) throw new IllegalAnnotationError(Messages.ILLEGAL_FIELD_SIGNATURE.format(f.getType())); }
public MultiValueFieldSetter(Object bean, Field f) { this.bean = bean; this.f = f; if(!List.class.isAssignableFrom(f.getType())) throw new IllegalAnnotationError(Messages.ILLEGAL_FIELD_SIGNATURE.format(f.getType())); }
public ArrayFieldSetter(Object bean, Field f) { this.bean = bean; this.f = f; if(!f.getType().isArray()) throw new IllegalAnnotationError(Messages.ILLEGAL_FIELD_SIGNATURE.format(f.getType())); trySetDefault(bean); }
public ArrayFieldSetter(Object bean, Field f) { this.bean = bean; this.f = f; if(!f.getType().isArray()) throw new IllegalAnnotationError(Messages.ILLEGAL_FIELD_SIGNATURE.format(f.getType())); trySetDefault(bean); }
private void checkOptionNotInMap(String name) throws IllegalAnnotationError { checkNonNull(name, "name"); if(findOptionByName(name)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_OPTION.format(name)); } }
private void checkOptionNotInMap(String name) throws IllegalAnnotationError { checkNonNull(name, "name"); if(findOptionByName(name)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_OPTION.format(name)); } }
/** * Programmatically defines an argument (instead of reading it from annotations as normal). * * @param setter the setter for the type * @param a the Argument * @throws NullPointerException if {@code setter} or {@code a} is {@code null}. */ public void addArgument(Setter setter, Argument a) { checkNonNull(setter, "Setter"); checkNonNull(a, "Argument"); OptionHandler h = createOptionHandler(new OptionDef(a,setter.isMultiValued()),setter); int index = a.index(); // make sure the argument will fit in the list while (index >= arguments.size()) { arguments.add(null); } if(arguments.get(index)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_ARGUMENT.format(index)); } arguments.set(index, h); }
/** * Programmatically defines an argument (instead of reading it from annotations as normal). * * @param setter the setter for the type * @param a the Argument * @throws NullPointerException if {@code setter} or {@code a} is {@code null}. */ public void addArgument(Setter setter, Argument a) { checkNonNull(setter, "Setter"); checkNonNull(a, "Argument"); OptionHandler h = createOptionHandler(new OptionDef(a,setter.isMultiValued()),setter); int index = a.index(); // make sure the argument will fit in the list while (index >= arguments.size()) { arguments.add(null); } if(arguments.get(index)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_ARGUMENT.format(index)); } arguments.set(index, h); }
/** * Creates an {@link OptionHandler} that handles the given {@link Option} annotation * and the {@link Setter} instance. */ @SuppressWarnings("unchecked") protected OptionHandler createOptionHandler(CmdLineParser parser, OptionDef o, Setter setter) { checkNonNull(o, "CmdLineParser"); checkNonNull(o, "OptionDef"); checkNonNull(setter, "Setter"); Class<? extends OptionHandler> h = o.handler(); if(h==OptionHandler.class) { // infer the type Class<?> t = setter.getType(); // enum is the special case if(Enum.class.isAssignableFrom(t)) return new EnumOptionHandler(parser,o,setter,t); OptionHandlerFactory factory = handlers.get(t); if (factory==null) throw new IllegalAnnotationError(Messages.UNKNOWN_HANDLER.format(t)); return factory.getHandler(parser, o, setter); } else { // explicit handler specified return new DefaultConstructorHandlerFactory(h).getHandler(parser, o, setter); } }
/** * Creates an {@link OptionHandler} that handles the given {@link Option} annotation * and the {@link Setter} instance. */ @SuppressWarnings("unchecked") protected OptionHandler createOptionHandler(CmdLineParser parser, OptionDef o, Setter setter) { checkNonNull(o, "CmdLineParser"); checkNonNull(o, "OptionDef"); checkNonNull(setter, "Setter"); Class<? extends OptionHandler> h = o.handler(); if(h==OptionHandler.class) { // infer the type Class<?> t = setter.getType(); // enum is the special case if(Enum.class.isAssignableFrom(t)) return new EnumOptionHandler(parser,o,setter,t); OptionHandlerFactory factory = handlers.get(t); if (factory==null) throw new IllegalAnnotationError(Messages.UNKNOWN_HANDLER.format(t)); return factory.getHandler(parser, o, setter); } else { // explicit handler specified return new DefaultConstructorHandlerFactory(h).getHandler(parser, o, setter); } }
public OptionHandler<?> getHandler(CmdLineParser parser, OptionDef o, Setter setter) { try { return cons.newInstance(parser, o, setter); } catch (InstantiationException e) { throw new IllegalAnnotationError(e); } catch (IllegalAccessException e) { throw new IllegalAnnotationError(e); } catch (InvocationTargetException e) { throw new IllegalAnnotationError(e); } } }
public OptionHandler<?> getHandler(CmdLineParser parser, OptionDef o, Setter setter) { try { return cons.newInstance(parser, o, setter); } catch (InstantiationException e) { throw new IllegalAnnotationError(e); } catch (IllegalAccessException e) { throw new IllegalAnnotationError(e); } catch (InvocationTargetException e) { throw new IllegalAnnotationError(e); } } }
private String extractType(String url) { int idx = url.lastIndexOf(StringConst.FW_SLASH) + 1; if (idx >= url.length()) throw new IllegalAnnotationError(url); return url.substring(idx); }
private String extractType(String url) { int idx = url.lastIndexOf(StringConst.FW_SLASH) + 1; if (idx >= url.length()) throw new IllegalAnnotationError(url); return url.substring(idx); }