Package org.spockframework.runtime
Class GroovyRuntimeUtil
- java.lang.Object
-
- org.spockframework.runtime.GroovyRuntimeUtil
-
public abstract class GroovyRuntimeUtil extends java.lang.Object
Provides convenient access to Groovy language and runtime features. By convention, all usages of Groovy's InvokerHelper and ScriptBytecodeAdapter go through this class.- Author:
- Peter Niederwieser
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Object[]
EMPTY_ARGUMENTS
-
Constructor Summary
Constructors Constructor Description GroovyRuntimeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Object[]
asArgumentArray(java.lang.Object args)
Need to be careful because this converts null to an empty array.static java.util.List<java.lang.Object>
asArgumentList(java.lang.Object args)
static java.util.Iterator<java.lang.Object>
asIterator(java.lang.Object object)
Note: This method may throw checked exceptions although it doesn't say so.static java.lang.Object[]
asUnwrappedArgumentArray(java.lang.Object args)
static java.lang.Object
coerce(java.lang.Object obj, java.lang.Class<?> type)
static java.lang.Object[]
despreadList(java.lang.Object[] args, java.lang.Object[] spreads, int[] positions)
static boolean
equals(java.lang.Object obj, java.lang.Object other)
static java.lang.Object
getAttribute(java.lang.Object target, java.lang.String name)
Note: This method may throw checked exceptions although it doesn't say so.static groovy.lang.MetaClass
getMetaClass(java.lang.Class<?> clazz)
static groovy.lang.MetaClass
getMetaClass(java.lang.Object object)
static java.lang.Object
getProperty(java.lang.Object target, java.lang.String property)
Note: This method may throw checked exceptions although it doesn't say so.static java.lang.String
getterMethodToPropertyName(java.lang.String methodName, java.util.List<java.lang.Class<?>> parameterTypes, java.lang.Class<?> returnType)
Checks if the given method is a getter method according to Groovy rules.static java.lang.Object
invokeClosure(groovy.lang.Closure closure, java.lang.Object... args)
Note: This method may throw checked exceptions although it doesn't say so.static java.lang.Object
invokeConstructor(java.lang.Class<?> clazz, java.lang.Object... args)
Note: This method may throw checked exceptions although it doesn't say so.static java.lang.Object
invokeMethod(java.lang.Object target, java.lang.String method, java.lang.Object... args)
Note: This method may throw checked exceptions although it doesn't say so.static java.lang.Object
invokeMethodNullSafe(java.lang.Object target, java.lang.String method, java.lang.Object... args)
static java.lang.Object
invokeMethodQuietly(java.lang.Object target, java.lang.String method, java.lang.Object... args)
static boolean
isPhysicalMethod(groovy.lang.MetaMethod method, java.lang.Class<?> targetClass)
Tells whether the specified method is declared (in byte code) in the specified target class or one of its superclasses.static boolean
isTruthy(java.lang.Object obj)
static boolean
isVoidMethod(java.lang.Object target, java.lang.String method, java.lang.Object... args)
static java.lang.String
propertyToMethodName(java.lang.String prefix, java.lang.String propertyName)
static void
setMetaClass(java.lang.Class<?> clazz, groovy.lang.MetaClass metaClass)
static void
setMetaClass(java.lang.Object object, groovy.lang.MetaClass metaClass)
static void
setProperty(java.lang.Object target, java.lang.String property, java.lang.Object value)
Note: This method may throw checked exceptions although it doesn't say so.static java.lang.String
toString(java.lang.Object obj)
-
-
-
Method Detail
-
isTruthy
public static boolean isTruthy(java.lang.Object obj)
-
coerce
public static java.lang.Object coerce(java.lang.Object obj, java.lang.Class<?> type)
-
equals
public static boolean equals(java.lang.Object obj, java.lang.Object other)
-
toString
public static java.lang.String toString(java.lang.Object obj)
-
getMetaClass
public static groovy.lang.MetaClass getMetaClass(java.lang.Object object)
-
getMetaClass
public static groovy.lang.MetaClass getMetaClass(java.lang.Class<?> clazz)
-
setMetaClass
public static void setMetaClass(java.lang.Object object, groovy.lang.MetaClass metaClass)
-
setMetaClass
public static void setMetaClass(java.lang.Class<?> clazz, groovy.lang.MetaClass metaClass)
-
propertyToMethodName
public static java.lang.String propertyToMethodName(java.lang.String prefix, java.lang.String propertyName)
-
getterMethodToPropertyName
public static java.lang.String getterMethodToPropertyName(java.lang.String methodName, java.util.List<java.lang.Class<?>> parameterTypes, java.lang.Class<?> returnType)
Checks if the given method is a getter method according to Groovy rules. If yes, the corresponding property name is returned. Otherwise, null is returned. This method differs from Groovy 1.6.8 in that the latter doesn't support the "is" prefix for static boolean properties; however, that seems more like a bug. See http://jira.codehaus.org/browse/GROOVY-4206
-
getProperty
public static java.lang.Object getProperty(java.lang.Object target, java.lang.String property)
Note: This method may throw checked exceptions although it doesn't say so.
-
setProperty
public static void setProperty(java.lang.Object target, java.lang.String property, java.lang.Object value)
Note: This method may throw checked exceptions although it doesn't say so.
-
invokeConstructor
public static java.lang.Object invokeConstructor(java.lang.Class<?> clazz, java.lang.Object... args)
Note: This method may throw checked exceptions although it doesn't say so.
-
invokeMethod
public static java.lang.Object invokeMethod(java.lang.Object target, java.lang.String method, java.lang.Object... args)
Note: This method may throw checked exceptions although it doesn't say so.
-
invokeMethodNullSafe
public static java.lang.Object invokeMethodNullSafe(java.lang.Object target, java.lang.String method, java.lang.Object... args)
-
invokeMethodQuietly
public static java.lang.Object invokeMethodQuietly(java.lang.Object target, java.lang.String method, java.lang.Object... args)
-
invokeClosure
public static java.lang.Object invokeClosure(groovy.lang.Closure closure, java.lang.Object... args)
Note: This method may throw checked exceptions although it doesn't say so.
-
asIterator
public static java.util.Iterator<java.lang.Object> asIterator(java.lang.Object object)
Note: This method may throw checked exceptions although it doesn't say so.
-
asUnwrappedArgumentArray
public static java.lang.Object[] asUnwrappedArgumentArray(java.lang.Object args)
-
asArgumentArray
public static java.lang.Object[] asArgumentArray(java.lang.Object args)
Need to be careful because this converts null to an empty array. For single arguments, new Object[] {arg} should therefore be used.
-
asArgumentList
public static java.util.List<java.lang.Object> asArgumentList(java.lang.Object args)
-
despreadList
public static java.lang.Object[] despreadList(java.lang.Object[] args, java.lang.Object[] spreads, int[] positions)
-
isVoidMethod
public static boolean isVoidMethod(java.lang.Object target, java.lang.String method, java.lang.Object... args)
-
getAttribute
public static java.lang.Object getAttribute(java.lang.Object target, java.lang.String name)
Note: This method may throw checked exceptions although it doesn't say so.
-
isPhysicalMethod
public static boolean isPhysicalMethod(groovy.lang.MetaMethod method, java.lang.Class<?> targetClass)
Tells whether the specified method is declared (in byte code) in the specified target class or one of its superclasses.
-
-