From 941eba6f285312b7572b47e561380bec8b282e73 Mon Sep 17 00:00:00 2001 From: Rafael Zubairov Date: Sat, 16 Jan 2016 15:35:25 -0800 Subject: [PATCH 1/2] Update to use latest commons-lang, to make jmxterm to be able to work with Java8 jvm --- pom.xml | 8 +- .../cyclopsgroup/jcli/ValidationResult.java | 2 +- .../jcli/example/UserControl.java | 2 +- .../jcli/impl/AnnotationOption.java | 4 +- .../jcli/impl/DefaultHelpPrinter.java | 2 +- .../cyclopsgroup/jcli/impl/OptionHelp.java | 2 +- .../org/cyclopsgroup/jcli/impl/Reference.java | 2 +- .../cyclopsgroup/jcli/jline/CliCompletor.java | 346 ++++++++---------- .../cyclopsgroup/jcli/spi/CommandLine.java | 2 +- .../java/org/cyclopsgroup/jcli/Simple.java | 2 +- 10 files changed, 164 insertions(+), 208 deletions(-) diff --git a/pom.xml b/pom.xml index 92edd20..a989465 100644 --- a/pom.xml +++ b/pom.xml @@ -27,9 +27,9 @@ 1.7.0 - commons-lang - commons-lang - 2.4 + org.apache.commons + commons-lang3 + 3.4 commons-logging @@ -39,7 +39,7 @@ org.cyclopsgroup caff - 0.3 + 0.4.0 jline diff --git a/src/main/java/org/cyclopsgroup/jcli/ValidationResult.java b/src/main/java/org/cyclopsgroup/jcli/ValidationResult.java index 4cacc43..576bbd4 100644 --- a/src/main/java/org/cyclopsgroup/jcli/ValidationResult.java +++ b/src/main/java/org/cyclopsgroup/jcli/ValidationResult.java @@ -4,7 +4,7 @@ import java.util.Collections; import java.util.List; -import org.apache.commons.lang.Validate; +import org.apache.commons.lang3.Validate; /** * Argument validation result coming from {@link ArgumentProcessor#validate(String[])} diff --git a/src/main/java/org/cyclopsgroup/jcli/example/UserControl.java b/src/main/java/org/cyclopsgroup/jcli/example/UserControl.java index bcfaa77..6308c5a 100644 --- a/src/main/java/org/cyclopsgroup/jcli/example/UserControl.java +++ b/src/main/java/org/cyclopsgroup/jcli/example/UserControl.java @@ -3,7 +3,7 @@ import java.util.Date; import java.util.List; -import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; import org.cyclopsgroup.caff.conversion.DateField; import org.cyclopsgroup.jcli.ArgumentProcessor; import org.cyclopsgroup.jcli.annotation.Argument; diff --git a/src/main/java/org/cyclopsgroup/jcli/impl/AnnotationOption.java b/src/main/java/org/cyclopsgroup/jcli/impl/AnnotationOption.java index b2564cc..e132dd1 100644 --- a/src/main/java/org/cyclopsgroup/jcli/impl/AnnotationOption.java +++ b/src/main/java/org/cyclopsgroup/jcli/impl/AnnotationOption.java @@ -1,7 +1,7 @@ package org.cyclopsgroup.jcli.impl; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; import org.cyclopsgroup.jcli.annotation.Option; class AnnotationOption diff --git a/src/main/java/org/cyclopsgroup/jcli/impl/DefaultHelpPrinter.java b/src/main/java/org/cyclopsgroup/jcli/impl/DefaultHelpPrinter.java index a4d5b27..7e69f4a 100644 --- a/src/main/java/org/cyclopsgroup/jcli/impl/DefaultHelpPrinter.java +++ b/src/main/java/org/cyclopsgroup/jcli/impl/DefaultHelpPrinter.java @@ -3,7 +3,7 @@ import java.io.IOException; import java.io.PrintWriter; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.cyclopsgroup.caff.format.Format; import org.cyclopsgroup.caff.format.Formats; import org.cyclopsgroup.jcli.spi.Option; diff --git a/src/main/java/org/cyclopsgroup/jcli/impl/OptionHelp.java b/src/main/java/org/cyclopsgroup/jcli/impl/OptionHelp.java index 0e72d8c..4715b5e 100644 --- a/src/main/java/org/cyclopsgroup/jcli/impl/OptionHelp.java +++ b/src/main/java/org/cyclopsgroup/jcli/impl/OptionHelp.java @@ -1,6 +1,6 @@ package org.cyclopsgroup.jcli.impl; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.cyclopsgroup.caff.format.FixLengthField; import org.cyclopsgroup.caff.format.FixLengthType; import org.cyclopsgroup.jcli.spi.Option; diff --git a/src/main/java/org/cyclopsgroup/jcli/impl/Reference.java b/src/main/java/org/cyclopsgroup/jcli/impl/Reference.java index 7652a87..2ff8435 100644 --- a/src/main/java/org/cyclopsgroup/jcli/impl/Reference.java +++ b/src/main/java/org/cyclopsgroup/jcli/impl/Reference.java @@ -1,6 +1,6 @@ package org.cyclopsgroup.jcli.impl; -import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; import org.cyclopsgroup.caff.conversion.Converter; import org.cyclopsgroup.caff.ref.ValueReference; diff --git a/src/main/java/org/cyclopsgroup/jcli/jline/CliCompletor.java b/src/main/java/org/cyclopsgroup/jcli/jline/CliCompletor.java index 7191978..1abfd24 100644 --- a/src/main/java/org/cyclopsgroup/jcli/jline/CliCompletor.java +++ b/src/main/java/org/cyclopsgroup/jcli/jline/CliCompletor.java @@ -9,8 +9,8 @@ import jline.console.completer.Completer; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.Validate; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.Validate; import org.cyclopsgroup.caff.token.TokenEvent; import org.cyclopsgroup.caff.token.TokenEventHandler; import org.cyclopsgroup.caff.token.ValueTokenizer; @@ -25,215 +25,171 @@ * @author Jiaqi Guo */ public class CliCompletor - implements Completer -{ - private static List filterList( List list, String prefix ) - { - if ( StringUtils.isEmpty( prefix ) || list == null ) - { - return list; - } - List results = new ArrayList(); - for ( String item : list ) - { - if ( item.startsWith( prefix ) ) - { - results.add( item ); - } - } - return results; + implements Completer { + private static List filterList(List list, String prefix) { + if (StringUtils.isEmpty(prefix) || list == null) { + return list; + } + List results = new ArrayList(); + for (String item : list) { + if (item.startsWith(prefix)) { + results.add(item); + } } + return results; + } - private final ParsingContext context; + private final ParsingContext context; - private final AutoCompletable completable; + private final AutoCompletable completable; - private final ValueTokenizer tokenizer; + private final ValueTokenizer tokenizer; - /** - * @param cliBean Entyped AutoCompletable implementation or an normal bean - * @param tokenizer Tokenizer for argument parsing - * @throws IntrospectionException - */ - public CliCompletor( final Object cliBean, final ValueTokenizer tokenizer ) - { - Validate.notNull( cliBean, "Cli bean can't be NULL" ); - Validate.notNull( tokenizer, "String tokenizer can't be NULL" ); - context = - ArgumentProcessor.newInstance( cliBean.getClass() ).createParsingContext(); - if ( cliBean instanceof AutoCompletable ) - { - this.completable = (AutoCompletable) cliBean; + /** + * @param cliBean Entyped AutoCompletable implementation or an normal bean + * @param tokenizer Tokenizer for argument parsing + * @throws IntrospectionException + */ + public CliCompletor(final Object cliBean, final ValueTokenizer tokenizer) { + Validate.notNull(cliBean, "Cli bean can't be NULL"); + Validate.notNull(tokenizer, "String tokenizer can't be NULL"); + context = + ArgumentProcessor.newInstance(cliBean.getClass()).createParsingContext(); + if (cliBean instanceof AutoCompletable) { + this.completable = (AutoCompletable) cliBean; + } else { + this.completable = new AutoCompletable() { + public List suggestArgument(String partialArgument) { + return Collections.emptyList(); } - else - { - this.completable = new AutoCompletable() - { - public List suggestArgument( String partialArgument ) - { - return Collections.emptyList(); - } - public List suggestOption( String optionName, - String partialOption ) - { - return Collections.emptyList(); - } - }; + public List suggestOption(String optionName, + String partialOption) { + return Collections.emptyList(); } - this.tokenizer = tokenizer; + }; } + this.tokenizer = tokenizer; + } - /** - * @inheritDoc - */ - @SuppressWarnings( { "unchecked", "rawtypes" } ) - public int complete( final String command, final int cursor, - final List suggestions ) - { - ArgumentsInspector inspector = new ArgumentsInspector( context ); - final AtomicBoolean terminated = new AtomicBoolean( true ); - final AtomicInteger lastWordStart = new AtomicInteger( 0 ); - if ( StringUtils.isNotEmpty( command ) ) - { - final List args = new ArrayList(); - tokenizer.parse( command, new TokenEventHandler() - { + /** + * @inheritDoc + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + public int complete(final String command, final int cursor, + final List suggestions) { + ArgumentsInspector inspector = new ArgumentsInspector(context); + final AtomicBoolean terminated = new AtomicBoolean(true); + final AtomicInteger lastWordStart = new AtomicInteger(0); + if (StringUtils.isNotEmpty(command)) { + final List args = new ArrayList(); + tokenizer.parse(command, new TokenEventHandler() { - public void handleEvent( TokenEvent ev ) - { - args.add( ev.getToken() ); - terminated.set( ev.isTerminated() ); - lastWordStart.set( ev.getStart() ); - } - } ); - for ( String arg : args ) - { - inspector.consume( arg ); - } - if ( terminated.get() ) - { - inspector.end(); - } - } - // System.err.println( "command=[" + command + "], cursor=" + cursor + - // ", state=" + inspector.getState().name() - // + ", value=" + inspector.getCurrentValue() ); - List candidates = new ArrayList(); - switch ( inspector.getState() ) - { - case READY: - for ( Option o : inspector.getRemainingOptions() ) - { - candidates.add( "-" + o.getName() ); - } - Collections.sort( candidates ); - candidates.addAll( suggestArguments( null ) ); - break; - case OPTION: - case LONG_OPTION: - candidates.addAll( suggestOptionNames( inspector, - inspector.getCurrentValue() ) ); - break; - case OPTION_VALUE: - candidates.addAll( suggestOptionValue( inspector.getCurrentOption(), - inspector.getCurrentValue() ) ); - break; - case ARGUMENT: - candidates.addAll( suggestArguments( inspector.getCurrentValue() ) ); - } - for ( String candidate : candidates ) - { - suggestions.add( tokenizer.escape( candidate ) ); - } - if ( StringUtils.isEmpty( command ) ) - { - return 0; - } - if ( terminated.get() ) - { - return cursor; - } - return lastWordStart.get(); + public void handleEvent(TokenEvent ev) { + args.add(ev.getToken()); + terminated.set(ev.isTerminated()); + lastWordStart.set(ev.getStart()); + } + }); + for (String arg : args) { + inspector.consume(arg); + } + if (terminated.get()) { + inspector.end(); + } + } + // System.err.println( "command=[" + command + "], cursor=" + cursor + + // ", state=" + inspector.getState().name() + // + ", value=" + inspector.getCurrentValue() ); + List candidates = new ArrayList(); + switch (inspector.getState()) { + case READY: + for (Option o : inspector.getRemainingOptions()) { + candidates.add("-" + o.getName()); + } + Collections.sort(candidates); + candidates.addAll(suggestArguments(null)); + break; + case OPTION: + case LONG_OPTION: + candidates.addAll(suggestOptionNames(inspector, + inspector.getCurrentValue())); + break; + case OPTION_VALUE: + candidates.addAll(suggestOptionValue(inspector.getCurrentOption(), + inspector.getCurrentValue())); + break; + case ARGUMENT: + candidates.addAll(suggestArguments(inspector.getCurrentValue())); + } + for (String candidate : candidates) { + suggestions.add(tokenizer.escape(candidate)); + } + if (StringUtils.isEmpty(command)) { + return 0; + } + if (terminated.get()) { + return cursor; } + return lastWordStart.get(); + } - private List suggestArguments( String partialArgument ) - { - List results; - if ( StringUtils.isEmpty( partialArgument ) ) - { - results = completable.suggestArgument( null ); - } - else - { - results = completable.suggestArgument( partialArgument ); - if ( results == null ) - { - results = - filterList( completable.suggestArgument( null ), - partialArgument ); - } - } - if ( results == null ) - { - results = Collections.emptyList(); - } - else - { - results = new ArrayList( results ); - Collections.sort( results ); - } - return results; + private List suggestArguments(String partialArgument) { + List results; + if (StringUtils.isEmpty(partialArgument)) { + results = completable.suggestArgument(null); + } else { + results = completable.suggestArgument(partialArgument); + if (results == null) { + results = + filterList(completable.suggestArgument(null), + partialArgument); + } + } + if (results == null) { + results = Collections.emptyList(); + } else { + results = new ArrayList(results); + Collections.sort(results); } + return results; + } - private List suggestOptionNames( ArgumentsInspector inspector, - String value ) - { - List results = new ArrayList(); - for ( Option o : inspector.getRemainingOptions() ) - { - if ( value.startsWith( "--" ) && o.getLongName() != null - && ( "--" + o.getLongName() ).startsWith( value ) ) - { - results.add( "--" + o.getLongName() ); - } - else if ( value.startsWith( "-" ) - && ( "-" + o.getName() ).startsWith( value ) ) - { - results.add( "-" + o.getName() ); - } - } - Collections.sort( results ); - return results; + private List suggestOptionNames(ArgumentsInspector inspector, + String value) { + List results = new ArrayList(); + for (Option o : inspector.getRemainingOptions()) { + if (value.startsWith("--") && o.getLongName() != null + && ("--" + o.getLongName()).startsWith(value)) { + results.add("--" + o.getLongName()); + } else if (value.startsWith("-") + && ("-" + o.getName()).startsWith(value)) { + results.add("-" + o.getName()); + } } + Collections.sort(results); + return results; + } - private List suggestOptionValue( Option option, String partialValue ) - { - List results; - if ( StringUtils.isEmpty( partialValue ) ) - { - results = completable.suggestOption( option.getName(), null ); - } - else - { - results = - completable.suggestOption( option.getName(), partialValue ); - if ( results == null ) - { - results = - filterList( completable.suggestOption( option.getName(), - null ), partialValue ); - } - } - if ( results == null ) - { - results = Collections.emptyList(); - } - else - { - results = new ArrayList( results ); - Collections.sort( results ); - } - return results; + private List suggestOptionValue(Option option, String partialValue) { + List results; + if (StringUtils.isEmpty(partialValue)) { + results = completable.suggestOption(option.getName(), null); + } else { + results = + completable.suggestOption(option.getName(), partialValue); + if (results == null) { + results = + filterList(completable.suggestOption(option.getName(), + null), partialValue); + } + } + if (results == null) { + results = Collections.emptyList(); + } else { + results = new ArrayList(results); + Collections.sort(results); } + return results; + } } diff --git a/src/main/java/org/cyclopsgroup/jcli/spi/CommandLine.java b/src/main/java/org/cyclopsgroup/jcli/spi/CommandLine.java index 5dfc6ff..7293dde 100644 --- a/src/main/java/org/cyclopsgroup/jcli/spi/CommandLine.java +++ b/src/main/java/org/cyclopsgroup/jcli/spi/CommandLine.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; /** * Data that comes from command arguments diff --git a/src/test/java/org/cyclopsgroup/jcli/Simple.java b/src/test/java/org/cyclopsgroup/jcli/Simple.java index c82ff89..8468cf7 100644 --- a/src/test/java/org/cyclopsgroup/jcli/Simple.java +++ b/src/test/java/org/cyclopsgroup/jcli/Simple.java @@ -4,7 +4,7 @@ import java.util.Arrays; import java.util.List; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.cyclopsgroup.jcli.annotation.Argument; import org.cyclopsgroup.jcli.annotation.Cli; import org.cyclopsgroup.jcli.annotation.MultiValue; From acfc979fc5b07083ed7710643ccfe579ead0afb6 Mon Sep 17 00:00:00 2001 From: Rafael Zubairov Date: Fri, 5 Feb 2016 20:26:38 -0800 Subject: [PATCH 2/2] Restore formatting. --- .../cyclopsgroup/jcli/jline/CliCompletor.java | 342 ++++++++++-------- 1 file changed, 193 insertions(+), 149 deletions(-) diff --git a/src/main/java/org/cyclopsgroup/jcli/jline/CliCompletor.java b/src/main/java/org/cyclopsgroup/jcli/jline/CliCompletor.java index 1abfd24..13116de 100644 --- a/src/main/java/org/cyclopsgroup/jcli/jline/CliCompletor.java +++ b/src/main/java/org/cyclopsgroup/jcli/jline/CliCompletor.java @@ -25,171 +25,215 @@ * @author Jiaqi Guo */ public class CliCompletor - implements Completer { - private static List filterList(List list, String prefix) { - if (StringUtils.isEmpty(prefix) || list == null) { - return list; - } - List results = new ArrayList(); - for (String item : list) { - if (item.startsWith(prefix)) { - results.add(item); - } + implements Completer +{ + private static List filterList( List list, String prefix ) + { + if ( StringUtils.isEmpty( prefix ) || list == null ) + { + return list; + } + List results = new ArrayList(); + for ( String item : list ) + { + if ( item.startsWith( prefix ) ) + { + results.add( item ); + } + } + return results; } - return results; - } - private final ParsingContext context; + private final ParsingContext context; - private final AutoCompletable completable; + private final AutoCompletable completable; - private final ValueTokenizer tokenizer; + private final ValueTokenizer tokenizer; - /** - * @param cliBean Entyped AutoCompletable implementation or an normal bean - * @param tokenizer Tokenizer for argument parsing - * @throws IntrospectionException - */ - public CliCompletor(final Object cliBean, final ValueTokenizer tokenizer) { - Validate.notNull(cliBean, "Cli bean can't be NULL"); - Validate.notNull(tokenizer, "String tokenizer can't be NULL"); - context = - ArgumentProcessor.newInstance(cliBean.getClass()).createParsingContext(); - if (cliBean instanceof AutoCompletable) { - this.completable = (AutoCompletable) cliBean; - } else { - this.completable = new AutoCompletable() { - public List suggestArgument(String partialArgument) { - return Collections.emptyList(); + /** + * @param cliBean Entyped AutoCompletable implementation or an normal bean + * @param tokenizer Tokenizer for argument parsing + * @throws IntrospectionException + */ + public CliCompletor( final Object cliBean, final ValueTokenizer tokenizer ) + { + Validate.notNull( cliBean, "Cli bean can't be NULL" ); + Validate.notNull( tokenizer, "String tokenizer can't be NULL" ); + context = + ArgumentProcessor.newInstance( cliBean.getClass() ).createParsingContext(); + if ( cliBean instanceof AutoCompletable ) + { + this.completable = (AutoCompletable) cliBean; } + else + { + this.completable = new AutoCompletable() + { + public List suggestArgument( String partialArgument ) + { + return Collections.emptyList(); + } - public List suggestOption(String optionName, - String partialOption) { - return Collections.emptyList(); + public List suggestOption( String optionName, + String partialOption ) + { + return Collections.emptyList(); + } + }; } - }; + this.tokenizer = tokenizer; } - this.tokenizer = tokenizer; - } - /** - * @inheritDoc - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - public int complete(final String command, final int cursor, - final List suggestions) { - ArgumentsInspector inspector = new ArgumentsInspector(context); - final AtomicBoolean terminated = new AtomicBoolean(true); - final AtomicInteger lastWordStart = new AtomicInteger(0); - if (StringUtils.isNotEmpty(command)) { - final List args = new ArrayList(); - tokenizer.parse(command, new TokenEventHandler() { + /** + * @inheritDoc + */ + @SuppressWarnings( { "unchecked", "rawtypes" } ) + public int complete( final String command, final int cursor, + final List suggestions ) + { + ArgumentsInspector inspector = new ArgumentsInspector( context ); + final AtomicBoolean terminated = new AtomicBoolean( true ); + final AtomicInteger lastWordStart = new AtomicInteger( 0 ); + if ( StringUtils.isNotEmpty( command ) ) + { + final List args = new ArrayList(); + tokenizer.parse( command, new TokenEventHandler() + { - public void handleEvent(TokenEvent ev) { - args.add(ev.getToken()); - terminated.set(ev.isTerminated()); - lastWordStart.set(ev.getStart()); - } - }); - for (String arg : args) { - inspector.consume(arg); - } - if (terminated.get()) { - inspector.end(); - } - } - // System.err.println( "command=[" + command + "], cursor=" + cursor + - // ", state=" + inspector.getState().name() - // + ", value=" + inspector.getCurrentValue() ); - List candidates = new ArrayList(); - switch (inspector.getState()) { - case READY: - for (Option o : inspector.getRemainingOptions()) { - candidates.add("-" + o.getName()); - } - Collections.sort(candidates); - candidates.addAll(suggestArguments(null)); - break; - case OPTION: - case LONG_OPTION: - candidates.addAll(suggestOptionNames(inspector, - inspector.getCurrentValue())); - break; - case OPTION_VALUE: - candidates.addAll(suggestOptionValue(inspector.getCurrentOption(), - inspector.getCurrentValue())); - break; - case ARGUMENT: - candidates.addAll(suggestArguments(inspector.getCurrentValue())); - } - for (String candidate : candidates) { - suggestions.add(tokenizer.escape(candidate)); - } - if (StringUtils.isEmpty(command)) { - return 0; - } - if (terminated.get()) { - return cursor; + public void handleEvent( TokenEvent ev ) + { + args.add( ev.getToken() ); + terminated.set( ev.isTerminated() ); + lastWordStart.set( ev.getStart() ); + } + } ); + for ( String arg : args ) + { + inspector.consume( arg ); + } + if ( terminated.get() ) + { + inspector.end(); + } + } + // System.err.println( "command=[" + command + "], cursor=" + cursor + + // ", state=" + inspector.getState().name() + // + ", value=" + inspector.getCurrentValue() ); + List candidates = new ArrayList(); + switch ( inspector.getState() ) + { + case READY: + for ( Option o : inspector.getRemainingOptions() ) + { + candidates.add( "-" + o.getName() ); + } + Collections.sort( candidates ); + candidates.addAll( suggestArguments( null ) ); + break; + case OPTION: + case LONG_OPTION: + candidates.addAll( suggestOptionNames( inspector, + inspector.getCurrentValue() ) ); + break; + case OPTION_VALUE: + candidates.addAll( suggestOptionValue( inspector.getCurrentOption(), + inspector.getCurrentValue() ) ); + break; + case ARGUMENT: + candidates.addAll( suggestArguments( inspector.getCurrentValue() ) ); + } + for ( String candidate : candidates ) + { + suggestions.add( tokenizer.escape( candidate ) ); + } + if ( StringUtils.isEmpty( command ) ) + { + return 0; + } + if ( terminated.get() ) + { + return cursor; + } + return lastWordStart.get(); } - return lastWordStart.get(); - } - private List suggestArguments(String partialArgument) { - List results; - if (StringUtils.isEmpty(partialArgument)) { - results = completable.suggestArgument(null); - } else { - results = completable.suggestArgument(partialArgument); - if (results == null) { - results = - filterList(completable.suggestArgument(null), - partialArgument); - } - } - if (results == null) { - results = Collections.emptyList(); - } else { - results = new ArrayList(results); - Collections.sort(results); + private List suggestArguments( String partialArgument ) + { + List results; + if ( StringUtils.isEmpty( partialArgument ) ) + { + results = completable.suggestArgument( null ); + } + else + { + results = completable.suggestArgument( partialArgument ); + if ( results == null ) + { + results = + filterList( completable.suggestArgument( null ), + partialArgument ); + } + } + if ( results == null ) + { + results = Collections.emptyList(); + } + else + { + results = new ArrayList( results ); + Collections.sort( results ); + } + return results; } - return results; - } - private List suggestOptionNames(ArgumentsInspector inspector, - String value) { - List results = new ArrayList(); - for (Option o : inspector.getRemainingOptions()) { - if (value.startsWith("--") && o.getLongName() != null - && ("--" + o.getLongName()).startsWith(value)) { - results.add("--" + o.getLongName()); - } else if (value.startsWith("-") - && ("-" + o.getName()).startsWith(value)) { - results.add("-" + o.getName()); - } + private List suggestOptionNames( ArgumentsInspector inspector, + String value ) + { + List results = new ArrayList(); + for ( Option o : inspector.getRemainingOptions() ) + { + if ( value.startsWith( "--" ) && o.getLongName() != null + && ( "--" + o.getLongName() ).startsWith( value ) ) + { + results.add( "--" + o.getLongName() ); + } + else if ( value.startsWith( "-" ) + && ( "-" + o.getName() ).startsWith( value ) ) + { + results.add( "-" + o.getName() ); + } + } + Collections.sort( results ); + return results; } - Collections.sort(results); - return results; - } - private List suggestOptionValue(Option option, String partialValue) { - List results; - if (StringUtils.isEmpty(partialValue)) { - results = completable.suggestOption(option.getName(), null); - } else { - results = - completable.suggestOption(option.getName(), partialValue); - if (results == null) { - results = - filterList(completable.suggestOption(option.getName(), - null), partialValue); - } - } - if (results == null) { - results = Collections.emptyList(); - } else { - results = new ArrayList(results); - Collections.sort(results); + private List suggestOptionValue( Option option, String partialValue ) + { + List results; + if ( StringUtils.isEmpty( partialValue ) ) + { + results = completable.suggestOption( option.getName(), null ); + } + else + { + results = + completable.suggestOption( option.getName(), partialValue ); + if ( results == null ) + { + results = + filterList( completable.suggestOption( option.getName(), + null ), partialValue ); + } + } + if ( results == null ) + { + results = Collections.emptyList(); + } + else + { + results = new ArrayList( results ); + Collections.sort( results ); + } + return results; } - return results; - } }