@@ -0,0 +1,2239 @@
+package ch.deletescape.jterm.commandcontexts;%0A%0Aimport java.lang.reflect.Constructor;%0Aimport java.lang.reflect.Method;%0Aimport java.net.MalformedURLException;%0Aimport java.net.URL;%0Aimport java.net.URLClassLoader;%0A%0Aimport ch.deletescape.jterm.CommandUtils;%0Aimport ch.deletescape.jterm.JTerm;%0Aimport ch.deletescape.jterm.io.Printer;%0A%0Apublic class Reflect extends CommandContext %7B%0A  private static final BetterURLClassLoader CL = new BetterURLClassLoader(new URL%5B0%5D);%0A%0A  @Override%0A  protected void init() %7B%0A    CommandUtils.addListener(%22loadjar%22, this::load);%0A    CommandUtils.addListener(%22class%22, this::clazz);%0A  %7D%0A%0A  private String load(String args) throws MalformedURLException %7B%0A    URL url = JTerm.getCurrPath().resolve(args).toUri().toURL();%0A    CL._addURL(url);%0A    return %22%22;%0A  %7D%0A%0A  private String clazz(String arg) throws Exception %7B%0A    String%5B%5D args = arg.split(%22 %22);%0A    String classname = args%5B0%5D;%0A    Printer.out.println(%22Loading class %25s...%22, classname);%0A    Class%3C?%3E clazz = CL.loadClass(classname);%0A    Printer.out.println(%22   Name: %25s%22, clazz.getSimpleName());%0A    if (args.length %3E 1) %7B%0A      Printer.out.println(%22 Creating new instance of %25s...%22, clazz.getSimpleName());%0A      Constructor%3C?%3E constr = clazz.getDeclaredConstructor();%0A      if (!constr.isAccessible()) %7B%0A        Printer.out.println(%22  Default constructor not accessible, forcing access%22);%0A        constr.setAccessible(true);%0A      %7D%0A      Object obj = constr.newInstance();%0A      Printer.out.println(%22 Getting method %25s...%22, args%5B1%5D);%0A      Method m = clazz.getDeclaredMethod(args%5B1%5D);%0A      if (!m.isAccessible()) %7B%0A        Printer.out.println(%22    Method not accessible, forcing access...%22);%0A        m.setAccessible(true);%0A      %7D%0A      Printer.out.println(%22    Method accessible...%22);%0A      Printer.out.println(%22  Invoking method %5C%22%25s%5C%22 on previously created object of %25s...%22, m.toString(),%0A          clazz.toString());%0A      Object result = m.invoke(obj);%0A      Printer.out.println(%22    Success! --- Result: %25s%22, result);%0A    %7D%0A    return %22%22;%0A  %7D%0A%0A  private static class BetterURLClassLoader extends URLClassLoader %7B%0A%0A    public BetterURLClassLoader(URL%5B%5D urls) %7B%0A      super(urls);%0A    %7D%0A%0A    public void _addURL(URL url) %7B%0A      addURL(url);%0A    %7D%0A  %7D%0A%7D%0A

Add a reflection command context