!636 !700 // ctex !include #2000470 // class _x16 main { psvm { Class<?> solver = compileAndLoadMainClass(loadSnippet("#695")); Object case = call(solver, "parse", "#1000386"); call(solver, "calculate", case); } static Object call(Object o, String method, Object... args) ctex { findMethod(o, method, args).invoke(o, args); } static Method findMethod(Object o, String method, Object[] args) { // TODO: go to superclasses too for (Method method : theClass.getMethods()) if (method.getName().equals("main") && method.getParameterTypes().length == 1) return method; throw new RuntimeException("Method 'main' with 1 parameter not found in " + theClass.getName()); } // compile JavaX source and load main class static Class<?> compileAndLoadMainClass(String src) tex { File srcDir = _x16.TempDirMaker_make(); File classesDir = _x16.TempDirMaker_make(); _x16.saveTextFile(new File(srcDir, "main.java").getPath(), src); new List<File> libraries; File transpiledDir = _x16.topLevelTranslate(srcDir, libraries); String javacOutput = _x16.compileJava(transpiledDir, libraries, classesDir); System.out.println(javacOutput); URL[] urls = {classesDir.toURI().toURL()}; // make class loader URLClassLoader classLoader = new URLClassLoader(urls); // load main class Class<?> mainClass = classLoader.loadClass("main"); return mainClass; } }
Snippet is not live.
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
2 comment(s) hidden. show
Snippet ID: | #2000479 |
Snippet name: | Wiring runner |
Eternal ID of this version: | #2000479/1 |
Text MD5: | 8f3e5e9ff883f2bf3842874bd090152b |
Author: | stefan |
Category: | |
Type: | New Tinybrain snippet |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-08-02 01:37:17 |
Source code size: | 1495 bytes / 43 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 780 / 152 |
Referenced in: | [show references] |