本文整理汇总了Java中com.obdobion.argument.annotation.Arg类的典型用法代码示例。如果您正苦于以下问题:Java Arg类的具体用法?Java Arg怎么用?Java Arg使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Arg类属于com.obdobion.argument.annotation包,在下文中一共展示了Arg类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: allAvailableInstanceFields
import com.obdobion.argument.annotation.Arg; //导入依赖的package包/类
private void allAvailableInstanceFields(final Class<?> targetClass, final List<Field> fields)
{
for (final Field field : targetClass.getDeclaredFields())
if (field.isAnnotationPresent(Arg.class) || field.isAnnotationPresent(Args.class))
fields.add(field);
final Class<?> superclass = targetClass.getSuperclass();
if (superclass != null && superclass != Object.class)
/*
* Recursive from here, up the hierarchy of classes all the way to
* the top.
*/
allAvailableInstanceFields(targetClass.getSuperclass(), fields);
}
示例2: verifyArgument
import com.obdobion.argument.annotation.Arg; //导入依赖的package包/类
/**
*
*
* @param arg
* @param argAnnotation is only needed to evaluate parameters that are not
* stored on the arg itself; like excludeArgs.
* @throws ParseException
*/
private void verifyArgument(final ICmdLineArg<?> arg, final Arg argAnnotation, final Class<?> fieldType)
throws ParseException
{
if (arg.isCamelCapsAllowed())
{
if (!arg.supportsCamelCaps())
throw new ParseException(verifyMsg("allowCamelCaps is not allowed", arg), 0);
if (arg.getKeyword() == null)
throw new ParseException(verifyMsg("allowCamelCaps requires a longName", arg), 0);
}
if (arg.isMetaphoneAllowed())
{
if (!arg.supportsMetaphone())
throw new ParseException(verifyMsg("allowMetaphone is not allowed", arg), 0);
if (arg.getKeyword() == null)
throw new ParseException(verifyMsg("allowMetaphone requires a longName", arg), 0);
}
if (arg.isCaseSensitive())
if (!arg.supportsCaseSensitive())
throw new ParseException(verifyMsg("caseSensitive is not allowed", arg), 0);
if (arg.getDefaultValues() != null && arg.getDefaultValues().size() > 0)
if (!arg.supportsDefaultValues())
throw new ParseException(verifyMsg("defaultValues is not allowed", arg), 0);
if (arg.getFactoryMethodName() != null)
if (!arg.supportsFactoryMethod())
throw new ParseException(verifyMsg("factoryMethod is not allowed", arg), 0);
if (arg.getFactoryArgName() != null)
{
if (!arg.supportsFactoryArgName())
throw new ParseException(verifyMsg("factoryArgName is not allowed", arg), 0);
if (arg.getFactoryMethodName() == null)
throw new ParseException(verifyMsg("factoryArgName requires factoryMethod", arg), 0);
}
if (arg.getFormat() != null)
if (!arg.supportsFormat())
throw new ParseException(verifyMsg("format is not allowed", arg), 0);
if (arg.getHelp() != null)
if (!arg.supportsHelp())
throw new ParseException(verifyMsg("help is not allowed", arg), 0);
if (arg.getCriteria() != null)
{
if (arg.getCriteria() instanceof ListCriteria)
if (!arg.supportsInList())
throw new ParseException(verifyMsg("inList is not allowed", arg), 0);
if (arg.getCriteria() instanceof RegxCriteria)
if (!arg.supportsMatches())
throw new ParseException(verifyMsg("matches is not allowed", arg), 0);
}
if (argAnnotation != null)
{
if (argAnnotation.excludeArgs() != null && argAnnotation.excludeArgs().length > 0)
if (!arg.supportsExcludeArgs())
throw new ParseException(verifyMsg("excludeArgs is not allowed", arg), 0);
if (argAnnotation.instanceClass() != null && !argAnnotation.instanceClass().isEmpty())
if (!arg.supportsInstanceClass())
throw new ParseException(verifyMsg("instanceClass is not allowed", arg), 0);
if (argAnnotation.multimin() != 0)
{
if (!fieldType.isArray() && fieldType != java.util.List.class && fieldType != WildFiles.class)
throw new ParseException(verifyMsg("multimin is not allowed", arg), 0);
if (argAnnotation.multimin() < 1)
throw new ParseException(verifyMsg("multimin must be > 0", arg), 0);
}
if (argAnnotation.multimax() > 0)
{
if (!fieldType.isArray() && fieldType != java.util.List.class && fieldType != WildFiles.class)
throw new ParseException(verifyMsg("multimax is not allowed", arg), 0);
if (argAnnotation.multimax() < argAnnotation.multimin())
throw new ParseException(verifyMsg("multimax must be >= multimin", arg), 0);
}
}
}
示例3: compileArgAnnotation
import com.obdobion.argument.annotation.Arg; //导入依赖的package包/类
/**
* @param excludeArgsByVariableName
*/
private void compileArgAnnotation(
final Field oneField,
final Arg argAnnotation,
final List<Class<?>> alreadySeen,
final String[] excludeArgsByVariableName)
throws ParseException, IOException
{
final ICmdLineArg<?> arg = CLAFactory.getInstance().instanceFor(
commandPrefix,
oneField,
argAnnotation);
if (!argAnnotation.variable().equals(""))
{
/*
* This actually annotating an embedded class, probably because it
* can not be modified. The previous annotation will be the
* subparser that this argument should be added to.
*/
final CmdLineCLA subparser = (CmdLineCLA) argForVariableName(oneField.getName());
if (subparser == null)
throw new ParseException("invalid variable reference: " + argAnnotation.variable(), 0);
subparser.templateCmdLine.add(arg);
return;
}
add(arg);
if (arg instanceof CmdLineCLA)
{
final CmdLine embedded = new CmdLine(arg.getKeyword() == null
? ("" + arg.getKeychar())
: ("" + arg.getKeychar() + "," + arg.getKeyword()), commandPrefix, notPrefix);
((CmdLineCLA) arg).templateCmdLine = embedded;
Class<?> embeddedTarget;
try
{
if (((CmdLineCLA) arg).getInstanceClass() != null)
embeddedTarget = CmdLine.ClassLoader.loadClass(((CmdLineCLA) arg).getInstanceClass());
else
embeddedTarget = CLAFactory.instanceType(oneField);
} catch (final ClassNotFoundException e)
{
throw new ParseException(e.getMessage(), 0);
}
embedded.attemptAnnotationCompile(embeddedTarget, false, alreadySeen, argAnnotation.excludeArgs());
}
}