Package groovy.inspect

# Class Inspector

java.lang.Object
groovy.inspect.Inspector

public class Inspector extends Object
The Inspector provides a unified access to an object's information that can be determined by introspection.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `Inspector.MemberComparator`
  Comparator for member information arrays.
  `static class`
  `Inspector.MemberComparatorWithValue`
  Comparator for property tuples that include values.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `CLASS_CLASS_IDX`
  Index for class information.
  `static final int`
  `CLASS_INTERFACE_IDX`
  Index for implemented interface information.
  `static final int`
  `CLASS_OTHER_IDX`
  Index for other class information.
  `static final int`
  `CLASS_PACKAGE_IDX`
  Index for package information.
  `static final int`
  `CLASS_SUPERCLASS_IDX`
  Index for superclass information.
  `static final String`
  `GROOVY`
  Origin label for Groovy members.
  `static final String`
  `JAVA`
  Origin label for Java members.
  `static final int`
  `MEMBER_DECLARER_IDX`
  Index for member declarer information.
  `static final int`
  `MEMBER_EXCEPTIONS_IDX`
  Index for member exception information.
  `static final int`
  `MEMBER_MODIFIER_IDX`
  Index for member modifier information.
  `static final int`
  `MEMBER_NAME_IDX`
  Index for member name information.
  `static final int`
  `MEMBER_ORIGIN_IDX`
  Index for member origin information.
  `static final int`
  `MEMBER_PARAMS_IDX`
  Index for member parameter information.
  `static final int`
  `MEMBER_TYPE_IDX`
  Index for member type information.
  `static final int`
  `MEMBER_VALUE_IDX`
  Index for member value information.
  `static final String`
  `NOT_APPLICABLE`
  Placeholder for unavailable information.
  `protected Object`
  `objectUnderInspection`
  Object currently being inspected.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Inspector(Object objectUnderInspection)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected String[]`
  `fieldInfo(PropertyValue pv)`
  Builds descriptive information for a Groovy property value.
  `protected String[]`
  `fieldInfo(Field field)`
  Builds descriptive information for a Java field.
  `protected Tuple2<Object,String[]>`
  `fieldWithInfo(PropertyValue pv)`
  Builds the value and metadata tuple for a Groovy property.
  `String[]`
  `getClassProps()`
  Get the Class Properties of the object under inspection.
  `protected Class`
  `getClassUnderInspection()`
  Gets the class of the inspected object.
  `Object[]`
  `getMetaMethods()`
  Get info about instance and class Methods that are dynamically added through Groovy.
  `Tuple2[]`
  `getMetaMethodsWithInfo()`
  Get info about instance and class Methods that are dynamically added through Groovy.
  `Object[]`
  `getMethods()`
  Get info about usual Java instance and class Methods as well as Constructors.
  `Tuple2[]`
  `getMethodsWithInfo()`
  Get info about usual Java instance and class Methods as well as Constructors.
  `Object`
  `getObject()`
  Gets the object being inspected.
  `Object[]`
  `getPropertiesWithInfo()`
  Gets properties together with their values and formatted metadata.
  `Object[]`
  `getPropertyInfo()`
  Get info about Properties (Java and Groovy alike).
  `Object[]`
  `getPublicFields()`
  Get info about usual Java public fields incl.
  `boolean`
  `isGroovy()`
  Indicates whether the inspected type implements `GroovyObject`.
  `protected String[]`
  `methodInfo(MetaMethod method)`
  Builds descriptive information for a Groovy meta-method.
  `protected String[]`
  `methodInfo(Constructor ctor)`
  Builds descriptive information for a constructor.
  `protected String[]`
  `methodInfo(Method method)`
  Builds descriptive information for a Java method.
  `static void`
  `print(Object[] memberInfo)`
  Prints member information to `System.out`.
  `static String`
  `shortName(Class clazz)`
  Returns the class name without its package prefix.
  `static Collection`
  `sort(List<Object> memberInfo)`
  Sorts member information using the default comparator.
  `static Collection`
  `sort(List<Object> memberInfo, Comparator<Object> comparator)`
  Sorts member information using the supplied comparator.
  `protected String[]`
  `withoutNulls(String[] toNormalize)`
  Replaces `null` entries with `NOT_APPLICABLE`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### objectUnderInspection

    protected Object objectUnderInspection
    Object currently being inspected.

  - ### CLASS_PACKAGE_IDX

    public static final int CLASS_PACKAGE_IDX
    Index for package information.
    See Also:
      - Constant Field Values

  - ### CLASS_CLASS_IDX

    public static final int CLASS_CLASS_IDX
    Index for class information.
    See Also:
      - Constant Field Values

  - ### CLASS_INTERFACE_IDX

    public static final int CLASS_INTERFACE_IDX
    Index for implemented interface information.
    See Also:
      - Constant Field Values

  - ### CLASS_SUPERCLASS_IDX

    public static final int CLASS_SUPERCLASS_IDX
    Index for superclass information.
    See Also:
      - Constant Field Values

  - ### CLASS_OTHER_IDX

    public static final int CLASS_OTHER_IDX
    Index for other class information.
    See Also:
      - Constant Field Values

  - ### MEMBER_ORIGIN_IDX

    public static final int MEMBER_ORIGIN_IDX
    Index for member origin information.
    See Also:
      - Constant Field Values

  - ### MEMBER_MODIFIER_IDX

    public static final int MEMBER_MODIFIER_IDX
    Index for member modifier information.
    See Also:
      - Constant Field Values

  - ### MEMBER_DECLARER_IDX

    public static final int MEMBER_DECLARER_IDX
    Index for member declarer information.
    See Also:
      - Constant Field Values

  - ### MEMBER_TYPE_IDX

    public static final int MEMBER_TYPE_IDX
    Index for member type information.
    See Also:
      - Constant Field Values

  - ### MEMBER_NAME_IDX

    public static final int MEMBER_NAME_IDX
    Index for member name information.
    See Also:
      - Constant Field Values

  - ### MEMBER_PARAMS_IDX

    public static final int MEMBER_PARAMS_IDX
    Index for member parameter information.
    See Also:
      - Constant Field Values

  - ### MEMBER_VALUE_IDX

    public static final int MEMBER_VALUE_IDX
    Index for member value information.
    See Also:
      - Constant Field Values

  - ### MEMBER_EXCEPTIONS_IDX

    public static final int MEMBER_EXCEPTIONS_IDX
    Index for member exception information.
    See Also:
      - Constant Field Values

  - ### NOT_APPLICABLE

    public static final String NOT_APPLICABLE
    Placeholder for unavailable information.
    See Also:
      - Constant Field Values

  - ### GROOVY

    public static final String GROOVY
    Origin label for Groovy members.
    See Also:
      - Constant Field Values

  - ### JAVA

    public static final String JAVA
    Origin label for Java members.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### Inspector

    public Inspector(Object objectUnderInspection)
    Parameters:
      `objectUnderInspection` - must not be null

- ## Method Details

  - ### getClassProps

    public String[] getClassProps()
    Get the Class Properties of the object under inspection.
    Returns:
      String array to be indexed by the CLASS_xxx_IDX constants

  - ### isGroovy

    public boolean isGroovy()
    Indicates whether the inspected type implements `GroovyObject`.
    Returns:
      `true` if the inspected type is Groovy-aware

  - ### getObject

    public Object getObject()
    Gets the object being inspected.
    Returns:
      the object

  - ### getMethods

    public Object[] getMethods()
    Get info about usual Java instance and class Methods as well as Constructors.
    Returns:
      Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants

  - ### getMethodsWithInfo

    public Tuple2[] getMethodsWithInfo()
    Get info about usual Java instance and class Methods as well as Constructors.

  - ### getMetaMethods

    public Object[] getMetaMethods()
    Get info about instance and class Methods that are dynamically added through Groovy.
    Returns:
      Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants

  - ### getMetaMethodsWithInfo

    public Tuple2[] getMetaMethodsWithInfo()
    Get info about instance and class Methods that are dynamically added through Groovy.

  - ### getPublicFields

    public Object[] getPublicFields()
    Get info about usual Java public fields incl. constants.
    Returns:
      Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants

  - ### getPropertyInfo

    public Object[] getPropertyInfo()
    Get info about Properties (Java and Groovy alike).
    Returns:
      Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants

  - ### fieldInfo

    protected String[] fieldInfo(Field field)
    Builds descriptive information for a Java field.
    Parameters:
      `field` - the field to describe
    Returns:
      the field information array

  - ### fieldInfo

    protected String[] fieldInfo(PropertyValue pv)
    Builds descriptive information for a Groovy property value.
    Parameters:
      `pv` - the property value to describe
    Returns:
      the property information array

  - ### getPropertiesWithInfo

    public Object[] getPropertiesWithInfo()
    Gets properties together with their values and formatted metadata.
    Returns:
      the property/value tuples

  - ### fieldWithInfo

    protected Tuple2<Object,String[]> fieldWithInfo(PropertyValue pv)
    Builds the value and metadata tuple for a Groovy property.
    Parameters:
      `pv` - the property value to describe
    Returns:
      the property tuple

  - ### getClassUnderInspection

    protected Class getClassUnderInspection()
    Gets the class of the inspected object.
    Returns:
      the inspected class

  - ### shortName

    public static String shortName(Class clazz)
    Returns the class name without its package prefix.
    Parameters:
      `clazz` - the class to shorten
    Returns:
      the shortened class name, or `NOT_APPLICABLE`

  - ### methodInfo

    protected String[] methodInfo(Method method)
    Builds descriptive information for a Java method.
    Parameters:
      `method` - the method to describe
    Returns:
      the method information array

  - ### methodInfo

    protected String[] methodInfo(Constructor ctor)
    Builds descriptive information for a constructor.
    Parameters:
      `ctor` - the constructor to describe
    Returns:
      the constructor information array

  - ### methodInfo

    protected String[] methodInfo(MetaMethod method)
    Builds descriptive information for a Groovy meta-method.
    Parameters:
      `method` - the meta-method to describe
    Returns:
      the method information array

  - ### withoutNulls

    protected String[] withoutNulls(String[] toNormalize)
    Replaces `null` entries with `NOT_APPLICABLE`.
    Parameters:
      `toNormalize` - the array to normalize
    Returns:
      the normalized array

  - ### print

    public static void print(Object[] memberInfo)
    Prints member information to `System.out`.
    Parameters:
      `memberInfo` - the member information to print

  - ### sort

    public static Collection sort(List<Object> memberInfo)
    Sorts member information using the default comparator.
    Parameters:
      `memberInfo` - the member information to sort
    Returns:
      the sorted collection

  - ### sort

    public static Collection sort(List<Object> memberInfo, Comparator<Object> comparator)
    Sorts member information using the supplied comparator.
    Parameters:
      `memberInfo` - the member information to sort
      `comparator` - the comparator to apply
    Returns:
      the sorted collection