Module jEdit

Class BeanShellFacade<T>

java.lang.Object
org.gjt.sp.jedit.BeanShellFacade<T>

public abstract class BeanShellFacade<T> extends Object
This class will be the interface for beanshell interaction. In jEdit it will be used with the static methods of BeanShell
Since:
jEdit 4.3pre13
Author:
Matthieu Casanova
  • Field Details

  • Constructor Details

    • BeanShellFacade

      protected BeanShellFacade()
  • Method Details

    • init

      protected void init()
      Initialize things. It is called by the constructor. You can override it to import other packages
    • evalSelection

      public void evalSelection(T param, TextArea textArea)
      Evaluates the text selected in the specified text area.
      Parameters:
      param - some sort of parameter
      textArea - the textArea
    • eval

      public Object eval(T param, String command)
      Evaluates the specified BeanShell expression with the global namespace
      Parameters:
      param - The parameter
      command - The expression
      Returns:
      an object
    • eval

      public Object eval(T param, NameSpace namespace, String command)
      Evaluates the specified BeanShell expression. Errors are reported in a dialog box.
      Parameters:
      param - The parameter
      namespace - The namespace
      command - The expression
      Returns:
      an object
    • _eval

      public Object _eval(T view, NameSpace namespace, String command) throws Exception
      Evaluates the specified BeanShell expression. Unlike eval(), this method passes any exceptions to the caller.
      Parameters:
      view - The view. Within the script, references to buffer, textArea and editPane are determined with reference to this parameter.
      namespace - The namespace
      command - The expression
      Returns:
      an object
      Throws:
      Exception - instances are thrown when various BeanShell errors occur
    • cacheBlock

      public BshMethod cacheBlock(String id, String code, boolean namespace) throws Exception
      Caches a block of code, returning a handle that can be passed to runCachedBlock().
      Parameters:
      id - An identifier.
      code - The code
      namespace - If true, the namespace will be set
      Returns:
      a hsh method
      Throws:
      Exception - instances are thrown when various BeanShell errors occur
    • runCachedBlock

      public Object runCachedBlock(BshMethod method, T param, NameSpace namespace) throws Exception
      Runs a cached block of code in the specified namespace. Faster than evaluating the block each time.
      Parameters:
      method - The method instance returned by cacheBlock()
      param - a parameter
      namespace - The namespace to run the code in
      Returns:
      an object
      Throws:
      Exception - instances are thrown when various BeanShell errors occur
    • getNameSpace

      public NameSpace getNameSpace()
      Returns:
      the global namespace.
    • setVariable

      protected void setVariable(NameSpace nameSpace, String name, Object object) throws UtilEvalError
      Set a beanshell variable in the namespace without overriding it
      Parameters:
      nameSpace - the namespace
      name - the name of the variable
      object - the value of the variable
      Throws:
      UtilEvalError - when there is an error
    • setupDefaultVariables

      protected abstract void setupDefaultVariables(NameSpace namespace, T param) throws UtilEvalError
      Throws:
      UtilEvalError
    • resetDefaultVariables

      protected abstract void resetDefaultVariables(NameSpace namespace) throws UtilEvalError
      Throws:
      UtilEvalError
    • handleException

      protected abstract void handleException(T param, String path, Throwable t)
    • createInterpreter

      protected static Interpreter createInterpreter(NameSpace nameSpace)
    • unwrapException

      protected static void unwrapException(Exception e) throws Exception
      This extracts an exception from a 'wrapping' exception, as BeanShell sometimes throws. This gives the user a more accurate error traceback
      Parameters:
      e - the exception
      Throws:
      Exception - on error