picocli.CommandLine.Unmatched Java Examples

The following examples show how to use picocli.CommandLine.Unmatched. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCommandSpecProcessor.java    From picocli with Apache License 2.0 6 votes vote down vote up
private boolean isSubcommand(ExecutableElement method, RoundEnvironment roundEnv) {
    Element typeElement = method.getEnclosingElement();
    if (typeElement.getAnnotation(Command.class) != null && typeElement.getAnnotation(Command.class).addMethodSubcommands()) {
        return true;
    }
    if (typeElement.getAnnotation(Command.class) == null) {
        Set<Element> elements = new HashSet<Element>(typeElement.getEnclosedElements());

        // The class is a Command if it has any fields or methods annotated with the below:
        return roundEnv.getElementsAnnotatedWith(Option.class).removeAll(elements)
                || roundEnv.getElementsAnnotatedWith(Parameters.class).removeAll(elements)
                || roundEnv.getElementsAnnotatedWith(Mixin.class).removeAll(elements)
                || roundEnv.getElementsAnnotatedWith(ArgGroup.class).removeAll(elements)
                || roundEnv.getElementsAnnotatedWith(Unmatched.class).removeAll(elements)
                || roundEnv.getElementsAnnotatedWith(Spec.class).removeAll(elements);
    }
    return false;
}
 
Example #2
Source File: AbstractCommandSpecProcessor.java    From picocli with Apache License 2.0 5 votes vote down vote up
private void buildUnmatched(RoundEnvironment roundEnv, Context context) {
    logger.fine("Building unmatched...");
    Set<? extends Element> explicitUnmatched = roundEnv.getElementsAnnotatedWith(Unmatched.class);
    for (Element element : explicitUnmatched) {
        buildUnmatched(element, context);
    }
}
 
Example #3
Source File: AbstractCommandSpecProcessor.java    From picocli with Apache License 2.0 4 votes vote down vote up
private void registerSubcommands(List<AnnotationValue> typeMirrors,
                                 List<CommandSpec> result,
                                 Context context,
                                 RoundEnvironment roundEnv) {

    for (AnnotationValue typeMirror : typeMirrors) {
        Element subcommandElement = processingEnv.getElementUtils().getTypeElement(
                typeMirror.getValue().toString().replace('$', '.'));
        logger.fine("Processing subcommand: " + subcommandElement);

        if (isValidSubcommandHasNameAttribute(subcommandElement)) {
            CommandSpec commandSpec = buildCommand(subcommandElement, context, roundEnv);
            result.add(commandSpec);

            List<? extends Element> enclosedElements = subcommandElement.getEnclosedElements();
            for (Element enclosed : enclosedElements) {
                if (enclosed.getAnnotation(Command.class) != null) {
                    buildCommand(enclosed, context, roundEnv);
                }
                if (enclosed.getAnnotation(ArgGroup.class) != null) {
                    buildArgGroup(enclosed, context);
                }
                if (enclosed.getAnnotation(Mixin.class) != null) {
                    buildMixin(enclosed, roundEnv, context);
                }
                if (enclosed.getAnnotation(Option.class) != null) {
                    buildOption(enclosed, context);
                }
                if (enclosed.getAnnotation(Parameters.class) != null) {
                    buildParameter(enclosed, context);
                }
                if (enclosed.getAnnotation(Unmatched.class) != null) {
                    buildUnmatched(enclosed, context);
                }
                if (enclosed.getAnnotation(Spec.class) != null) {
                    buildSpec(enclosed, context);
                }
                if (enclosed.getAnnotation(ParentCommand.class) != null) {
                    buildParentCommand(enclosed, context);
                }
            }
        }
    }
}