/** * Finds a registered {@code OptionHandler} by its name or its alias. * @param name name * @return the {@code OptionHandler} or {@code null} */ private OptionHandler findOptionByName(String name) { for (OptionHandler h : options) { NamedOptionDef option = (NamedOptionDef)h.option; if (name.equals(option.name())) { return h; } for (String alias : option.aliases()) { if (name.equals(alias)) { return h; } } } return null; }
/** * @return {@code true} if all options required by {@code option} are present, {@code false} otherwise */ private boolean isHandlerHasHisOptions(NamedOptionDef option, Set<OptionHandler> present) { for (String depend : option.depends()) { if (!present.contains(findOptionHandler(depend))) return false; } return true; }
/** * @return {@code true} if all options forbid by {@code option} are not present, {@code false} otherwise */ private boolean isHandlerAllowOtherOptions(NamedOptionDef option, Set<OptionHandler> present) { for (String forbid : option.forbids()) { if (present.contains(findOptionHandler(forbid))) return false; } return true; }
private void checkRequiredOptionsAndArguments(Set<OptionHandler> present) throws CmdLineException { // make sure that all mandatory options are present for (OptionHandler handler : options) { if(handler.option.required() && !present.contains(handler)) { throw new CmdLineException(this, Messages.REQUIRED_OPTION_MISSING, handler.option.toString()); } } // make sure that all mandatory arguments are present for (OptionHandler handler : arguments) { if(handler.option.required() && !present.contains(handler)) { throw new CmdLineException(this, Messages.REQUIRED_ARGUMENT_MISSING, handler.option.toString()); } } //make sure that all requires arguments are present for (OptionHandler handler : present) { if (handler.option instanceof NamedOptionDef && !isHandlerHasHisOptions((NamedOptionDef)handler.option, present)) { throw new CmdLineException(this, Messages.REQUIRES_OPTION_MISSING, handler.option.toString(), Arrays.toString(((NamedOptionDef)handler.option).depends())); } } //make sure that all forbids arguments are not present for (OptionHandler handler : present) { if (handler.option instanceof NamedOptionDef && !isHandlerAllowOtherOptions((NamedOptionDef) handler.option, present)) { throw new CmdLineException(this, Messages.FORBIDDEN_OPTION_PRESENT, handler.option.toString(), Arrays.toString(((NamedOptionDef) handler.option).forbids())); } } }
public NamedOptionDef(Option o) { super(o.usage(),o.metaVar(),o.required(),o.help(),o.hidden(),o.handler(),false); this.name = o.name(); this.aliases = createZeroSizedArrayIfNull(o.aliases()); this.depends = createZeroSizedArrayIfNull(o.depends()); this.forbids = createZeroSizedArrayIfNull(o.forbids()); }
/** * Programmatically defines an option (instead of reading it from annotations as normal). * * @param setter the setter for the type * @param o the {@code Option} * @throws NullPointerException if {@code setter} or {@code o} is {@code null}. * @throws IllegalAnnotationError if the option name or one of the aliases is already taken. */ public void addOption(Setter setter, Option o) { checkNonNull(setter, "Setter"); checkNonNull(o, "Option"); checkOptionNotInMap(o.name()); for (String alias : o.aliases()) { checkOptionNotInMap(alias); } options.add(createOptionHandler(new NamedOptionDef(o), setter)); }
private void checkRequiredOptionsAndArguments(Set<OptionHandler> present) throws CmdLineException { // make sure that all mandatory options are present for (OptionHandler handler : options) { if(handler.option.required() && !present.contains(handler)) { throw new CmdLineException(this, Messages.REQUIRED_OPTION_MISSING, handler.option.toString()); } } // make sure that all mandatory arguments are present for (OptionHandler handler : arguments) { if(handler.option.required() && !present.contains(handler)) { throw new CmdLineException(this, Messages.REQUIRED_ARGUMENT_MISSING, handler.option.toString()); } } //make sure that all requires arguments are present for (OptionHandler handler : present) { if (handler.option instanceof NamedOptionDef && !isHandlerHasHisOptions((NamedOptionDef)handler.option, present)) { throw new CmdLineException(this, Messages.REQUIRES_OPTION_MISSING, handler.option.toString(), Arrays.toString(((NamedOptionDef)handler.option).depends())); } } //make sure that all forbids arguments are not present for (OptionHandler handler : present) { if (handler.option instanceof NamedOptionDef && !isHandlerAllowOtherOptions((NamedOptionDef) handler.option, present)) { throw new CmdLineException(this, Messages.FORBIDDEN_OPTION_PRESENT, handler.option.toString(), Arrays.toString(((NamedOptionDef) handler.option).forbids())); } } }
public NamedOptionDef(Option o) { super(o.usage(),o.metaVar(),o.required(),o.help(),o.hidden(),o.handler(),false); this.name = o.name(); this.aliases = createZeroSizedArrayIfNull(o.aliases()); this.depends = createZeroSizedArrayIfNull(o.depends()); this.forbids = createZeroSizedArrayIfNull(o.forbids()); }
/** * Programmatically defines an option (instead of reading it from annotations as normal). * * @param setter the setter for the type * @param o the {@code Option} * @throws NullPointerException if {@code setter} or {@code o} is {@code null}. * @throws IllegalAnnotationError if the option name or one of the aliases is already taken. */ public void addOption(Setter setter, Option o) { checkNonNull(setter, "Setter"); checkNonNull(o, "Option"); checkOptionNotInMap(o.name()); for (String alias : o.aliases()) { checkOptionNotInMap(alias); } options.add(createOptionHandler(new NamedOptionDef(o), setter)); }
/** * Finds a registered {@code OptionHandler} by its name or its alias. * @param name name * @return the {@code OptionHandler} or {@code null} */ private OptionHandler findOptionByName(String name) { for (OptionHandler h : options) { NamedOptionDef option = (NamedOptionDef)h.option; if (name.equals(option.name())) { return h; } for (String alias : option.aliases()) { if (name.equals(alias)) { return h; } } } return null; }
@Override Module parseItem(String item) { return instantiateObject( ((NamedOptionDef) option).name(), "plugin module", Module.class, ((SoyCmdLineParser) this.owner).pluginLoader, item); } }
private void checkRequiredOptionsAndArguments(Set<OptionHandler> present) throws CmdLineException { // make sure that all mandatory options are present for (OptionHandler handler : options) { if(handler.option.required() && !present.contains(handler)) { throw new CmdLineException(this, Messages.REQUIRED_OPTION_MISSING, handler.option.toString()); } } // make sure that all mandatory arguments are present for (OptionHandler handler : arguments) { if(handler.option.required() && !present.contains(handler)) { throw new CmdLineException(this, Messages.REQUIRED_ARGUMENT_MISSING, handler.option.toString()); } } //make sure that all requires arguments are present for (OptionHandler handler : present) { if (handler.option instanceof NamedOptionDef && !isHandlerHasHisOptions((NamedOptionDef)handler.option, present)) { throw new CmdLineException(this, Messages.REQUIRES_OPTION_MISSING, handler.option.toString(), Arrays.toString(((NamedOptionDef)handler.option).depends())); } } //make sure that all forbids arguments are not present for (OptionHandler handler : present) { if (handler.option instanceof NamedOptionDef && !isHandlerAllowOtherOptions((NamedOptionDef) handler.option, present)) { throw new CmdLineException(this, Messages.FORBIDDEN_OPTION_PRESENT, handler.option.toString(), Arrays.toString(((NamedOptionDef) handler.option).forbids())); } } }
/** * @return {@code true} if all options forbid by {@code option} are not present, {@code false} otherwise */ private boolean isHandlerAllowOtherOptions(NamedOptionDef option, Set<OptionHandler> present) { for (String forbid : option.forbids()) { if (present.contains(findOptionHandler(forbid))) return false; } return true; }
/** * @return {@code true} if all options required by {@code option} are present, {@code false} otherwise */ private boolean isHandlerHasHisOptions(NamedOptionDef option, Set<OptionHandler> present) { for (String depend : option.depends()) { if (!present.contains(findOptionHandler(depend))) return false; } return true; }
public NamedOptionDef(Option o) { super(o.usage(),o.metaVar(),o.required(),o.help(),o.hidden(),o.handler(),false); this.name = o.name(); this.aliases = createZeroSizedArrayIfNull(o.aliases()); this.depends = createZeroSizedArrayIfNull(o.depends()); this.forbids = createZeroSizedArrayIfNull(o.forbids()); }
/** * Programmatically defines an option (instead of reading it from annotations as normal). * * @param setter the setter for the type * @param o the {@code Option} * @throws NullPointerException if {@code setter} or {@code o} is {@code null}. * @throws IllegalAnnotationError if the option name or one of the aliases is already taken. */ public void addOption(Setter setter, Option o) { checkNonNull(setter, "Setter"); checkNonNull(o, "Option"); checkOptionNotInMap(o.name()); for (String alias : o.aliases()) { checkOptionNotInMap(alias); } options.add(createOptionHandler(new NamedOptionDef(o), setter)); }
/** * Finds a registered {@code OptionHandler} by its name or its alias. * @param name name * @return the {@code OptionHandler} or {@code null} */ private OptionHandler findOptionByName(String name) { for (OptionHandler h : options) { NamedOptionDef option = (NamedOptionDef)h.option; if (name.equals(option.name())) { return h; } for (String alias : option.aliases()) { if (name.equals(alias)) { return h; } } } return null; }
@Override Module parseItem(String item) { return instantiateObject( ((NamedOptionDef) option).name(), "plugin module", Module.class, ((SoyCmdLineParser) this.owner).pluginLoader, item); } }