Package groovy.inspect
Class Inspector
java.lang.Object
groovy.inspect.Inspector
The Inspector provides a unified access to an object's
information that can be determined by introspection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classComparator for member information arrays.static classComparator for property tuples that include values. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndex for class information.static final intIndex for implemented interface information.static final intIndex for other class information.static final intIndex for package information.static final intIndex for superclass information.static final StringOrigin label for Groovy members.static final StringOrigin label for Java members.static final intIndex for member declarer information.static final intIndex for member exception information.static final intIndex for member modifier information.static final intIndex for member name information.static final intIndex for member origin information.static final intIndex for member parameter information.static final intIndex for member type information.static final intIndex for member value information.static final StringPlaceholder for unavailable information.protected ObjectObject currently being inspected. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String[]Builds descriptive information for a Groovy property value.protected String[]Builds descriptive information for a Java field.Builds the value and metadata tuple for a Groovy property.String[]Get the Class Properties of the object under inspection.protected ClassGets the class of the inspected object.Object[]Get info about instance and class Methods that are dynamically added through Groovy.Tuple2[]Get info about instance and class Methods that are dynamically added through Groovy.Object[]Get info about usual Java instance and class Methods as well as Constructors.Tuple2[]Get info about usual Java instance and class Methods as well as Constructors.Gets the object being inspected.Object[]Gets properties together with their values and formatted metadata.Object[]Get info about Properties (Java and Groovy alike).Object[]Get info about usual Java public fields incl.booleanisGroovy()Indicates whether the inspected type implementsGroovyObject.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 voidPrints member information toSystem.out.static StringReturns the class name without its package prefix.static CollectionSorts member information using the default comparator.static Collectionsort(List<Object> memberInfo, Comparator<Object> comparator) Sorts member information using the supplied comparator.protected String[]withoutNulls(String[] toNormalize) Replacesnullentries withNOT_APPLICABLE.
-
Field Details
-
objectUnderInspection
Object currently being inspected. -
CLASS_PACKAGE_IDX
public static final int CLASS_PACKAGE_IDXIndex for package information.- See Also:
-
CLASS_CLASS_IDX
public static final int CLASS_CLASS_IDXIndex for class information.- See Also:
-
CLASS_INTERFACE_IDX
public static final int CLASS_INTERFACE_IDXIndex for implemented interface information.- See Also:
-
CLASS_SUPERCLASS_IDX
public static final int CLASS_SUPERCLASS_IDXIndex for superclass information.- See Also:
-
CLASS_OTHER_IDX
public static final int CLASS_OTHER_IDXIndex for other class information.- See Also:
-
MEMBER_ORIGIN_IDX
public static final int MEMBER_ORIGIN_IDXIndex for member origin information.- See Also:
-
MEMBER_MODIFIER_IDX
public static final int MEMBER_MODIFIER_IDXIndex for member modifier information.- See Also:
-
MEMBER_DECLARER_IDX
public static final int MEMBER_DECLARER_IDXIndex for member declarer information.- See Also:
-
MEMBER_TYPE_IDX
public static final int MEMBER_TYPE_IDXIndex for member type information.- See Also:
-
MEMBER_NAME_IDX
public static final int MEMBER_NAME_IDXIndex for member name information.- See Also:
-
MEMBER_PARAMS_IDX
public static final int MEMBER_PARAMS_IDXIndex for member parameter information.- See Also:
-
MEMBER_VALUE_IDX
public static final int MEMBER_VALUE_IDXIndex for member value information.- See Also:
-
MEMBER_EXCEPTIONS_IDX
public static final int MEMBER_EXCEPTIONS_IDXIndex for member exception information.- See Also:
-
NOT_APPLICABLE
Placeholder for unavailable information.- See Also:
-
GROOVY
Origin label for Groovy members.- See Also:
-
JAVA
Origin label for Java members.- See Also:
-
-
Constructor Details
-
Inspector
- Parameters:
objectUnderInspection- must not be null
-
-
Method Details
-
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 implementsGroovyObject.- Returns:
trueif the inspected type is Groovy-aware
-
getObject
Gets the object being inspected.- Returns:
- the 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
Get info about usual Java instance and class Methods as well as Constructors. -
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
Get info about instance and class Methods that are dynamically added through Groovy. -
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
Get info about Properties (Java and Groovy alike).- Returns:
- Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants
-
fieldInfo
Builds descriptive information for a Java field.- Parameters:
field- the field to describe- Returns:
- the field information array
-
fieldInfo
Builds descriptive information for a Groovy property value.- Parameters:
pv- the property value to describe- Returns:
- the property information array
-
getPropertiesWithInfo
Gets properties together with their values and formatted metadata.- Returns:
- the property/value tuples
-
fieldWithInfo
Builds the value and metadata tuple for a Groovy property.- Parameters:
pv- the property value to describe- Returns:
- the property tuple
-
getClassUnderInspection
Gets the class of the inspected object.- Returns:
- the inspected class
-
shortName
Returns the class name without its package prefix.- Parameters:
clazz- the class to shorten- Returns:
- the shortened class name, or
NOT_APPLICABLE
-
methodInfo
Builds descriptive information for a Java method.- Parameters:
method- the method to describe- Returns:
- the method information array
-
methodInfo
Builds descriptive information for a constructor.- Parameters:
ctor- the constructor to describe- Returns:
- the constructor information array
-
methodInfo
Builds descriptive information for a Groovy meta-method.- Parameters:
method- the meta-method to describe- Returns:
- the method information array
-
withoutNulls
Replacesnullentries withNOT_APPLICABLE.- Parameters:
toNormalize- the array to normalize- Returns:
- the normalized array
-
print
Prints member information toSystem.out.- Parameters:
memberInfo- the member information to print
-
sort
Sorts member information using the default comparator.- Parameters:
memberInfo- the member information to sort- Returns:
- the sorted collection
-
sort
Sorts member information using the supplied comparator.- Parameters:
memberInfo- the member information to sortcomparator- the comparator to apply- Returns:
- the sorted collection
-