Interface ICodeFactory

All Known Implementing Classes:
AbstractCodeFactory, GroovyCodeFactory, JavaScriptCodeFactory, PythonCodeFactory, RubyCodeFactory

public interface ICodeFactory
An ICodeFactory is capable of generating code fragments for a dedicated target language.
  • Field Details

    • RESULT_NAME

      static final String RESULT_NAME
      intermediate name of original method call return value.
      See Also:
    • TRACE_MODULE_WRAPPER

      static final boolean TRACE_MODULE_WRAPPER
      Trace enablement for module wrappers.
  • Method Details

    • getSaveVariableName

      String getSaveVariableName(String variableName)
      Converts a given string to a save variable name for the target language. Typically filters invalid characters and verifies that the returned string does not match any reserved keyword. Does not verify if the returned name is already in use.
      Parameters:
      variableName - variable name candidate
      Returns:
      converted variable name
    • classInstantiation

      String classInstantiation(Class<?> clazz, String[] parameters)
      Create code to instantiate a java class.
      Parameters:
      clazz - class to instantiate
      parameters - parameters used for class instantiation
      Returns:
      wrapped script code
    • createFunctionCall

      String createFunctionCall(Method method, Object... parameters)
      Create code to call a wrapped function.
      Parameters:
      method - method to be called
      parameters - call parameters
      Returns:
      script code to call function
    • getDefaultValue

      String getDefaultValue(ICodeFactory.Parameter parameter)
      Get the default value for a given parameter.
      Parameters:
      parameter - parameter to get default value for
      Returns:
      String representation of default value
    • createCommentedString

      String createCommentedString(String comment, boolean blockComment)
      Create code for the provided comment. Typically line or block comment tokens will be added around the comment. Start block comment token will be added immediately before comment and end block comment token will be added immediately after comment. Format comment properly to get proper result.
      Parameters:
      comment - the comment
      blockComment - true for adding block comment or false for adding (multiple) line comments
      Returns:
      the comment string with comment tokens.
    • createWrapper

      String createWrapper(IEnvironment environment, Object instance, String identifier, boolean customNamespace, IScriptEngine engine)
      Create script wrapper code for a given java instance.
      Parameters:
      environment - environment module instance
      instance - object instance to wrap
      identifier - script variable name for wrapped Java object
      customNamespace - whether to store methods to the global namespace or to create a custom object
      engine - script engine
      Returns:
      create wrapped script code