Class InvokerHelper


  • public class InvokerHelper
    extends Object
    A static helper class to make bytecode generation easier and act as a facade over the Invoker
    • Field Detail

      • EMPTY_ARGS

        public static final Object[] EMPTY_ARGS
      • EMPTY_ARGUMENTS

        protected static final Object[] EMPTY_ARGUMENTS
      • EMPTY_TYPES

        protected static final Class[] EMPTY_TYPES
    • Constructor Detail

      • InvokerHelper

        public InvokerHelper()
    • Method Detail

      • removeClass

        public static void removeClass​(Class clazz)
      • invokeStaticNoArgumentsMethod

        public static Object invokeStaticNoArgumentsMethod​(Class type,
                                                           String methodName)
      • invokeNoArgumentsConstructorOf

        public static Object invokeNoArgumentsConstructorOf​(Class type)
      • invokeClosure

        public static Object invokeClosure​(Object closure,
                                           Object arguments)
      • asList

        public static List asList​(Object value)
      • toString

        public static String toString​(Object arguments)
      • setAttribute

        public static void setAttribute​(Object object,
                                        String attribute,
                                        Object newValue)
      • getPropertySafe

        public static Object getPropertySafe​(Object object,
                                             String property)
      • setProperty

        public static void setProperty​(Object object,
                                       String property,
                                       Object newValue)
      • setProperty2

        public static void setProperty2​(Object newValue,
                                        Object object,
                                        String property)
        This is so we don't have to reorder the stack when we call this method. At some point a better name might be in order.
      • setGroovyObjectProperty

        public static void setGroovyObjectProperty​(Object newValue,
                                                   GroovyObject object,
                                                   String property)
        This is so we don't have to reorder the stack when we call this method. At some point a better name might be in order.
      • setPropertySafe2

        public static void setPropertySafe2​(Object newValue,
                                            Object object,
                                            String property)
        This is so we don't have to reorder the stack when we call this method. At some point a better name might be in order.
      • getMethodPointer

        public static Closure getMethodPointer​(Object object,
                                               String methodName)
        Returns the method pointer for the given object name
      • unaryMinus

        public static Object unaryMinus​(Object value)
      • unaryPlus

        public static Object unaryPlus​(Object value)
      • findRegex

        public static Matcher findRegex​(Object left,
                                        Object right)
        Find the right hand regex within the left hand string and return a matcher.
        Parameters:
        left - string to compare
        right - regular expression to compare the string to
      • matchRegex

        public static boolean matchRegex​(Object left,
                                         Object right)
        Find the right hand regex within the left hand string and return a matcher.
        Parameters:
        left - string to compare
        right - regular expression to compare the string to
      • createTuple

        public static Tuple createTuple​(Object[] array)
      • createList

        public static List createList​(Object[] values)
      • createMap

        public static Map createMap​(Object[] values)
      • assertFailed

        public static void assertFailed​(Object expression,
                                        Object message)
      • createScript

        public static Script createScript​(Class scriptClass,
                                          Binding context)
      • setProperties

        public static void setProperties​(Object object,
                                         Map map)
        Sets the properties on the given object
      • write

        public static void write​(Writer out,
                                 Object object)
                          throws IOException
        Writes an object to a Writer using Groovy's default representation for the object.
        Throws:
        IOException
      • append

        public static void append​(Appendable out,
                                  Object object)
                           throws IOException
        Appends an object to an Appendable using Groovy's default representation for the object.
        Throws:
        IOException
      • format

        protected static String format​(Object arguments,
                                       boolean verbose)
      • format

        public static String format​(Object arguments,
                                    boolean verbose,
                                    int maxSize)
      • format

        public static String format​(Object arguments,
                                    boolean verbose,
                                    int maxSize,
                                    boolean safe)
      • escapeBackslashes

        public static String escapeBackslashes​(String orig)
      • toTypeString

        public static String toTypeString​(Object[] arguments)
        A helper method to format the arguments types as a comma-separated list.
        Parameters:
        arguments - the type to process
        Returns:
        the string representation of the type
      • toTypeString

        public static String toTypeString​(Object[] arguments,
                                          int maxSize)
        A helper method to format the arguments types as a comma-separated list.
        Parameters:
        arguments - the type to process
        maxSize - stop after approximately this many characters and append '...', -1 means don't stop
        Returns:
        the string representation of the type
      • toMapString

        public static String toMapString​(Map arg)
        A helper method to return the string representation of a map with bracket boundaries "[" and "]".
        Parameters:
        arg - the map to process
        Returns:
        the string representation of the map
      • toMapString

        public static String toMapString​(Map arg,
                                         int maxSize)
        A helper method to return the string representation of a map with bracket boundaries "[" and "]".
        Parameters:
        arg - the map to process
        maxSize - stop after approximately this many characters and append '...', -1 means don't stop
        Returns:
        the string representation of the map
      • toListString

        public static String toListString​(Collection arg)
        A helper method to return the string representation of a list with bracket boundaries "[" and "]".
        Parameters:
        arg - the collection to process
        Returns:
        the string representation of the collection
      • toListString

        public static String toListString​(Collection arg,
                                          int maxSize)
        A helper method to return the string representation of a list with bracket boundaries "[" and "]".
        Parameters:
        arg - the collection to process
        maxSize - stop after approximately this many characters and append '...'
        Returns:
        the string representation of the collection
      • toListString

        public static String toListString​(Collection arg,
                                          int maxSize,
                                          boolean safe)
        A helper method to return the string representation of a list with bracket boundaries "[" and "]".
        Parameters:
        arg - the collection to process
        maxSize - stop after approximately this many characters and append '...', -1 means don't stop
        safe - whether to use a default object representation for any item in the collection if an exception occurs when generating its toString
        Returns:
        the string representation of the collection
      • toArrayString

        public static String toArrayString​(Object[] arguments)
        A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".
        Parameters:
        arguments - the array to process
        Returns:
        the string representation of the array
      • toArrayString

        public static String toArrayString​(Object[] arguments,
                                           int maxSize,
                                           boolean safe)
        A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".
        Parameters:
        arguments - the array to process
        maxSize - stop after approximately this many characters and append '...'
        safe - whether to use a default object representation for any item in the array if an exception occurs when generating its toString
        Returns:
        the string representation of the array
      • createRange

        public static List createRange​(Object from,
                                       Object to,
                                       boolean inclusive)
      • bitwiseNegate

        public static Object bitwiseNegate​(Object value)
      • invokeMethod

        public static Object invokeMethod​(Object object,
                                          String methodName,
                                          Object arguments)
        Invokes the given method on the object.
      • invokeConstructorOf

        public static Object invokeConstructorOf​(Class type,
                                                 Object arguments)
      • asArray

        public static Object[] asArray​(Object arguments)
        Converts the given object into an array; if its an array then just cast otherwise wrap it in an array
      • asUnwrappedArray

        public static Object[] asUnwrappedArray​(Object arguments)