private static Method getPublicMethod()

in src/main/java/org/apache/maven/shared/utils/introspection/ClassMap.java [384:431]


    private static Method getPublicMethod(Class<?> clazz, String name, Class<?>... paramTypes) {
        /*
         *  if this class is public, then try to get it
         */

        if ((clazz.getModifiers() & Modifier.PUBLIC) != 0) {
            try {
                return clazz.getMethod(name, paramTypes);
            } catch (NoSuchMethodException e) {
                /*
                 *  If the class does not have the method, then neither its
                 *  superclass nor any of its interfaces has it so quickly return
                 *  null.
                 */
                return null;
            }
        }

        /*
         *  try the superclass
         */

        Class<?> superclazz = clazz.getSuperclass();

        if (superclazz != null) {
            Method superclazzMethod = getPublicMethod(superclazz, name, paramTypes);

            if (superclazzMethod != null) {
                return superclazzMethod;
            }
        }

        /*
         *  and interfaces
         */

        Class<?>[] interfaces = clazz.getInterfaces();

        for (Class<?> anInterface : interfaces) {
            Method interfaceMethod = getPublicMethod(anInterface, name, paramTypes);

            if (interfaceMethod != null) {
                return interfaceMethod;
            }
        }

        return null;
    }