private void discoverDescriptors()

in gshell-support/gshell-clp/src/main/java/org/apache/geronimo/gshell/clp/CommandLineProcessor.java [88:126]


    private void discoverDescriptors(final Object bean) {
        assert bean != null;

        // Recursively process all the methods/fields.
        for (Class type=bean.getClass(); type!=null; type=type.getSuperclass()) {
            // Discover methods
            for (Method method : type.getDeclaredMethods()) {
                Option option = method.getAnnotation(Option.class);
                if (option != null) {
                    addOption(new MethodSetter(bean, method), option);
                }

                Argument argument = method.getAnnotation(Argument.class);
                if (argument != null) {
                    addArgument(new MethodSetter(bean, method), argument);
                }
            }

            // Discover fields
            for (Field field : type.getDeclaredFields()) {
                Option option = field.getAnnotation(Option.class);
                if (option != null) {
                    addOption(createFieldSetter(bean, field), option);
                }

                Argument argument = field.getAnnotation(Argument.class);
                if (argument != null) {
                    addArgument(createFieldSetter(bean, field), argument);
                }
            }
        }

        // Sanity check the argument indexes
        for (int i=0; i< argumentHandlers.size(); i++) {
            if (argumentHandlers.get(i) == null) {
                throw new IllegalAnnotationError("No argument annotation for index: " + i);
            }
        }
    }