Class InvokerHelper

java.lang.Object
org.codehaus.groovy.runtime.InvokerHelper

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

    Fields
    Modifier and Type Field Description
    static java.lang.Object[] EMPTY_ARGS  
    protected static java.lang.Object[] EMPTY_ARGUMENTS  
    protected static java.lang.Class[] EMPTY_TYPES  
    static java.lang.String MAIN_METHOD_NAME  
    static MetaClassRegistry metaRegistry  
  • Constructor Summary

    Constructors
    Constructor Description
    InvokerHelper()  
  • Method Summary

    Modifier and Type Method Description
    static void append​(java.lang.Appendable out, java.lang.Object object)
    Appends an object to an Appendable using Groovy's default representation for the object.
    static java.lang.Object[] asArray​(java.lang.Object arguments)
    Converts the given object into an array; if its an array then just cast otherwise wrap it in an array
    static java.util.Iterator<java.lang.Object> asIterator​(java.lang.Object o)  
    static java.util.List asList​(java.lang.Object value)  
    static void assertFailed​(java.lang.Object expression, java.lang.Object message)  
    static java.lang.Object[] asUnwrappedArray​(java.lang.Object arguments)  
    static java.lang.Object bitwiseNegate​(java.lang.Object value)  
    static java.util.List createList​(java.lang.Object[] values)  
    static java.util.Map createMap​(java.lang.Object[] values)  
    static java.util.List createRange​(java.lang.Object from, java.lang.Object to, boolean inclusive)  
    static Script createScript​(java.lang.Class scriptClass, Binding context)  
    static Tuple createTuple​(java.lang.Object[] array)  
    static java.lang.String escapeBackslashes​(java.lang.String orig)  
    static java.util.regex.Matcher findRegex​(java.lang.Object left, java.lang.Object right)
    Find the right hand regex within the left hand string and return a matcher.
    protected static java.lang.String format​(java.lang.Object arguments, boolean verbose)  
    static java.lang.String format​(java.lang.Object arguments, boolean verbose, int maxSize)  
    static java.lang.String format​(java.lang.Object arguments, boolean verbose, int maxSize, boolean safe)  
    static java.lang.Object getAttribute​(java.lang.Object object, java.lang.String attribute)  
    static java.lang.Object getGroovyObjectProperty​(GroovyObject object, java.lang.String property)  
    static MetaClass getMetaClass​(java.lang.Class cls)  
    static MetaClass getMetaClass​(java.lang.Object object)  
    static MetaClassRegistry getMetaRegistry()  
    static Closure getMethodPointer​(java.lang.Object object, java.lang.String methodName)
    Returns the method pointer for the given object name
    static java.lang.Object getProperty​(java.lang.Object object, java.lang.String property)  
    static java.lang.Object getPropertySafe​(java.lang.Object object, java.lang.String property)  
    static int initialCapacity​(int initialEntryCnt)
    According to the initial entry count, calculate the initial capacity of hash map, which is power of 2 (SEE https://stackoverflow.com/questions/8352378/why-does-hashmap-require-that-the-initial-capacity-be-a-power-of-two)
    static java.lang.String inspect​(java.lang.Object self)  
    static java.lang.Object invokeClosure​(java.lang.Object closure, java.lang.Object arguments)  
    static java.lang.Object invokeConstructorOf​(java.lang.Class type, java.lang.Object arguments)  
    static java.lang.Object invokeConstructorOf​(java.lang.String klass, java.lang.Object arguments)  
    static java.lang.Object invokeMethod​(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
    Invokes the given method on the object.
    static java.lang.Object invokeMethodSafe​(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)  
    static java.lang.Object invokeNoArgumentsConstructorOf​(java.lang.Class type)  
    static java.lang.Object invokeStaticMethod​(java.lang.Class type, java.lang.String method, java.lang.Object arguments)  
    static java.lang.Object invokeStaticMethod​(java.lang.String klass, java.lang.String methodName, java.lang.Object arguments)  
    static java.lang.Object invokeStaticNoArgumentsMethod​(java.lang.Class type, java.lang.String methodName)  
    static java.lang.Object invokeSuperMethod​(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)  
    static boolean matchRegex​(java.lang.Object left, java.lang.Object right)
    Find the right hand regex within the left hand string and return a matcher.
    static Script newScript​(java.lang.Class<?> scriptClass, Binding context)  
    static void removeClass​(java.lang.Class clazz)  
    static java.lang.Object runScript​(java.lang.Class scriptClass, java.lang.String[] args)  
    static void setAttribute​(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)  
    static void setGroovyObjectProperty​(java.lang.Object newValue, GroovyObject object, java.lang.String property)
    This is so we don't have to reorder the stack when we call this method.
    static void setProperties​(java.lang.Object object, java.util.Map map)
    Sets the properties on the given object
    static void setProperty​(java.lang.Object object, java.lang.String property, java.lang.Object newValue)  
    static void setProperty2​(java.lang.Object newValue, java.lang.Object object, java.lang.String property)
    This is so we don't have to reorder the stack when we call this method.
    static void setPropertySafe2​(java.lang.Object newValue, java.lang.Object object, java.lang.String property)
    This is so we don't have to reorder the stack when we call this method.
    static SpreadMap spreadMap​(java.lang.Object value)  
    static java.lang.String toArrayString​(java.lang.Object[] arguments)
    A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".
    static java.lang.String toArrayString​(java.lang.Object[] arguments, int maxSize, boolean safe)
    A helper method to return the string representation of an array of objects with brace boundaries "[" and "]".
    static java.lang.String toListString​(java.util.Collection arg)
    A helper method to return the string representation of a list with bracket boundaries "[" and "]".
    static java.lang.String toListString​(java.util.Collection arg, int maxSize)
    A helper method to return the string representation of a list with bracket boundaries "[" and "]".
    static java.lang.String toListString​(java.util.Collection arg, int maxSize, boolean safe)
    A helper method to return the string representation of a list with bracket boundaries "[" and "]".
    static java.lang.String toMapString​(java.util.Map arg)
    A helper method to return the string representation of a map with bracket boundaries "[" and "]".
    static java.lang.String toMapString​(java.util.Map arg, int maxSize)
    A helper method to return the string representation of a map with bracket boundaries "[" and "]".
    static java.lang.String toString​(java.lang.Object arguments)  
    static java.lang.String toTypeString​(java.lang.Object[] arguments)
    A helper method to format the arguments types as a comma-separated list.
    static java.lang.String toTypeString​(java.lang.Object[] arguments, int maxSize)
    A helper method to format the arguments types as a comma-separated list.
    static java.lang.Object unaryMinus​(java.lang.Object value)  
    static java.lang.Object unaryPlus​(java.lang.Object value)  
    static void write​(java.io.Writer out, java.lang.Object object)
    Writes an object to a Writer using Groovy's default representation for the object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EMPTY_ARGS

      public static final java.lang.Object[] EMPTY_ARGS
    • EMPTY_ARGUMENTS

      protected static final java.lang.Object[] EMPTY_ARGUMENTS
    • EMPTY_TYPES

      protected static final java.lang.Class[] EMPTY_TYPES
    • metaRegistry

      public static final MetaClassRegistry metaRegistry
    • MAIN_METHOD_NAME

      public static final java.lang.String MAIN_METHOD_NAME
      See Also:
      Constant Field Values
  • Constructor Details

    • InvokerHelper

      public InvokerHelper()
  • Method Details

    • removeClass

      public static void removeClass​(java.lang.Class clazz)
    • invokeMethodSafe

      public static java.lang.Object invokeMethodSafe​(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
    • invokeStaticMethod

      public static java.lang.Object invokeStaticMethod​(java.lang.String klass, java.lang.String methodName, java.lang.Object arguments) throws java.lang.ClassNotFoundException
      Throws:
      java.lang.ClassNotFoundException
    • invokeStaticNoArgumentsMethod

      public static java.lang.Object invokeStaticNoArgumentsMethod​(java.lang.Class type, java.lang.String methodName)
    • invokeConstructorOf

      public static java.lang.Object invokeConstructorOf​(java.lang.String klass, java.lang.Object arguments) throws java.lang.ClassNotFoundException
      Throws:
      java.lang.ClassNotFoundException
    • invokeNoArgumentsConstructorOf

      public static java.lang.Object invokeNoArgumentsConstructorOf​(java.lang.Class type)
    • invokeClosure

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

      public static java.util.List asList​(java.lang.Object value)
    • toString

      public static java.lang.String toString​(java.lang.Object arguments)
    • inspect

      public static java.lang.String inspect​(java.lang.Object self)
    • getAttribute

      public static java.lang.Object getAttribute​(java.lang.Object object, java.lang.String attribute)
    • setAttribute

      public static void setAttribute​(java.lang.Object object, java.lang.String attribute, java.lang.Object newValue)
    • getProperty

      public static java.lang.Object getProperty​(java.lang.Object object, java.lang.String property)
    • getPropertySafe

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

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

      public static void setProperty2​(java.lang.Object newValue, java.lang.Object object, java.lang.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​(java.lang.Object newValue, GroovyObject object, java.lang.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.
    • getGroovyObjectProperty

      public static java.lang.Object getGroovyObjectProperty​(GroovyObject object, java.lang.String property)
    • setPropertySafe2

      public static void setPropertySafe2​(java.lang.Object newValue, java.lang.Object object, java.lang.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​(java.lang.Object object, java.lang.String methodName)
      Returns the method pointer for the given object name
    • unaryMinus

      public static java.lang.Object unaryMinus​(java.lang.Object value)
    • unaryPlus

      public static java.lang.Object unaryPlus​(java.lang.Object value)
    • findRegex

      public static java.util.regex.Matcher findRegex​(java.lang.Object left, java.lang.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​(java.lang.Object left, java.lang.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​(java.lang.Object[] array)
    • spreadMap

      public static SpreadMap spreadMap​(java.lang.Object value)
    • createList

      public static java.util.List createList​(java.lang.Object[] values)
    • initialCapacity

      public static int initialCapacity​(int initialEntryCnt)
      According to the initial entry count, calculate the initial capacity of hash map, which is power of 2 (SEE https://stackoverflow.com/questions/8352378/why-does-hashmap-require-that-the-initial-capacity-be-a-power-of-two)
      Parameters:
      initialEntryCnt - the initial entry count
      Returns:
      the initial capacity
    • createMap

      public static java.util.Map createMap​(java.lang.Object[] values)
    • assertFailed

      public static void assertFailed​(java.lang.Object expression, java.lang.Object message)
    • runScript

      public static java.lang.Object runScript​(java.lang.Class scriptClass, java.lang.String[] args)
    • createScript

      public static Script createScript​(java.lang.Class scriptClass, Binding context)
    • newScript

      public static Script newScript​(java.lang.Class<?> scriptClass, Binding context) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
      Throws:
      java.lang.InstantiationException
      java.lang.IllegalAccessException
      java.lang.reflect.InvocationTargetException
    • setProperties

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

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

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

      public static java.util.Iterator<java.lang.Object> asIterator​(java.lang.Object o)
    • format

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

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

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

      public static java.lang.String escapeBackslashes​(java.lang.String orig)
    • toTypeString

      public static java.lang.String toTypeString​(java.lang.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 java.lang.String toTypeString​(java.lang.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 java.lang.String toMapString​(java.util.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 java.lang.String toMapString​(java.util.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 java.lang.String toListString​(java.util.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 java.lang.String toListString​(java.util.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 java.lang.String toListString​(java.util.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 java.lang.String toArrayString​(java.lang.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 java.lang.String toArrayString​(java.lang.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 java.util.List createRange​(java.lang.Object from, java.lang.Object to, boolean inclusive)
    • bitwiseNegate

      public static java.lang.Object bitwiseNegate​(java.lang.Object value)
    • getMetaRegistry

      public static MetaClassRegistry getMetaRegistry()
    • getMetaClass

      public static MetaClass getMetaClass​(java.lang.Object object)
    • getMetaClass

      public static MetaClass getMetaClass​(java.lang.Class cls)
    • invokeMethod

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

      public static java.lang.Object invokeSuperMethod​(java.lang.Object object, java.lang.String methodName, java.lang.Object arguments)
    • invokeStaticMethod

      public static java.lang.Object invokeStaticMethod​(java.lang.Class type, java.lang.String method, java.lang.Object arguments)
    • invokeConstructorOf

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

      public static java.lang.Object[] asArray​(java.lang.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 java.lang.Object[] asUnwrappedArray​(java.lang.Object arguments)