Overview | Package | Class | Tree | Deprecated | Index | Help
| SSJ V. 2.1.1.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## umontreal.iro.lecuyer.util
Class Introspection

    java.lang.Object
      umontreal.iro.lecuyer.util.Introspection

    public class Introspection

extends Object

Provides utility methods for introspection using Java Reflection API.

Method Summary
`static Field` | `getField(Class<?> c, String name)` This is like `getField`, except that it can return non-public fields.
`static String` | `getFieldName(Object val)` Returns the field name corresponding to the value of an enumerated type `val`.
`static Field[]` | `getFields(Class<?> c)` Returns all the fields declared and inherited by a class.
`static Method` | `getMethod(Class<?> c, String name, Class[] pt)` This is like `getMethod`, except that it can return non-public methods.
`static Method[]` | `getMethods(Class<?> c)` Returns all the methods declared and inherited by a class.
`static boolean` | `sameSignature(Method m1, Method m2)` Determines if two methods `m1` and `m2` share the same signature.
`static
`<T> T`
` | `valueOf(Class<T> cls, String name)` Returns the field of class `cls` corresponding to the name `name`.
`static
`<T> T`
` | `valueOfIgnoreCase(Class<T> cls, String name)` Similar to `valueOf` `(cls, name)`, with case insensitive field name look-up.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### getMethods

    public static Method[] getMethods(Class<?> c)

  Returns all the methods declared and inherited by a class. This is similar to `getMethods` except that it enumerates non-public methods as well as public ones. This method uses `getDeclaredMethods` to get the declared methods of `c`. It also gets the declared methods of superclasses. If a method is defined in a superclass and overriden in a subclass, only the overriden method will be in the returned array.

  Note that since this method uses `getDeclaredMethods`, it can throw a `SecurityException` if a security manager is present.

  Parameters:
    `c` - the class being processed.
  Returns:
    the array of methods.

### sameSignature

    public static boolean sameSignature(Method m1,
                                        Method m2)

  Determines if two methods `m1` and `m2` share the same signature. For the signature to be identical, methods must have the same number of parameters and the same parameter types.

  Parameters:
    `m1` - the first method.
    `m2` - the second method.
  Returns:
    `true` if the signatures are the same, `false` otherwise.

### getFields

    public static Field[] getFields(Class<?> c)

  Returns all the fields declared and inherited by a class. This is similar to `getFields` except that it enumerates non-public fields as well as public ones. This method uses `getDeclaredFields` to get the declared fields of `c`. It also gets the declared fields of superclasses and implemented interfaces.

  Note that since this method uses `getDeclaredFields`, it can throw a `SecurityException` if a security manager is present.

  Parameters:
    `c` - the class being processed.
  Returns:
    the array of fields.

### getMethod

    public static Method getMethod(Class<?> c,
                                   String name,
                                   Class[] pt)
                            throws NoSuchMethodException

  This is like `getMethod`, except that it can return non-public methods.

  Parameters:
    `c` - the class being processed.
    `name` - the name of the method.
    `pt` - the parameter types.
  Throws:
    `NoSuchMethodException` - if the method cannot be found.

### getField

    public static Field getField(Class<?> c,
                                 String name)
                          throws NoSuchFieldException

  This is like `getField`, except that it can return non-public fields.

  Note that since this method uses `getDeclaredField`, it can throw a `SecurityException` if a security manager is present.

  Parameters:
    `c` - the class being processed.
    `name` - the name of the method.
  Throws:
    `NoSuchFieldException` - if the field cannot be found.

### getFieldName

    public static String getFieldName(Object val)

  Returns the field name corresponding to the value of an enumerated type `val`. This method gets the class of `val` and scans its fields to find a public static and final field containing `val`. If such a field is found, its name is returned. Otherwise, `null` is returned.

  Parameters:
    `val` - the value of the enumerated type.
  Returns:
    the field name or `null`.

### valueOf

    public static <T> T valueOf(Class<T> cls,
                                String name)

  Returns the field of class `cls` corresponding to the name `name`. This method looks for a public, static, and final field with name `name` and returns its value. If no appropriate field can be found, an `IllegalArgumentException` is thrown.

  Parameters:
    `cls` - the class to look for a field in.
    `name` - the name of field.
  Returns:
    the object in the field.
  Throws:
    `IllegalArgumentException` - if `name` does not correspond to a valid field name.

### valueOfIgnoreCase

    public static <T> T valueOfIgnoreCase(Class<T> cls,
                                          String name)

  Similar to `valueOf` `(cls, name)`, with case insensitive field name look-up. If `cls` defines several fields with the same case insensitive name `name`, an `IllegalArgumentException` is thrown.

  Parameters:
    `cls` - the class to look for a field in.
    `name` - the name of field.
  Returns:
    the object in the field.
  Throws:
    `IllegalArgumentException` - if `name` does not correspond to a valid field name, or if the class defines several fields with the same name.

Overview | Package | Class | Tree | Deprecated | Index | Help
| SSJ V. 2.1.1.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.