Package sleep.engine

Class ObjectUtilities


  • public class ObjectUtilities
    extends java.lang.Object
    This class is sort of the center of the HOES universe containing several methods for mapping between Sleep and Java and resolving which mappings make sense.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ARG_MATCH_MAYBE
      when looking for a Java method that matches the sleep args, we save the maybes and use them as a last resort if no yes match is found
      static int ARG_MATCH_NO
      when looking for a Java method that matches the sleep args, we immediately drop all of the no answers.
      static int ARG_MATCH_YES
      when looking for a Java method that matches the sleep args, we use a Yes match immediately
    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object buildArgument​(java.lang.Class type, Scalar value, ScriptInstance script)
      marshalls the Sleep value into a Java value of the specified type.
      static java.lang.Object[] buildArgumentArray​(java.lang.Class[] types, java.util.Stack arguments, ScriptInstance script)
      populates a Java array with Sleep values marshalled into values of the specified types.
      static java.lang.String buildArgumentErrorMessage​(java.lang.Class theClass, java.lang.String method, java.lang.Class[] expected, java.lang.Object[] parameters)
      utility to create a string representation of an incompatible argument choice
      static Scalar BuildScalar​(boolean primitives, java.lang.Object value)
      marshalls a Java type into the appropriate Sleep scalar.
      static java.lang.Class convertDescriptionToClass​(java.lang.String description)
      converts the one character class description to the specified Class type, i.e.
      static java.lang.Class convertScalarDescriptionToClass​(Scalar description)
      this function checks if the specified scalar is a Class literal and uses that if it is, otherwise description is converted to a string and the convertDescriptionToClass method is used
      static java.lang.reflect.Constructor findConstructor​(java.lang.Class theClass, java.util.Stack arguments)
      attempts to find the constructor that is the closest match to the arguments
      static java.lang.reflect.Method findMethod​(java.lang.Class theClass, java.lang.String method, java.util.Stack arguments)
      attempts to find the method that is the closest match to the specified arguments
      static java.lang.Class getArrayType​(Scalar value, java.lang.Class defaultc)
      Determines the primitive type of the specified array.
      static void handleExceptionFromJava​(java.lang.Throwable ex, ScriptEnvironment env, java.lang.String description, int lineNumber)
      Standard method to handle a Java exception from a HOES call.
      static int isArgMatch​(java.lang.Class[] check, java.util.Stack arguments)
      convienence method to determine wether or not the stack of values is a safe match for the specified method signature
      static int isArgMatch​(java.lang.Class check, Scalar scalar)
      determined if the specified scalar can be rightfully cast to the specified class
      • Methods inherited from class java.lang.Object

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

      • ARG_MATCH_YES

        public static final int ARG_MATCH_YES
        when looking for a Java method that matches the sleep args, we use a Yes match immediately
        See Also:
        Constant Field Values
      • ARG_MATCH_NO

        public static final int ARG_MATCH_NO
        when looking for a Java method that matches the sleep args, we immediately drop all of the no answers.
        See Also:
        Constant Field Values
      • ARG_MATCH_MAYBE

        public static final int ARG_MATCH_MAYBE
        when looking for a Java method that matches the sleep args, we save the maybes and use them as a last resort if no yes match is found
        See Also:
        Constant Field Values
    • Constructor Detail

      • ObjectUtilities

        public ObjectUtilities()
    • Method Detail

      • isArgMatch

        public static int isArgMatch​(java.lang.Class[] check,
                                     java.util.Stack arguments)
        convienence method to determine wether or not the stack of values is a safe match for the specified method signature
      • isArgMatch

        public static int isArgMatch​(java.lang.Class check,
                                     Scalar scalar)
        determined if the specified scalar can be rightfully cast to the specified class
      • findMethod

        public static java.lang.reflect.Method findMethod​(java.lang.Class theClass,
                                                          java.lang.String method,
                                                          java.util.Stack arguments)
        attempts to find the method that is the closest match to the specified arguments
      • findConstructor

        public static java.lang.reflect.Constructor findConstructor​(java.lang.Class theClass,
                                                                    java.util.Stack arguments)
        attempts to find the constructor that is the closest match to the arguments
      • convertScalarDescriptionToClass

        public static java.lang.Class convertScalarDescriptionToClass​(Scalar description)
        this function checks if the specified scalar is a Class literal and uses that if it is, otherwise description is converted to a string and the convertDescriptionToClass method is used
      • convertDescriptionToClass

        public static java.lang.Class convertDescriptionToClass​(java.lang.String description)
        converts the one character class description to the specified Class type, i.e. z = boolean, c = char, b = byte, i = integer, etc..
      • buildArgument

        public static java.lang.Object buildArgument​(java.lang.Class type,
                                                     Scalar value,
                                                     ScriptInstance script)
        marshalls the Sleep value into a Java value of the specified type.
      • buildArgumentErrorMessage

        public static java.lang.String buildArgumentErrorMessage​(java.lang.Class theClass,
                                                                 java.lang.String method,
                                                                 java.lang.Class[] expected,
                                                                 java.lang.Object[] parameters)
        utility to create a string representation of an incompatible argument choice
      • buildArgumentArray

        public static java.lang.Object[] buildArgumentArray​(java.lang.Class[] types,
                                                            java.util.Stack arguments,
                                                            ScriptInstance script)
        populates a Java array with Sleep values marshalled into values of the specified types.
      • BuildScalar

        public static Scalar BuildScalar​(boolean primitives,
                                         java.lang.Object value)
        marshalls a Java type into the appropriate Sleep scalar. The primitives value will force this method to also check if the Java type could map to an int, long, double, etc. Use true when in doubt.
      • getArrayType

        public static java.lang.Class getArrayType​(Scalar value,
                                                   java.lang.Class defaultc)
        Determines the primitive type of the specified array. Primitive Sleep values (int, long, double) will return the appropriate Number.TYPE class. This is an important distinction as Double.TYPE != new Double().getClass()
      • handleExceptionFromJava

        public static void handleExceptionFromJava​(java.lang.Throwable ex,
                                                   ScriptEnvironment env,
                                                   java.lang.String description,
                                                   int lineNumber)
        Standard method to handle a Java exception from a HOES call. Basically this places the exception into Sleep's throw mechanism and collects the stack frame.