Skip to content

Commit

Permalink
Fix Javadoc errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaqi committed Feb 7, 2018
1 parent f1845e9 commit 4f9e1ce
Show file tree
Hide file tree
Showing 15 changed files with 706 additions and 1,010 deletions.
149 changes: 69 additions & 80 deletions src/main/java/org/cyclopsgroup/jcli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,94 +12,83 @@
* The facade class that parses arguments and sets values to given bean
*
* @author <a href="mailto:[email protected]">Jiaqi Guo</a>
* @param <T>
* Type of bean it processes.
* @param <T> Type of bean it processes.
*/
public abstract class ArgumentProcessor<T> {
/**
* Create new instance with default parser, a {@link GnuParser}
*
* @param <T>
* Type of the bean
* @param beanType
* Type of the bean
* @return Instance of an implementation of argument processor
*/
public static <T> ArgumentProcessor<T> forType(Class<T> beanType) {
return newInstance(beanType, new GnuParser());
}
/**
* Create new instance with default parser, a {@link GnuParser}
*
* @param <T> Type of the bean
* @param beanType Type of the bean
* @return Instance of an implementation of argument processor
*/
public static <T> ArgumentProcessor<T> forType(Class<T> beanType) {
return newInstance(beanType, new GnuParser());
}

@SuppressWarnings("unchecked")
public static <T> ArgumentProcessor<T> forTypeOf(T bean) {
return forType((Class<T>) bean.getClass());
}
@SuppressWarnings("unchecked")
public static <T> ArgumentProcessor<T> forTypeOf(T bean) {
return forType((Class<T>) bean.getClass());
}

/**
* Create new instance with given bean type and command line parser that
* describes command line sytnax.
*
* @param <T>
* type of bean
* @param beanType
* Type of bean
* @param parser
* command line parser that is aware of command line syntax
* @return instance of an implementation of argument processor.
*/
public static <T> ArgumentProcessor<T> newInstance(
Class<? extends T> beanType, CommandLineParser parser) {
return ArgumentProcessorFactory.getInstance().newProcessor(beanType,
parser);
}
/**
* Create new instance with given bean type and command line parser that describes command line
* sytnax.
*
* @param <T> type of bean
* @param beanType Type of bean
* @param parser command line parser that is aware of command line syntax
* @return instance of an implementation of argument processor.
*/
public static <T> ArgumentProcessor<T> newInstance(Class<? extends T> beanType,
CommandLineParser parser) {
return ArgumentProcessorFactory.getInstance().newProcessor(beanType, parser);
}

/**
* @deprecated Use {@link #forType(Class)} instead.
*/
public static <T> ArgumentProcessor<T> newInstance(Class<T> beanType) {
return forType(beanType);
}
/**
* @param beanType type of the bean.
* @param <T> type of bean class.
* @return instance of argument processor for given type of bean.
* @deprecated Use {@link #forType(Class)} instead.
*/
public static <T> ArgumentProcessor<T> newInstance(Class<T> beanType) {
return forType(beanType);
}

/**
* @return Implementation of parsing context
*/
public abstract ParsingContext createParsingContext();
/**
* @return Implementation of parsing context
*/
public abstract ParsingContext createParsingContext();

/**
* @param out
* Output to print help message to
* @throws IOException
* Allows IO errors
*/
public abstract void printHelp(PrintWriter out) throws IOException;
/**
* @param out Output to print help message to
* @throws IOException Allows IO errors
*/
public abstract void printHelp(PrintWriter out) throws IOException;

/**
* Process argument list and pass values to given bean
*
* @param arguments
* List of arguments
* @param bean
* Bean to pass values to
*/
public abstract void process(List<String> arguments, T bean);
/**
* Process argument list and pass values to given bean
*
* @param arguments List of arguments
* @param bean Bean to pass values to
*/
public abstract void process(List<String> arguments, T bean);

/**
* Process argument array and pass values to given bean
*
* @param arguments
* Arary of arguments
* @param bean
* Bean to pass values to
*/
public void process(String[] arguments, T bean) {
process(Arrays.asList(arguments), bean);
}
/**
* Process argument array and pass values to given bean
*
* @param arguments Arary of arguments
* @param bean Bean to pass values to
*/
public void process(String[] arguments, T bean) {
process(Arrays.asList(arguments), bean);
}

/**
* Verify if given arguments meet requirement defined for processor
*
* @param arguments
* Array of command line arguments
* @return
*/
public abstract ValidationResult validate(String[] arguments);
/**
* Verifies if given arguments meet requirement defined for processor.
*
* @param arguments array of command line arguments.
* @return a result object.
*/
public abstract ValidationResult validate(String[] arguments);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.cyclopsgroup.jcli.spi.CommandLineParser;

/**
* Factory class for {@link ArguemntProcessor}
* Factory class for {@link ArgumentProcessor}
*
* @author <a href="mailto:[email protected]">Jiaqi Guo</a>
*/
Expand Down
109 changes: 41 additions & 68 deletions src/main/java/org/cyclopsgroup/jcli/GnuParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,47 @@
/**
* @author <a href="mailto:[email protected]">Jiaqi Guo</a>
*/
public class GnuParser
implements CommandLineParser
{
/**
* @inheritDoc
*/
@Override
public CommandLine parse( List<String> arguments, ParsingContext context )
{
CommandLineBuilder builder = new CommandLineBuilder();
boolean expectingOptionValue = false;
String optionName = null;
boolean shortOption = false;
for ( String arg : arguments )
{
if ( expectingOptionValue )
{
if ( shortOption )
{
builder.withShortOption( optionName, arg );
}
else
{
builder.withLongOption( optionName, arg );
}
expectingOptionValue = false;
}
else if ( arg.startsWith( "--" ) )
{
optionName = arg.substring( 2 );
Option opt = context.optionWithLongName( optionName );
if ( opt == null )
{
builder.withArgument( arg );
}
else if ( opt.isFlag() )
{
builder.withLongFlag( optionName );
}
else
{
expectingOptionValue = true;
shortOption = false;
}
}
else if ( arg.startsWith( "-" ) )
{
optionName = arg.substring( 1 );
Option opt = context.optionWithShortName( optionName );
if ( opt == null )
{
builder.withArgument( arg );
}
else if ( opt.isFlag() )
{
builder.withShortFlag( optionName );
}
else
{
expectingOptionValue = true;
shortOption = true;
}
}
else
{
builder.withArgument( arg );
}
public class GnuParser implements CommandLineParser {
@Override
public CommandLine parse(List<String> arguments, ParsingContext context) {
CommandLineBuilder builder = new CommandLineBuilder();
boolean expectingOptionValue = false;
String optionName = null;
boolean shortOption = false;
for (String arg : arguments) {
if (expectingOptionValue) {
if (shortOption) {
builder.withShortOption(optionName, arg);
} else {
builder.withLongOption(optionName, arg);
}
return builder.toCommandLine();
expectingOptionValue = false;
} else if (arg.startsWith("--")) {
optionName = arg.substring(2);
Option opt = context.optionWithLongName(optionName);
if (opt == null) {
builder.withArgument(arg);
} else if (opt.isFlag()) {
builder.withLongFlag(optionName);
} else {
expectingOptionValue = true;
shortOption = false;
}
} else if (arg.startsWith("-")) {
optionName = arg.substring(1);
Option opt = context.optionWithShortName(optionName);
if (opt == null) {
builder.withArgument(arg);
} else if (opt.isFlag()) {
builder.withShortFlag(optionName);
} else {
expectingOptionValue = true;
shortOption = true;
}
} else {
builder.withArgument(arg);
}
}
return builder.toCommandLine();
}
}
Loading

0 comments on commit 4f9e1ce

Please sign in to comment.