Example #1
0
  /**
   * Runs a cached block of code in the specified namespace. Faster than evaluating the block each
   * time.
   *
   * @param method The method instance returned by cacheBlock()
   * @param namespace The namespace to run the code in
   * @return Description of the Return Value
   * @exception Exception instances are thrown when various BeanShell errors occur
   * @since jEdit 4.1pre1
   */
  public Object runCachedBlock(BshMethod method, NameSpace namespace) throws Exception {
    boolean useNamespace;
    if (namespace == null) {
      useNamespace = false;
      namespace = global;
    } else {
      useNamespace = true;
    }

    try {
      setupDefaultVariables(namespace);

      Object retVal =
          method.invoke(
              useNamespace ? new Object[] {namespace} : NO_ARGS, interpForMethods, new CallStack());
      if (retVal instanceof Primitive) {
        if (retVal == Primitive.VOID) {
          return null;
        } else {
          return ((Primitive) retVal).getValue();
        }
      } else {
        return retVal;
      }
    } catch (Exception e) {
      unwrapException(e);
      // never called
      return null;
    } finally {
      resetDefaultVariables(namespace);
    }
  } // }}}
 @Override
 public String invoke(final Object[] parameters) throws Exception {
   Object result;
   synchronized (interpreter) {
     result = method.invoke(parameters, interpreter);
   }
   if (result instanceof String) return ((String) result);
   else return (null);
 }
Example #3
0
    /**
     * 调用一个方法
     *
     * @param methodName 方法名
     * @param args 参数
     * @throws EvalError
     */
    private void callMethod(String methodName, Object[] args) throws EvalError {
      if (TextUtils.isEmpty(methodName)) {
        return;
      }

      Class[] classes = getMethodArgumentClass(args);
      BshMethod method = getMethod(methodName, classes);

      if (method == null) {
        L.i("cannot find " + methodName + "() in " + nickName);
        return;
      }

      method.invoke(args, getInterpreter());
    }