public final class GrailsMetaClassUtils extends Object
Provides utility methods for working with the Groovy MetaClass API.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public static void |
copyExpandoMetaClass(Class<?> fromClass, Class<?> toClass, boolean removeSource)Copies the ExpandoMetaClass dynamic methods and properties from one Class to another. |
|
public static ExpandoMetaClass |
getExpandoMetaClass(Class<?> aClass) |
|
public static MetaClass |
getMetaClass(Object instance) |
|
public static Object |
getPropertyIfExists(Object instance, String property)Obtains a property of an instance if it exists |
<T> |
public static T |
getPropertyIfExists(Object instance, String property, Class<T> requiredType)Obtains a property of an instance if it exists |
|
public static MetaClassRegistry |
getRegistry()Retrieves the MetaClassRegistry instance. |
|
public static Object |
invokeMethodIfExists(Object instance, String methodName)Invokes a method if it exists otherwise returns null |
|
public static Object |
invokeMethodIfExists(Object instance, String methodName, Object[] args)Invokes a method if it exists otherwise returns null |
Copies the ExpandoMetaClass dynamic methods and properties from one Class to another.
fromClass - The source classtoClass - The destination classremoveSource - Whether to remove the source class after completion. True if yesObtains a property of an instance if it exists
instance - The instanceproperty - The propertyObtains a property of an instance if it exists
instance - The instanceproperty - The propertyrequiredType - The required type of the propertyRetrieves the MetaClassRegistry instance.
Invokes a method if it exists otherwise returns null
instance - The instancemethodName - The method name