當前位置: 首頁>>代碼示例>>Java>>正文


Java Arg類代碼示例

本文整理匯總了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);
}
 
開發者ID:fedups,項目名稱:com.obdobion.argument,代碼行數:14,代碼來源:CmdLine.java

示例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);
        }
    }
}
 
開發者ID:fedups,項目名稱:com.obdobion.argument,代碼行數:81,代碼來源:CLAFactory.java

示例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());
    }
}
 
開發者ID:fedups,項目名稱:com.obdobion.argument,代碼行數:49,代碼來源:CmdLine.java


注:本文中的com.obdobion.argument.annotation.Arg類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。