Griffon 0.9.5-rc2

griffon.util
[Java] Class GriffonClassUtils

java.lang.Object
  griffon.util.GriffonClassUtils

public final class GriffonClassUtils
extends Object

Class containing utility methods for dealing with Griffon class artifacts.

Contains utility methods copied from commons-lang and commons-beanutils in order to reduce dependencies on external libraries.

Contains code copied from commons-beanutils and commons-langs

Authors:
Graeme Rocher (Grails 0.1)


Nested Class Summary
static class GriffonClassUtils.MethodDescriptor

 
Field Summary
private static Set BASIC_METHODS

static Object[] EMPTY_ARGS

static Class[] EMPTY_CLASS_ARRAY

static Object[] EMPTY_OBJECT_ARRAY

private static String EMPTY_STRING

static Class[] EMPTY_TYPES

private static Pattern EVENT_HANDLER_PATTERN

private static Set EVENT_PUBLISHER_METHODS

private static Pattern GETTER_PATTERN_1

private static Pattern GETTER_PATTERN_2

static String INNER_CLASS_SEPARATOR

static char INNER_CLASS_SEPARATOR_CHAR

private static Set MVC_METHODS

private static Set OBSERVABLE_METHODS

static String PACKAGE_SEPARATOR

static char PACKAGE_SEPARATOR_CHAR

static Map PRIMITIVE_TYPE_COMPATIBLE_CLASSES

private static String PROPERTY_GET_PREFIX

private static String PROPERTY_IS_PREFIX

private static String PROPERTY_SET_PREFIX

private static Pattern SETTER_PATTERN

private static Set THREADING_METHODS

private static Map abbreviationMap

Maps a primitive class name to its corresponding abbreviation used in array class names.

private static Map descriptorsCache

private static Map reverseAbbreviationMap

Maps an abbreviation used in array class names to corresponding primitive class name.

 
Constructor Summary
GriffonClassUtils()

 
Method Summary
private static void addAbbreviation(String primitive, String abbreviation)

Add primitive type abbreviation to maps of abbreviations.

static Object[] collectionToObjectArray(Collection c)

Convenience method for converting a collection to an Object[]

private static String convertPropertyName(String prop)

static Collection createConcreteCollection(Class interfaceType)

Creates a concrete collection for the suppied interface

private static Method findDeclaredMethod(Class clazz, String methodName, Class[] parameterTypes)

static String findPropertyNameForValue(Object target, Object obj)

Locates the name of a property for the given value on the target object using Groovy's meta APIs.

static boolean getBooleanFromMap(String key, Map map)

Retrieves a boolean value from a Map for the given key

static MetaClass getExpandoMetaClass(Class clazz)

static Object getFieldValue(Object obj, String name)

Get the value of a declared field on an object

static String getGetterName(String propertyName)

Calculate the name for a getter method to retrieve the specified property

static String getPackageName(Object object, String valueIfNull)

static String getPackageName(Class cls)

static String getPackageName(String className)

static PropertyDescriptor[] getPropertiesAssignableToType(Class clazz, Class propertySuperType)

Retrieves all the properties of the given class which are assignable to the given type

static PropertyDescriptor[] getPropertiesOfType(Class clazz, Class propertyType)

Retrieves all the properties of the given class for the given type

static PropertyDescriptor getProperty(Class clazz, String propertyName, Class propertyType)

Retrieves a property of the given class of the specified name and type

static Object getProperty(Object bean, String name)

Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

static PropertyDescriptor getPropertyDescriptor(Object bean, String name)

static PropertyDescriptor getPropertyDescriptor(Class clazz, String name)

static PropertyDescriptor getPropertyDescriptorForValue(Object instance, Object propertyValue)

Retrieves a PropertyDescriptor for the specified instance and property value

static PropertyDescriptor[] getPropertyDescriptors(Class beanClass)

static String getPropertyForGetter(String getterName)

Returns a property name equivalent for the given getter name or null if it is not a getter

static String getPropertyForSetter(String setterName)

Returns a property name equivalent for the given setter name or null if it is not a getter

static Object getPropertyOrStaticPropertyOrFieldValue(Object obj, String name)

static Class getPropertyType(Class clazz, String propertyName)

Returns the type of the given property contained within the specified class

static Object getPropertyValueOfNewInstance(Class clazz, String propertyName, Class propertyType)

Returns the value of the specified property and type from an instance of the specified Griffon class

static Object getPropertyValueOfNewInstance(Class clazz, String propertyName)

Returns the value of the specified property and type from an instance of the specified Griffon class

static Method getReadMethod(PropertyDescriptor descriptor)

static Method getReadMethod(Class clazz, PropertyDescriptor descriptor)

static String getSetterName(String propertyName)

Retrieves the name of a setter for the specified property name

static String getShortClassName(Object object, String valueIfNull)

Feed abbreviation maps

static String getShortClassName(Class cls)

static String getShortClassName(String className)

static Object getStaticPropertyValue(Class clazz, String name)

static Object instantiate(Class clazz, Object[] args)

static Object instantiateClass(Class clazz)

Instantiates a Class, wrapping any exceptions in a RuntimeException.

static Object invokeExactInstanceMethod(Object object, String methodName)

static Object invokeExactInstanceMethod(Object object, String methodName, Object arg)

static Object invokeExactInstanceMethod(Object object, String methodName, Object... args)

static Object invokeExactStaticMethod(Class type, String methodName)

static Object invokeExactStaticMethod(Class type, String methodName, Object arg)

static Object invokeExactStaticMethod(Class type, String methodName, Object... args)

static Object invokeInstanceMethod(Object object, String methodName)

static Object invokeInstanceMethod(Object object, String methodName, Object arg)

static Object invokeInstanceMethod(Object object, String methodName, Object... args)

static Object invokeStaticMethod(Class type, String methodName)

static Object invokeStaticMethod(Class type, String methodName, Object arg)

static Object invokeStaticMethod(Class type, String methodName, Object... args)

static boolean isAssignableOrConvertibleFrom(Class clazz, Class type)

Returns true if the specified clazz parameter is either the same as, or is a superclass or superinterface of, the specified type parameter.

static boolean isBasicMethod(Method method)

Finds out if the given Method belongs either to the Object class or the GroovyObject class.

static boolean isBasicMethod(MetaMethod method)

Finds out if the given MetaMethod belongs either to the Object class or the GroovyObject class.

static boolean isBasicMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MethodDescriptor belongs either to the Object class or the GroovyObject class.

static boolean isClassBelowPackage(Class theClass, List packageList)

Returns whether the specified class is either within one of the specified packages or within a subpackage of one of the packages

static boolean isEventHandler(String name)

Finds out if the given string represents the name of an event handler by matching against the following pattern: "^on[A-Z][\\w]*$"

static boolean isEventHandler(Method method)

Finds out if the given Method represents an event handler by matching its name against the following pattern: "^on[A-Z][\\w]*$"

static boolean isEventHandler(MetaMethod method)

Finds out if the given Method represents an event handler by matching its name against the following pattern: "^on[A-Z][\\w]*$"

static boolean isEventHandler(GriffonClassUtils.MethodDescriptor method)

Finds out if the given Method represents an event handler by matching its name against the following pattern: "^on[A-Z][\\w]*$"

static boolean isEventPublisherMethod(Method method)

Finds out if the given Method belongs to the set of predefined EVENT_PUBLISHER methods by convention.

static boolean isEventPublisherMethod(MetaMethod method)

Finds out if the given MetaMethod belongs to the set of predefined EVENT_PUBLISHER methods by convention.

static boolean isEventPublisherMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MethodDescriptor belongs to the set of predefined EVENT_PUBLISHER methods by convention.

static boolean isGetter(MetaProperty property)

static boolean isGetter(MetaProperty property, boolean strict)

static boolean isGetter(String name, Class[] args)

Returns true if the name of the method specified and the number of arguments make it a javabean property

static boolean isGetterMethod(Method method)

Finds out if the given Method is a getter method.

static boolean isGetterMethod(MetaMethod method)

Finds out if the given MetaMethod is a getter method.

static boolean isGetterMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MetaMethod is a getter method.

static boolean isGroovyAssignableFrom(Class leftType, Class rightType)

static boolean isGroovyInjectedMethod(Method method)

Finds out if the given Method was injected by the Groovy compiler.

static boolean isGroovyInjectedMethod(MetaMethod method)

Finds out if the given MetaMethod was injected by the Groovy compiler.

static boolean isGroovyInjectedMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MethodDescriptor was injected by the Groovy compiler.

static boolean isInstanceMethod(Method method)

Finds out if the given Method is an instance method, i.e, it is public and non-static.

static boolean isInstanceMethod(MetaMethod method)

Finds out if the given MetaMethod is an instance method, i.e, it is public and non-static.

static boolean isInstanceMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MethodDescriptor is an instance method, i.e, it is public and non-static.

static boolean isMatchBetweenPrimitiveAndWrapperTypes(Class leftType, Class rightType)

Detect if left and right types are matching types.

static boolean isMvcMethod(Method method)

Finds out if the given Method belongs to the set of predefined MVC methods by convention.

static boolean isMvcMethod(MetaMethod method)

Finds out if the given MetaMethod belongs to the set of predefined MVC methods by convention.

static boolean isMvcMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MethodDescriptor belongs to the set of predefined MVC methods by convention.

static boolean isObservableMethod(Method method)

Finds out if the given Method belongs to the set of predefined OBSERVABLE methods by convention.

static boolean isObservableMethod(MetaMethod method)

Finds out if the given MetaMethod belongs to the set of predefined OBSERVABLE methods by convention.

static boolean isObservableMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MethodDescriptor belongs to the set of predefined OBSERVABLE methods by convention.

static boolean isPlainMethod(Method method)

Finds out if the given Method matches the following criteria:

  • isInstanceMethod(method)
  • !

static boolean isPlainMethod(MetaMethod method)

Finds out if the given MetaMethod matches the following criteria:

  • isInstanceMethod(method)
  • !

static boolean isPlainMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MethodDescriptor matches the following criteria:

  • isInstanceMethod(method)
  • !

static boolean isPropertyInherited(Class clz, String propertyName)

Checks whether the specified property is inherited from a super class

static boolean isPropertyOfType(Class clazz, String propertyName, Class type)

Returns true if the specified property in the specified class is of the specified type

static boolean isPublicField(Object obj, String name)

Work out if the specified object has a public field with the name supplied.

static boolean isPublicStatic(Method m)

Determine whether the method is declared public static

static boolean isPublicStatic(Field f)

Determine whether the field is declared public static

static boolean isReadable(Object bean, String name)

static boolean isSetter(MetaProperty property)

static boolean isSetter(String name, Class[] args)

static boolean isSetterMethod(Method method)

Finds out if the given Method is a setter method.

static boolean isSetterMethod(MetaMethod method)

Finds out if the given MetaMethod is a setter method.

static boolean isSetterMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MethodDescriptor is a setter method.

static boolean isStaticProperty(Class clazz, String propertyName)

static boolean isThreadingMethod(Method method)

Finds out if the given Method belongs to the set of predefined threading methods by convention.

static boolean isThreadingMethod(MetaMethod method)

Finds out if the given MetaMethod belongs to the set of predefined threading methods by convention.

static boolean isThreadingMethod(GriffonClassUtils.MethodDescriptor method)

Finds out if the given MethodDescriptor belongs to the set of predefined threading methods by convention.

static void isTrue(boolean expression, String message)

private static boolean isTypeInstanceOfPropertyType(Class type, Class propertyType)

private static void registerPrimitiveClassPair(Class left, Class right)

Just add two entries to the class compatibility map

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

BASIC_METHODS

private static final Set BASIC_METHODS


EMPTY_ARGS

public static final Object[] EMPTY_ARGS


EMPTY_CLASS_ARRAY

public static final Class[] EMPTY_CLASS_ARRAY


EMPTY_OBJECT_ARRAY

public static final Object[] EMPTY_OBJECT_ARRAY


EMPTY_STRING

private static final String EMPTY_STRING


EMPTY_TYPES

public static final Class[] EMPTY_TYPES


EVENT_HANDLER_PATTERN

private static final Pattern EVENT_HANDLER_PATTERN


EVENT_PUBLISHER_METHODS

private static final Set EVENT_PUBLISHER_METHODS


GETTER_PATTERN_1

private static final Pattern GETTER_PATTERN_1


GETTER_PATTERN_2

private static final Pattern GETTER_PATTERN_2


INNER_CLASS_SEPARATOR

public static final String INNER_CLASS_SEPARATOR

The inner class separator String: "$".


INNER_CLASS_SEPARATOR_CHAR

public static final char INNER_CLASS_SEPARATOR_CHAR

The inner class separator character: '$' == {@value}.


MVC_METHODS

private static final Set MVC_METHODS


OBSERVABLE_METHODS

private static final Set OBSERVABLE_METHODS


PACKAGE_SEPARATOR

public static final String PACKAGE_SEPARATOR

The package separator String: ".".


PACKAGE_SEPARATOR_CHAR

public static final char PACKAGE_SEPARATOR_CHAR

The package separator character: '.' == {@value}.


PRIMITIVE_TYPE_COMPATIBLE_CLASSES

public static final Map PRIMITIVE_TYPE_COMPATIBLE_CLASSES


PROPERTY_GET_PREFIX

private static final String PROPERTY_GET_PREFIX


PROPERTY_IS_PREFIX

private static final String PROPERTY_IS_PREFIX


PROPERTY_SET_PREFIX

private static final String PROPERTY_SET_PREFIX


SETTER_PATTERN

private static final Pattern SETTER_PATTERN


THREADING_METHODS

private static final Set THREADING_METHODS


abbreviationMap

private static final Map abbreviationMap
Maps a primitive class name to its corresponding abbreviation used in array class names.


descriptorsCache

private static final Map descriptorsCache


reverseAbbreviationMap

private static final Map reverseAbbreviationMap
Maps an abbreviation used in array class names to corresponding primitive class name.


 
Constructor Detail

GriffonClassUtils

GriffonClassUtils()


 
Method Detail

addAbbreviation

private static void addAbbreviation(String primitive, String abbreviation)
Add primitive type abbreviation to maps of abbreviations.
Parameters:
primitive - Canonical name of primitive type
abbreviation - Corresponding abbreviation of primitive type


collectionToObjectArray

public static Object[] collectionToObjectArray(Collection c)
Convenience method for converting a collection to an Object[]
Parameters:
c - The collection
Returns:
An object array


convertPropertyName

private static String convertPropertyName(String prop)


createConcreteCollection

public static Collection createConcreteCollection(Class interfaceType)
Creates a concrete collection for the suppied interface
Parameters:
interfaceType - The interface
Returns:
ArrayList for List, TreeSet for SortedSet, HashSet for Set etc.


findDeclaredMethod

private static Method findDeclaredMethod(Class clazz, String methodName, Class[] parameterTypes)


findPropertyNameForValue

public static String findPropertyNameForValue(Object target, Object obj)
Locates the name of a property for the given value on the target object using Groovy's meta APIs. Note that this method uses the reference so the incorrect result could be returned for two properties that refer to the same reference. Use with caution.
Parameters:
target - The target
obj - The property value
Returns:
The property name or null


getBooleanFromMap

public static boolean getBooleanFromMap(String key, Map map)
Retrieves a boolean value from a Map for the given key
Parameters:
key - The key that references the boolean value
map - The map to look in
Returns:
A boolean value which will be false if the map is null, the map doesn't contain the key or the value is false


getExpandoMetaClass

public static MetaClass getExpandoMetaClass(Class clazz)


getFieldValue

public static Object getFieldValue(Object obj, String name)
Get the value of a declared field on an object
Parameters:
obj
name
Returns:
The object value or null if there is no such field or access problems


getGetterName

public static String getGetterName(String propertyName)
Calculate the name for a getter method to retrieve the specified property
Parameters:
propertyName
Returns:
The name for the getter method for this property, if it were to exist, i.e. getConstraints


getPackageName

public static String getPackageName(Object object, String valueIfNull)

Gets the package name of an Object.

Parameters:
object - the class to get the package name for, may be null
valueIfNull - the value to return if null
Returns:
the package name of the object, or the null value


getPackageName

public static String getPackageName(Class cls)

Gets the package name of a Class.

Parameters:
cls - the class to get the package name for, may be null.
Returns:
the package name or an empty string


getPackageName

public static String getPackageName(String className)

Gets the package name from a String.

The string passed in is assumed to be a class name - it is not checked.

If the class is unpackaged, return an empty string.

Parameters:
className - the className to get the package name for, may be null
Returns:
the package name or an empty string


getPropertiesAssignableToType

public static PropertyDescriptor[] getPropertiesAssignableToType(Class clazz, Class propertySuperType)
Retrieves all the properties of the given class which are assignable to the given type
Parameters:
clazz - The class to retrieve the properties from
propertySuperType - The type of the properties you wish to retrieve
Returns:
An array of PropertyDescriptor instances


getPropertiesOfType

public static PropertyDescriptor[] getPropertiesOfType(Class clazz, Class propertyType)
Retrieves all the properties of the given class for the given type
Parameters:
clazz - The class to retrieve the properties from
propertyType - The type of the properties you wish to retrieve
Returns:
An array of PropertyDescriptor instances


getProperty

public static PropertyDescriptor getProperty(Class clazz, String propertyName, Class propertyType)
Retrieves a property of the given class of the specified name and type
Parameters:
clazz - The class to retrieve the property from
propertyName - The name of the property
propertyType - The type of the property
Returns:
A PropertyDescriptor instance or null if none exists


getProperty

public static Object getProperty(Object bean, String name)
Return the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
throws:
IllegalAccessException if the caller does not have access to the property accessor method
throws:
IllegalArgumentException if bean or name is null
throws:
InvocationTargetException if the property accessor method throws an exception
throws:
NoSuchMethodException if an accessor method for this property cannot be found
Parameters:
bean - Bean whose property is to be extracted
name - Possibly indexed and/or nested name of the property to be extracted
Returns:
the property value


getPropertyDescriptor

public static PropertyDescriptor getPropertyDescriptor(Object bean, String name)

Retrieve the property descriptor for the specified property of the specified bean, or return null if there is no such descriptor.

This method does not resolve index, nested nor mapped properties.

throws:
IllegalAccessException if the caller does not have access to the property accessor method
throws:
IllegalArgumentException if bean or name is null
throws:
InvocationTargetException if the property accessor method throws an exception
throws:
NoSuchMethodException if an accessor method for this property cannot be found
Parameters:
bean - Bean for which a property descriptor is requested
name - name of the property for which a property descriptor is requested
Returns:
the property descriptor or null if the bean does not have a property that matches the specified name.


getPropertyDescriptor

public static PropertyDescriptor getPropertyDescriptor(Class clazz, String name)

Retrieve the property descriptor for the specified property of the specified class, or return null if there is no such descriptor.

This method does not resolve index, nested nor mapped properties.

throws:
IllegalAccessException if the caller does not have access to the property accessor method
throws:
IllegalArgumentException if bean or name is null
throws:
InvocationTargetException if the property accessor method throws an exception
throws:
NoSuchMethodException if an accessor method for this property cannot be found
Parameters:
clazz - class for which a property descriptor is requested
name - name of the property for which a property descriptor is requested
Returns:
the property descriptor or null if the bean does not have a property that matches the specified name.


getPropertyDescriptorForValue

public static PropertyDescriptor getPropertyDescriptorForValue(Object instance, Object propertyValue)
Retrieves a PropertyDescriptor for the specified instance and property value
Parameters:
instance - The instance
propertyValue - The value of the property
Returns:
The PropertyDescriptor


getPropertyDescriptors

public static PropertyDescriptor[] getPropertyDescriptors(Class beanClass)

Retrieve the property descriptors for the specified class, introspecting and caching them the first time a particular bean class is encountered.

throws:
IllegalArgumentException if beanClass is null
Parameters:
beanClass - Bean class for which property descriptors are requested
Returns:
the property descriptors


getPropertyForGetter

public static String getPropertyForGetter(String getterName)
Returns a property name equivalent for the given getter name or null if it is not a getter
Parameters:
getterName - The getter name
Returns:
The property name equivalent


getPropertyForSetter

public static String getPropertyForSetter(String setterName)
Returns a property name equivalent for the given setter name or null if it is not a getter
Parameters:
setterName - The setter name
Returns:
The property name equivalent


getPropertyOrStaticPropertyOrFieldValue

public static Object getPropertyOrStaticPropertyOrFieldValue(Object obj, String name)

Looks for a property of the reference instance with a given name.

If found its value is returned. We follow the Java bean conventions with augmentation for groovy support and static fields/properties. We will therefore match, in this order:

  1. Standard public bean property (with getter or just public field, using normal introspection)
  2. Public static property with getter method
  3. Public static field
Returns:
property value or null if no property found


getPropertyType

public static Class getPropertyType(Class clazz, String propertyName)
Returns the type of the given property contained within the specified class
Parameters:
clazz - The class which contains the property
propertyName - The name of the property
Returns:
The property type or null if none exists


getPropertyValueOfNewInstance

public static Object getPropertyValueOfNewInstance(Class clazz, String propertyName, Class propertyType)
Returns the value of the specified property and type from an instance of the specified Griffon class
Parameters:
clazz - The name of the class which contains the property
propertyName - The property name
propertyType - The property type
Returns:
The value of the property or null if none exists


getPropertyValueOfNewInstance

public static Object getPropertyValueOfNewInstance(Class clazz, String propertyName)
Returns the value of the specified property and type from an instance of the specified Griffon class
Parameters:
clazz - The name of the class which contains the property
propertyName - The property name
Returns:
The value of the property or null if none exists


getReadMethod

public static Method getReadMethod(PropertyDescriptor descriptor)

Return an accessible property getter method for this property, if there is one; otherwise return null.

Parameters:
descriptor - Property descriptor to return a getter for
Returns:
The read method


getReadMethod

public static Method getReadMethod(Class clazz, PropertyDescriptor descriptor)

Return an accessible property getter method for this property, if there is one; otherwise return null.

Parameters:
clazz - The class of the read method will be invoked on
descriptor - Property descriptor to return a getter for
Returns:
The read method


getSetterName

public static String getSetterName(String propertyName)
Retrieves the name of a setter for the specified property name
Parameters:
propertyName - The property name
Returns:
The setter equivalent


getShortClassName

public static String getShortClassName(Object object, String valueIfNull)
Feed abbreviation maps


getShortClassName

public static String getShortClassName(Class cls)

Gets the class name minus the package name from a Class.

Parameters:
cls - the class to get the short name for.
Returns:
the class name without the package name or an empty string


getShortClassName

public static String getShortClassName(String className)

Gets the class name minus the package name from a String.

The string passed in is assumed to be a class name - it is not checked.

Parameters:
className - the className to get the short name for
Returns:
the class name of the class without the package name or an empty string


getStaticPropertyValue

public static Object getStaticPropertyValue(Class clazz, String name)

Get a static property value, which has a public static getter or is just a public static field.

Parameters:
clazz - The class to check for static property
name - The property name
Returns:
The value if there is one, or null if unset OR there is no such property


instantiate

public static Object instantiate(Class clazz, Object[] args)


instantiateClass

public static Object instantiateClass(Class clazz)
Instantiates a Class, wrapping any exceptions in a RuntimeException.
throws:
BeanInstantiationException if an error occurs when creating the object
Parameters:
clazz - target Class for which an object will be instantiated
Returns:
the newly instantiated object.


invokeExactInstanceMethod

public static Object invokeExactInstanceMethod(Object object, String methodName)


invokeExactInstanceMethod

public static Object invokeExactInstanceMethod(Object object, String methodName, Object arg)


invokeExactInstanceMethod

public static Object invokeExactInstanceMethod(Object object, String methodName, Object... args)


invokeExactStaticMethod

public static Object invokeExactStaticMethod(Class type, String methodName)


invokeExactStaticMethod

public static Object invokeExactStaticMethod(Class type, String methodName, Object arg)


invokeExactStaticMethod

public static Object invokeExactStaticMethod(Class type, String methodName, Object... args)


invokeInstanceMethod

public static Object invokeInstanceMethod(Object object, String methodName)


invokeInstanceMethod

public static Object invokeInstanceMethod(Object object, String methodName, Object arg)


invokeInstanceMethod

public static Object invokeInstanceMethod(Object object, String methodName, Object... args)


invokeStaticMethod

public static Object invokeStaticMethod(Class type, String methodName)


invokeStaticMethod

public static Object invokeStaticMethod(Class type, String methodName, Object arg)


invokeStaticMethod

public static Object invokeStaticMethod(Class type, String methodName, Object... args)


isAssignableOrConvertibleFrom

public static boolean isAssignableOrConvertibleFrom(Class clazz, Class type)
Returns true if the specified clazz parameter is either the same as, or is a superclass or superinterface of, the specified type parameter. Converts primitive types to compatible class automatically.
Parameters:
clazz
type
Returns:
True if the class is a taglib
See Also:
Class.isAssignableFrom


isBasicMethod

public static boolean isBasicMethod(Method method)
Finds out if the given Method belongs either to the Object class or the GroovyObject class.

Parameters:
method - a Method reference
Returns:
true if the method belongs to Object or GroovyObject, false otherwise.


isBasicMethod

public static boolean isBasicMethod(MetaMethod method)
Finds out if the given MetaMethod belongs either to the Object class or the GroovyObject class.

Parameters:
method - a MetaMethod reference
Returns:
true if the method belongs to Object or GroovyObject, false otherwise.


isBasicMethod

public static boolean isBasicMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MethodDescriptor belongs either to the Object class or the GroovyObject class.

Parameters:
method - a MethodDescriptor reference
Returns:
true if the method belongs to Object or GroovyObject, false otherwise.


isClassBelowPackage

public static boolean isClassBelowPackage(Class theClass, List packageList)
Returns whether the specified class is either within one of the specified packages or within a subpackage of one of the packages
Parameters:
theClass - The class
packageList - The list of packages
Returns:
True if it is within the list of specified packages


isEventHandler

public static boolean isEventHandler(String name)
Finds out if the given string represents the name of an event handler by matching against the following pattern: "^on[A-Z][\\w]*$"

 GriffonClassUtils.isEventHandler("onBootstrapEnd") = true
 GriffonClassUtils.isEventHandler("mvcGroupInit")   = false
 GriffonClassUtils.isEventHandler("online")         = false
 
Parameters:
name - the name of a possible event handler
Returns:
true if the name matches the given event handler pattern, false otherwise.


isEventHandler

public static boolean isEventHandler(Method method)
Finds out if the given Method represents an event handler by matching its name against the following pattern: "^on[A-Z][\\w]*$"

 GriffonClassUtils.isEventHandler("onBootstrapEnd") = true
 GriffonClassUtils.isEventHandler("mvcGroupInit")   = false
 GriffonClassUtils.isEventHandler("online")         = false
 
Parameters:
method - a Method reference
Returns:
true if the method name matches the given event handler pattern, false otherwise.


isEventHandler

public static boolean isEventHandler(MetaMethod method)
Finds out if the given Method represents an event handler by matching its name against the following pattern: "^on[A-Z][\\w]*$"

 GriffonClassUtils.isEventHandler("onBootstrapEnd") = true
 GriffonClassUtils.isEventHandler("mvcGroupInit")   = false
 GriffonClassUtils.isEventHandler("online")         = false
 
Parameters:
method - a MetaMethod reference
Returns:
true if the method name matches the given event handler pattern, false otherwise.


isEventHandler

public static boolean isEventHandler(GriffonClassUtils.MethodDescriptor method)
Finds out if the given Method represents an event handler by matching its name against the following pattern: "^on[A-Z][\\w]*$"

 GriffonClassUtils.isEventHandler("onBootstrapEnd") = true
 GriffonClassUtils.isEventHandler("mvcGroupInit")   = false
 GriffonClassUtils.isEventHandler("online")         = false
 
Parameters:
method - a MethodDescriptor reference
Returns:
true if the method name matches the given event handler pattern, false otherwise.


isEventPublisherMethod

public static boolean isEventPublisherMethod(Method method)
Finds out if the given Method belongs to the set of predefined EVENT_PUBLISHER methods by convention.

 // assuming getMethod() returns an appropriate Method reference
 isEventPublisherMethod(getMethod("addEventPublisher"))  = true
 isEventPublisherMethod(getMethod("publishEvent"))       = true
 isEventPublisherMethod(getMethod("foo"))                = false
 
EventPublisher:
method, false otherwise.
Parameters:
method - a Method reference
Returns:
true if the method is an


isEventPublisherMethod

public static boolean isEventPublisherMethod(MetaMethod method)
Finds out if the given MetaMethod belongs to the set of predefined EVENT_PUBLISHER methods by convention.

 // assuming getMethod() returns an appropriate MetaMethod reference
 isEventPublisherMethod(getMethod("addEventPublisher"))  = true
 isEventPublisherMethod(getMethod("publishEvent"))       = true
 isEventPublisherMethod(getMethod("foo"))                = false
 
EventPublisher:
method, false otherwise.
Parameters:
method - a Method reference
Returns:
true if the method is an


isEventPublisherMethod

public static boolean isEventPublisherMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MethodDescriptor belongs to the set of predefined EVENT_PUBLISHER methods by convention.

 // assuming getMethod() returns an appropriate MethodDescriptor reference
 isEventPublisherMethod(getMethod("addEventPublisher"))  = true
 isEventPublisherMethod(getMethod("publishEvent"))       = true
 isEventPublisherMethod(getMethod("foo"))                = false
 
EventPublisher:
method, false otherwise.
Parameters:
method - a Method reference
Returns:
true if the method is an


isGetter

public static boolean isGetter(MetaProperty property)


isGetter

public static boolean isGetter(MetaProperty property, boolean strict)


isGetter

public static boolean isGetter(String name, Class[] args)
Returns true if the name of the method specified and the number of arguments make it a javabean property
Parameters:
name - True if its a Javabean property
args - The arguments
Returns:
True if it is a javabean property method


isGetterMethod

public static boolean isGetterMethod(Method method)
Finds out if the given Method is a getter method.

 // assuming getMethod() returns an appropriate Method reference
 isGetterMethod(getMethod("getFoo"))       = true
 isGetterMethod(getMethod("getfoo") )      = false
 isGetterMethod(getMethod("mvcGroupInit")) = false
 isGetterMethod(getMethod("isFoo"))        = true
 isGetterMethod(getMethod("island"))       = false
 
Parameters:
method - a Method reference
Returns:
true if the method is a getter, false otherwise.


isGetterMethod

public static boolean isGetterMethod(MetaMethod method)
Finds out if the given MetaMethod is a getter method.

 // assuming getMethod() returns an appropriate MetaMethod reference
 isGetterMethod(getMethod("getFoo"))       = true
 isGetterMethod(getMethod("getfoo") )      = false
 isGetterMethod(getMethod("mvcGroupInit")) = false
 isGetterMethod(getMethod("isFoo"))        = true
 isGetterMethod(getMethod("island"))       = false
 
Parameters:
method - a Method reference
Returns:
true if the method is a getter, false otherwise.


isGetterMethod

public static boolean isGetterMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MetaMethod is a getter method.

 // assuming getMethod() returns an appropriate MethodDescriptor reference
 isGetterMethod(getMethod("getFoo"))       = true
 isGetterMethod(getMethod("getfoo") )      = false
 isGetterMethod(getMethod("mvcGroupInit")) = false
 isGetterMethod(getMethod("isFoo"))        = true
 isGetterMethod(getMethod("island"))       = false
 
Parameters:
method - a MethodDescriptor reference
Returns:
true if the method is a getter, false otherwise.


isGroovyAssignableFrom

public static boolean isGroovyAssignableFrom(Class leftType, Class rightType)

Tests whether or not the left hand type is compatible with the right hand type in Groovy terms, i.e. can the left type be assigned a value of the right hand type in Groovy.

This handles Java primitive type equivalence and uses isAssignableFrom for all other types, with a bit of magic for native types and polymorphism i.e. Number assigned an int. If either parameter is null an exception is thrown

Parameters:
leftType - The type of the left hand part of a notional assignment
rightType - The type of the right hand part of a notional assignment
Returns:
True if values of the right hand type can be assigned in Groovy to variables of the left hand type.


isGroovyInjectedMethod

public static boolean isGroovyInjectedMethod(Method method)
Finds out if the given Method was injected by the Groovy compiler.

Performs a basic checks against the method's name, returning true if the name starts with either "super$" or "this$".

Parameters:
method - a Method reference
Returns:
true if the method matches the given criteria, false otherwise.


isGroovyInjectedMethod

public static boolean isGroovyInjectedMethod(MetaMethod method)
Finds out if the given MetaMethod was injected by the Groovy compiler.

Performs a basic checks against the method's name, returning true if the name starts with either "super$" or "this$".

Parameters:
method - a MetaMethod reference
Returns:
true if the method matches the given criteria, false otherwise.


isGroovyInjectedMethod

public static boolean isGroovyInjectedMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MethodDescriptor was injected by the Groovy compiler.

Performs a basic checks against the method's name, returning true if the name starts with either "super$" or "this$".

Parameters:
method - a MethodDescriptor reference
Returns:
true if the method matches the given criteria, false otherwise.


isInstanceMethod

public static boolean isInstanceMethod(Method method)
Finds out if the given Method is an instance method, i.e, it is public and non-static.
Parameters:
method - a Method reference
Returns:
true if the method is an instance method, false otherwise.


isInstanceMethod

public static boolean isInstanceMethod(MetaMethod method)
Finds out if the given MetaMethod is an instance method, i.e, it is public and non-static.
Parameters:
method - a MetaMethod reference
Returns:
true if the method is an instance method, false otherwise.


isInstanceMethod

public static boolean isInstanceMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MethodDescriptor is an instance method, i.e, it is public and non-static.
Parameters:
method - a MethodDescriptor reference
Returns:
true if the method is an instance method, false otherwise.


isMatchBetweenPrimitiveAndWrapperTypes

public static boolean isMatchBetweenPrimitiveAndWrapperTypes(Class leftType, Class rightType)
Detect if left and right types are matching types. In particular, test if one is a primitive type and the other is the corresponding Java wrapper type. Primitive and wrapper classes may be passed to either arguments.
Parameters:
leftType
rightType
Returns:
true if one of the classes is a native type and the other the object representation of the same native type


isMvcMethod

public static boolean isMvcMethod(Method method)
Finds out if the given Method belongs to the set of predefined MVC methods by convention.

 // assuming getMethod() returns an appropriate Method reference
 isMvcMethod(getMethod("mvcGroupInit"))    = true
 isMvcMethod(getMethod("mvcGroupDestroy")) = true
 isMvcMethod(getMethod("foo"))             = false
 
Parameters:
method - a Method reference
Returns:
true if the method is an MVC method, false otherwise.


isMvcMethod

public static boolean isMvcMethod(MetaMethod method)
Finds out if the given MetaMethod belongs to the set of predefined MVC methods by convention.

 // assuming getMethod() returns an appropriate MetaMethod reference
 isMvcMethod(getMethod("mvcGroupInit"))    = true
 isMvcMethod(getMethod("mvcGroupDestroy")) = true
 isMvcMethod(getMethod("foo"))             = false
 
Parameters:
method - a Method reference
Returns:
true if the method is an MVC method, false otherwise.


isMvcMethod

public static boolean isMvcMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MethodDescriptor belongs to the set of predefined MVC methods by convention.

 // assuming getMethod() returns an appropriate MethodDescriptor reference
 isMvcMethod(getMethod("mvcGroupInit"))    = true
 isMvcMethod(getMethod("mvcGroupDestroy")) = true
 isMvcMethod(getMethod("foo"))             = false
 
Parameters:
method - a Method reference
Returns:
true if the method is an MVC method, false otherwise.


isObservableMethod

public static boolean isObservableMethod(Method method)
Finds out if the given Method belongs to the set of predefined OBSERVABLE methods by convention.

 // assuming getMethod() returns an appropriate Method reference
 isObservableMethod(getMethod("addPropertyChangeListener"))  = true
 isObservableMethod(getMethod("getPropertyChangeListeners")) = true
 isObservableMethod(getMethod("foo"))                        = false
 
Parameters:
method - a Method reference
Returns:
true if the method is an Observable method, false otherwise.


isObservableMethod

public static boolean isObservableMethod(MetaMethod method)
Finds out if the given MetaMethod belongs to the set of predefined OBSERVABLE methods by convention.

 // assuming getMethod() returns an appropriate MetaMethod reference
 isObservableMethod(getMethod("addPropertyChangeListener"))  = true
 isObservableMethod(getMethod("getPropertyChangeListeners")) = true
 isObservableMethod(getMethod("foo"))                        = false
 
Parameters:
method - a Method reference
Returns:
true if the method is an Observable method, false otherwise.


isObservableMethod

public static boolean isObservableMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MethodDescriptor belongs to the set of predefined OBSERVABLE methods by convention.

 // assuming getMethod() returns an appropriate MethodDescriptor reference
 isObservableMethod(getMethod("addPropertyChangeListener"))  = true
 isObservableMethod(getMethod("getPropertyChangeListeners")) = true
 isObservableMethod(getMethod("foo"))                        = false
 
Parameters:
method - a Method reference
Returns:
true if the method is an Observable method, false otherwise.


isPlainMethod

public static boolean isPlainMethod(Method method)
Finds out if the given Method matches the following criteria:
Parameters:
method - a Method reference
Returns:
true if the method matches the given criteria, false otherwise.


isPlainMethod

public static boolean isPlainMethod(MetaMethod method)
Finds out if the given MetaMethod matches the following criteria:
Parameters:
method - a Method reference
Returns:
true if the method matches the given criteria, false otherwise.


isPlainMethod

public static boolean isPlainMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MethodDescriptor matches the following criteria:
Parameters:
method - a MethodDescriptor reference
Returns:
true if the method matches the given criteria, false otherwise.


isPropertyInherited

public static boolean isPropertyInherited(Class clz, String propertyName)
Checks whether the specified property is inherited from a super class
Parameters:
clz - The class to check
propertyName - The property name
Returns:
True if the property is inherited


isPropertyOfType

public static boolean isPropertyOfType(Class clazz, String propertyName, Class type)
Returns true if the specified property in the specified class is of the specified type
Parameters:
clazz - The class which contains the property
propertyName - The property name
type - The type to check
Returns:
A boolean value


isPublicField

public static boolean isPublicField(Object obj, String name)
Work out if the specified object has a public field with the name supplied.
Parameters:
obj
name
Returns:
True if a public field with the name exists


isPublicStatic

public static boolean isPublicStatic(Method m)
Determine whether the method is declared public static
Parameters:
m
Returns:
True if the method is declared public static


isPublicStatic

public static boolean isPublicStatic(Field f)
Determine whether the field is declared public static
Parameters:
f
Returns:
True if the field is declared public static


isReadable

public static boolean isReadable(Object bean, String name)

Return true if the specified property name identifies a readable property on the specified bean; otherwise, return false.

throws:
IllegalArgumentException if bean or name is null
Parameters:
bean - Bean to be examined
name - Property name to be evaluated
Returns:
true if the property is readable, otherwise false
Since:
BeanUtils 1.6


isSetter

public static boolean isSetter(MetaProperty property)


isSetter

public static boolean isSetter(String name, Class[] args)


isSetterMethod

public static boolean isSetterMethod(Method method)
Finds out if the given Method is a setter method.

 // assuming getMethod() returns an appropriate Method reference
 isGetterMethod(getMethod("setFoo"))       = true
 isGetterMethod(getMethod("setfoo"))       = false
 isGetterMethod(getMethod("mvcGroupInit")) = false
 
Parameters:
method - a Method reference
Returns:
true if the method is a setter, false otherwise.


isSetterMethod

public static boolean isSetterMethod(MetaMethod method)
Finds out if the given MetaMethod is a setter method.

 // assuming getMethod() returns an appropriate MetaMethod reference
 isGetterMethod(getMethod("setFoo"))       = true
 isGetterMethod(getMethod("setfoo"))       = false
 isGetterMethod(getMethod("mvcGroupInit")) = false
 
Parameters:
method - a MetaMethod reference
Returns:
true if the method is a setter, false otherwise.


isSetterMethod

public static boolean isSetterMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MethodDescriptor is a setter method.

 // assuming getMethod() returns an appropriate MethodDescriptor reference
 isGetterMethod(getMethod("setFoo"))       = true
 isGetterMethod(getMethod("setfoo"))       = false
 isGetterMethod(getMethod("mvcGroupInit")) = false
 
Parameters:
method - a MethodDescriptor reference
Returns:
true if the method is a setter, false otherwise.


isStaticProperty

public static boolean isStaticProperty(Class clazz, String propertyName)

Work out if the specified property is readable and static. Java introspection does not recognize this concept of static properties but Groovy does. We also consider public static fields as static properties with no getters/setters

Parameters:
clazz - The class to check for static property
propertyName - The property name
Returns:
true if the property with name propertyName has a static getter method


isThreadingMethod

public static boolean isThreadingMethod(Method method)
Finds out if the given Method belongs to the set of predefined threading methods by convention.

 // assuming getMethod() returns an appropriate Method reference
 isThreadingMethod(getMethod("execOutside"))    = true
 isThreadingMethod(getMethod("doLater"))        = true
 isThreadingMethod(getMethod("foo"))            = false
 
Parameters:
method - a Method reference
Returns:
true if the method is a threading method, false otherwise.


isThreadingMethod

public static boolean isThreadingMethod(MetaMethod method)
Finds out if the given MetaMethod belongs to the set of predefined threading methods by convention.

 // assuming getMethod() returns an appropriate MetaMethod reference
 isThreadingMethod(getMethod("execOutside"))    = true
 isThreadingMethod(getMethod("doLater"))        = true
 isThreadingMethod(getMethod("foo"))            = false
 
Parameters:
method - a Method reference
Returns:
true if the method is a threading method, false otherwise.


isThreadingMethod

public static boolean isThreadingMethod(GriffonClassUtils.MethodDescriptor method)
Finds out if the given MethodDescriptor belongs to the set of predefined threading methods by convention.

 // assuming getMethod() returns an appropriate MethodDescriptor reference
 isThreadingMethod(getMethod("execOutside"))    = true
 isThreadingMethod(getMethod("doLater"))        = true
 isThreadingMethod(getMethod("foo"))            = false
 
Parameters:
method - a Method reference
Returns:
true if the method is a threading method, false otherwise.


isTrue

public static void isTrue(boolean expression, String message)

Validate that the argument condition is true; otherwise throwing an exception with the specified message. This method is useful when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

 isTrue( (i > 0), "The value must be greater than zero");
 isTrue( myObject.isOk(), "The object is not OK");
 
throws:
IllegalArgumentException if expression is false
Parameters:
expression - the boolean expression to check
message - the exception message if invalid


isTypeInstanceOfPropertyType

private static boolean isTypeInstanceOfPropertyType(Class type, Class propertyType)


registerPrimitiveClassPair

private static void registerPrimitiveClassPair(Class left, Class right)
Just add two entries to the class compatibility map
Parameters:
left
right


 

Groovy Documentation