make.java 981 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package kawa.standard;
  2. import kawa.lang.*;
  3. import gnu.mapping.*;
  4. import gnu.expr.*;
  5. public class make extends ProcedureN
  6. {
  7. public int numArgs() { return 0xFFFFF001; } // minimum 1 argument
  8. public Object applyN (Object[] args)
  9. {
  10. int nargs = args.length;
  11. if (nargs == 0)
  12. throw new WrongArguments(this, nargs);
  13. Object arg_0 = args[0];
  14. Class clas;
  15. if (arg_0 instanceof Class)
  16. clas = (Class) arg_0;
  17. else if (arg_0 instanceof gnu.bytecode.ClassType)
  18. clas = ((gnu.bytecode.ClassType) arg_0).getReflectClass();
  19. else
  20. clas = null;
  21. if (clas == null)
  22. throw new WrongType(this, 1, arg_0, "class");
  23. Object result;
  24. try
  25. {
  26. result = clas.newInstance();
  27. }
  28. catch (Exception ex)
  29. {
  30. throw new WrappedException(ex);
  31. }
  32. for (int i = 1; i < nargs; )
  33. {
  34. Keyword key = (Keyword) args[i++];
  35. Object arg = args[i++];
  36. Record.set1(arg, key.getName(), result);
  37. }
  38. return result;
  39. }
  40. }