/** File "FullShowMethods.java"
 *  Written by David Hopwood <hopwood@zetnet.co.uk>
 *  Expanded and commented by Morris Hirsch <mhirsch@ipdinc.com>
 * <IMG SRC="/cgi-bin/counter">
 *  Based on the java.lang.reflect package,
 *  available 1.1 onwards. **/

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;

public class FullShowMethods {

/** Tell all about some named class */

    public static void main (String[] args) throws Exception {
        if ((args.length != 1)
	 || ("help".equals (args[0]))) {
            System.out.println ("Usage: java FullShowMethods <classname>");
            return;
        }

/* Get a class description object by class name,
 * then use reflection to learn all about it. */

        Class cl = Class.forName (args[0]);

/* First show the constructor(s) --
 * java.lang.reflect.Constructor.toString is formatted as:
 * the constructor access modifiers, if any,
 * followed by the fully-qualified name of the declaring class,
 * followed by a parenthesized, comma-separated list
 * of the constructor's formal parameter types. */

        Constructor[] ctors = cl.getConstructors ();
        for (int i = 0; i < ctors.length; i++)
            System.out.println (ctors[i]);

/* Then show all methods --
 * java.lang.reflect.Method.toString is formatted as:
 * the method access modifiers, if any,
 * followed by the method return type,
 * followed by a space,
 * followed by the class declaring the method,
 * followed by a period,
 * followed by the method name,
 * followed by a parenthesized, comma-separated list
 * of the method's formal parameter types.
 * If the method throws checked exceptions,
 * the parameter list is followed by a space,
 * followed by the word throws
 * followed by a comma-separated list
 * of the thrown exception types. */

        Method[] methods = cl.getMethods ();
        for (int i = 0; i < methods.length; i++)
            System.out.println (methods[i]);

/* Then fields --
 * java.lang.reflect.Field.toString is formatted as:
 * the method access modifiers, if any,
 * followed by the method return type,
 * followed by a space,
 * followed by the class declaring the method,
 * followed by a period,
 * followed by the method name,
 * followed by a parenthesized, comma-separated list
 * of the method's formal parameter types.
 * If the method throws checked exceptions,
 * the parameter list is followed by a space,
 * followed by the word throws
 * followed by a comma-separated list
 * of the thrown exception types. */

        Field[] fields = cl.getFields ();
        for (int i = 0; i < fields.length; i++)
            System.out.println (fields[i]);
    }
}
/* <IMG SRC="/cgi-bin/counter">*/
