Exemple #1
0
  @SuppressWarnings({"unchecked"})
  @Override
  public XValue run(Shell shell, List<XValue> args) throws Exception {
    ClassLoader classLoader = getClass().getClassLoader();

    requires(args.size() >= 2, "object( name parent-class [name type ...]");
    String name = args.remove(0).toString();
    XValue xpclass = args.remove(0);
    Class<?> pclass = DataMappingModule.resolveClass(null, xpclass, classLoader);

    DynamicType.Builder<?> b =
        new ByteBuddy().subclass((Class<?>) (pclass != null ? pclass : Object.class)).name(name);

    while (!args.isEmpty()) {
      XValue xv = args.remove(0);
      String f = xv.toString();
      Class<?> cls = String.class;
      if (!args.isEmpty()) cls = DataMappingModule.resolveClass(null, args.remove(0), classLoader);

      b = b.defineField(f, cls, Visibility.PUBLIC);
    }

    Object bean =
        b.make()
            .load(classLoader, ClassLoadingStrategy.Default.INJECTION)
            .getLoaded()
            .newInstance();

    return XValue.newXValue((Object) bean);
  }
  @Override
  public int exec(Shell shell) throws Exception {

    XValue ret = null;

    // No argument to return
    // e.g  return ;

    if (mArg == null) ret = null; // will convert to empty sequence and set last exit value
    else {
      ret = mArg.expand(shell, mEnv);
      if (ret == null) ret = XValue.empytSequence();
    }
    shell.exec_return(ret);
    return 0;
  }