Class GroovyRuntimeUtil

java.lang.Object
org.spockframework.runtime.GroovyRuntimeUtil

public abstract class GroovyRuntimeUtil extends 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 Details

    • EMPTY_ARGUMENTS

      public static Object[] EMPTY_ARGUMENTS
  • Constructor Details

    • GroovyRuntimeUtil

      public GroovyRuntimeUtil()
  • Method Details

    • isTruthy

      public static boolean isTruthy(Object obj)
    • coerce

      public static Object coerce(Object obj, Class<?> type)
    • equals

      public static boolean equals(Object obj, Object other)
    • toString

      public static String toString(Object obj)
    • getMetaClass

      public static groovy.lang.MetaClass getMetaClass(Object object)
    • getMetaClass

      public static groovy.lang.MetaClass getMetaClass(Class<?> clazz)
    • setMetaClass

      public static void setMetaClass(Object object, groovy.lang.MetaClass metaClass)
    • setMetaClass

      public static void setMetaClass(Class<?> clazz, groovy.lang.MetaClass metaClass)
    • propertyToMethodName

      public static String propertyToMethodName(String prefix, String propertyName)
    • getterMethodToPropertyName

      public static String getterMethodToPropertyName(String methodName, List<Class<?>> parameterTypes, 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 Object getProperty(Object target, String property)
      Note: This method may throw checked exceptions although it doesn't say so.
    • setProperty

      public static void setProperty(Object target, String property, Object value)
      Note: This method may throw checked exceptions although it doesn't say so.
    • invokeConstructor

      public static Object invokeConstructor(Class<?> clazz, Object... args)
      Note: This method may throw checked exceptions although it doesn't say so.
    • invokeMethod

      public static Object invokeMethod(Object target, String method, Object... args)
      Note: This method may throw checked exceptions although it doesn't say so.
    • invokeMethodNullSafe

      public static Object invokeMethodNullSafe(Object target, String method, Object... args)
    • invokeMethodQuietly

      public static Object invokeMethodQuietly(Object target, String method, Object... args)
    • invokeClosure

      public static Object invokeClosure(groovy.lang.Closure closure, Object... args)
      Note: This method may throw checked exceptions although it doesn't say so.
    • asIterator

      public static Iterator<Object> asIterator(Object object)
      Note: This method may throw checked exceptions although it doesn't say so.
    • asUnwrappedArgumentArray

      public static Object[] asUnwrappedArgumentArray(Object args)
    • asArgumentArray

      public static Object[] asArgumentArray(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 List<Object> asArgumentList(Object args)
    • despreadList

      public static Object[] despreadList(Object[] args, Object[] spreads, int[] positions)
    • isVoidMethod

      public static boolean isVoidMethod(Object target, String method, Object... args)
    • getAttribute

      public static Object getAttribute(Object target, String name)
      Note: This method may throw checked exceptions although it doesn't say so.
    • isPhysicalMethod

      public static boolean isPhysicalMethod(groovy.lang.MetaMethod method, Class<?> targetClass)
      Tells whether the specified method is declared (in byte code) in the specified target class or one of its superclasses.