Class BoxClassSupport

java.lang.Object
ortus.boxlang.runtime.runnables.BoxClassSupport

public class BoxClassSupport extends Object
The methods in this class are an extension of IClassRunnable. They are here for better readability since IClassRunnables don't extend a base class, there are placeholders in the BoxClassTransformer that delegate to these methods.
  • Constructor Details

    • BoxClassSupport

      public BoxClassSupport()
  • Method Details

    • pseudoConstructor

      public static void pseudoConstructor(IClassRunnable thisClass, IBoxContext context)
      Call the pseudo constructor
      Parameters:
      thisClass - The class to call the pseudo constructor on
      context - The context to use
    • defaultProperties

      public static void defaultProperties(IClassRunnable thisClass, IBoxContext context)
      I handle creating default values for all properties defined
      Parameters:
      thisClass - The class to create default properties for
      context - The context to use
    • getBoxMeta

      public static BoxMeta getBoxMeta(IClassRunnable thisClass)
      Get the class metadata
      Parameters:
      thisClass - The class to get the metadata for
      Returns:
      The metadata Box object
    • asString

      public static String asString(IClassRunnable thisClass)
      Represent as string, or throw exception if not possible
      Parameters:
      thisClass - The class to represent
      Returns:
      The string representation
    • canOutput

      public static Boolean canOutput(IClassRunnable thisClass)
      A helper to look at the "output" annotation, caching the result
      Parameters:
      thisClass - The class to check
      Returns:
      Whether the function can output
    • canInvokeImplicitAccessor

      public static Boolean canInvokeImplicitAccessor(IClassRunnable thisClass, IBoxContext context)
      A helper to look at the "InvokeImplicitAccessor" annotation and application settings, caching the result
      Parameters:
      thisClass - The class to check
      context - The context to use
      Returns:
      Whether the function can invoke implicit accessors
    • setSuper

      public static void setSuper(IClassRunnable thisClass, IClassRunnable _super)
      Set the super class. This method is called by the BoxClassTransformer
      Parameters:
      thisClass - The class to set the super class on
      _super - The super class
    • getBottomClass

      public static IClassRunnable getBottomClass(IClassRunnable thisClass)
      Get the bottom class in the inheritance chain
      Parameters:
      thisClass - The class to start from
      Returns:
      The bottom class if any, otherwise the class itself
    • assign

      public static Object assign(IClassRunnable thisClass, IBoxContext context, Key key, Object value)
      Assign a value to a key
      Parameters:
      thisClass - The class to assign the value to
      context - The context to use
      key - The key to assign
      value - The value to assign
      Returns:
      The assigned value
    • dereference

      public static Object dereference(IClassRunnable thisClass, IBoxContext context, Key key, Boolean safe)
      Dereference this object by a key and return the value, or throw exception
      Parameters:
      thisClass - The class to dereference
      context - The context to use
      key - The key to dereference
      safe - Whether to throw an exception if the key is not found
      Returns:
      The requested object
    • dereferenceAndInvoke

      public static Object dereferenceAndInvoke(IClassRunnable thisClass, IBoxContext context, Key name, Object[] positionalArguments, Boolean safe)
      Dereference this object by a key and invoke the result as an invokable (UDF, java method) using positional arguments
      Parameters:
      thisClass - The class to dereference
      context - The context to use
      name - The key to dereference
      positionalArguments - The positional arguments to pass to the invokable
      safe - Whether to throw an exception if the key is not found
      Returns:
      The requested object
    • dereferenceAndInvoke

      public static Object dereferenceAndInvoke(IClassRunnable thisClass, IBoxContext context, Key name, Map<Key,Object> namedArguments, Boolean safe)
      Dereference this object by a key and invoke the result as an invokable (UDF, java method)
      Parameters:
      thisClass - The class to dereference
      context - The context to use
      name - The name of the key to dereference, which becomes the method name
      namedArguments - The arguments to pass to the invokable
      safe - If true, return null if the method is not found, otherwise throw an exception
      Returns:
      The requested return value or null
    • getMetaData

      public static IStruct getMetaData(IClassRunnable thisClass)
      Get the combined metadata for this function and all it's parameters This follows the format of Lucee and Adobe's "combined" metadata This is to keep compatibility for CFML engines
      Parameters:
      thisClass - The class to get the metadata for
      Returns:
      The metadata as a struct
    • registerInterface

      public static void registerInterface(IClassRunnable thisClass, BoxInterface _interface)
      Register an interface with a class
      Parameters:
      thisClass - The class to register the interface with
      _interface - The interface to register
    • dereferenceAndInvokeStatic

      public static Object dereferenceAndInvokeStatic(DynamicObject targetClass, IBoxContext context, Key name, Map<Key,Object> namedArguments, Boolean safe)
    • dereferenceAndInvokeStatic

      public static Object dereferenceAndInvokeStatic(DynamicObject targetClass, IBoxContext context, Key name, Object[] positionalArguments, Boolean safe)
    • assignStatic

      public static Object assignStatic(DynamicObject targetClass, IBoxContext context, Key name, Object value)
    • dereferenceStatic

      public static Object dereferenceStatic(DynamicObject targetClass, IBoxContext context, Key name, Boolean safe)
    • dereferenceAndInvokeStatic

      public static Object dereferenceAndInvokeStatic(DynamicObject targetClass, StaticScope staticScope, IBoxContext context, Key name, Map<Key,Object> namedArguments, Boolean safe)
    • dereferenceAndInvokeStatic

      public static Object dereferenceAndInvokeStatic(DynamicObject targetClass, StaticScope staticScope, IBoxContext context, Key name, Object[] positionalArguments, Boolean safe)
    • assignStatic

      public static Object assignStatic(StaticScope staticScope, IBoxContext context, Key name, Object value)
      Assign a value to a key in the static scope
      Parameters:
      staticScope - The static scope to assign the value to
      context - The context to use
      name - The key to assign
      value - The value to assign
      Returns:
      The assigned value
    • dereferenceStatic

      public static Object dereferenceStatic(StaticScope staticScope, IBoxContext context, Key name, Boolean safe)
      Dereference this object by a key and return the value, or throw exception This is a static version of the dereference method
      Parameters:
      staticScope - The static scope to dereference
      context - The context to use
      name - The key to dereference
      safe - Whether to throw an exception if the key is not found
      Returns:
      The requested object
    • getStaticScope

      public static StaticScope getStaticScope(IBoxContext context, DynamicObject targetClass)
      Get the static scope from a static context
      Parameters:
      context - The context to use
      targetClass - The class to get the static scope from
      Returns:
      The static scope
    • getAnnotations

      public static IStruct getAnnotations(IBoxContext context, DynamicObject targetClass)
      Get the annotations from a static context
      Parameters:
      context - The context to use
      targetClass - The class to get the annotations from
      Returns:
      The annotations
    • canOutput

      public static Boolean canOutput(IBoxContext context, DynamicObject targetClass)
      A helper to look at the "output" annotation from a static context By default in BoxLang this is false
      Parameters:
      context - The context to use
      targetClass - The class to check
      Returns:
      Whether the function can output
    • hasAccessors

      public static Boolean hasAccessors(IClassRunnable targetClass)
      A helper to look at the "accessors" annotation By default in BoxLang this is true
      Parameters:
      targetClass - The class to check
      Returns:
      Whether the class has accessors
    • ensureClass

      public static DynamicObject ensureClass(IBoxContext context, Object obj, List<ImportDefinition> imports)
      Take an object and check if it is a dynamic object already or a string, in which case, load the class.
      Parameters:
      context - The context to use
      obj - The object to check
      imports - The imports to use
      Returns:
      The dynamic object of the class
    • validateAbstractMethods

      public static void validateAbstractMethods(IClassRunnable thisClass, Map<Key,AbstractFunction> abstractMethods)
      Vailidate if a given class instance satisfies the interface. Throws a BoxValidationException if not.
      Parameters:
      thisClass - The class to validate
      abstractMethods - The abstract methods for which to check the class for existence
      Throws:
      BoxValidationException - If the class does not satisfy the interface
    • resolveClassForUDF

      public static IClassRunnable resolveClassForUDF(IClassRunnable thisClass, Function udf)
      Given a UDF instance, resolve the actual class it was declared in. A method may be inherited by a child class, and copied down into the child class's variables scope, but at runtime, the class it uses as `super` needs to be relative to the current location.