Libraryless. Click here for Pure Java version (2117L/13K).
1 | static HashMap<S, L<Method>> callMC_cache = new HashMap; |
2 | static S callMC_key; |
3 | static Method callMC_value; |
4 | |
5 | // varargs assignment fixer for a single string array argument |
6 | static Object callMC(S method, S[] arg) {
|
7 | ret callMC(method, new O[] {arg});
|
8 | } |
9 | |
10 | static O callMC(S method, O... args) ctex {
|
11 | Method me; |
12 | if (callMC_cache == null) callMC_cache = new HashMap; // initializer time workaround |
13 | synchronized(callMC_cache) {
|
14 | me = method == callMC_key ? callMC_value : null; |
15 | } |
16 | if (me != null) try {
|
17 | ret invokeMethod(me, null, args); |
18 | } catch (IllegalArgumentException e) {
|
19 | throw new RuntimeException("Can't call " + me + " with arguments " + classNames(args), e);
|
20 | } |
21 | |
22 | L<Method> m; |
23 | synchronized(callMC_cache) {
|
24 | m = callMC_cache.get(method); |
25 | } |
26 | if (m == null) {
|
27 | if (callMC_cache.isEmpty()) {
|
28 | callMC_makeCache(); |
29 | m = callMC_cache.get(method); |
30 | } |
31 | if (m == null) fail("Method named " + method + " not found in main");
|
32 | } |
33 | int n = m.size(); |
34 | if (n == 1) {
|
35 | me = m.get(0); |
36 | synchronized(callMC_cache) {
|
37 | callMC_key = method; |
38 | callMC_value = me; |
39 | } |
40 | try {
|
41 | ret invokeMethod(me, null, args); |
42 | } catch (IllegalArgumentException e) {
|
43 | throw new RuntimeException("Can't call " + me + " with arguments " + classNames(args), e);
|
44 | } |
45 | } |
46 | for i to n: {
|
47 | me = m.get(i); |
48 | if (call_checkArgs(me, args, false)) |
49 | ret invokeMethod(me, null, args); |
50 | } |
51 | fail("No method called " + method + " with arguments (" + joinWithComma(getClasses(args)) + ") found in main");
|
52 | } |
53 | |
54 | static void callMC_makeCache() {
|
55 | synchronized(callMC_cache) {
|
56 | callMC_cache.clear(); |
57 | Class _c = (Class) mc(), c = _c; |
58 | while (c != null) {
|
59 | for (Method m : c.getDeclaredMethods()) |
60 | if ((m.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0) {
|
61 | makeAccessible(m); |
62 | multiMapPut(callMC_cache, m.getName(), m); |
63 | } |
64 | c = c.getSuperclass(); |
65 | } |
66 | } |
67 | } |
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1005370 |
| Snippet name: | callMC - call function in main class |
| Eternal ID of this version: | #1005370/16 |
| Text MD5: | d6d257d7568bc1f8e4cc6329c0146862 |
| Transpilation MD5: | de25577a3d86202fafd0c455241400ea |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-09-17 02:17:06 |
| Source code size: | 2023 bytes / 67 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1084 / 1336 |
| Version history: | 15 change(s) |
| Referenced in: | [show references] |