Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1007836 // callMC - call function in main class [OLD]

JavaX fragment (include)

1  
static final HashMap<S, L<Method>> callMC_cache = new HashMap;
2  
3  
// varargs assignment fixer for a single string array argument
4  
static Object callMC(S method, S[] arg) {
5  
  ret callMC(method, new O[] {arg});
6  
}
7  
8  
static O callMC(S method, O... args) ctex {
9  
  L<Method> m = callMC_cache.get(method);
10  
  if (m == null) {
11  
    if (callMC_cache.isEmpty()) {
12  
      callMC_makeCache();
13  
      m = callMC_cache.get(method);
14  
    }
15  
    if (m == null) fail("Method named " + method + " not found in main");
16  
  }
17  
  int n = m.size();
18  
  for i to n: {
19  
    Method me = m.get(i);
20  
    if (call_checkArgs(me, args, false))
21  
      ret me.invoke(null, args);
22  
  }
23  
  fail("No method called " + method + " with matching arguments found in main");
24  
}
25  
26  
static synchronized void callMC_makeCache() {
27  
  callMC_cache.clear();
28  
  Class _c = (Class) mc(), c = _c;
29  
  while (c != null) {
30  
    for (Method m : c.getDeclaredMethods())
31  
      if ((m.getModifiers() & Modifier.STATIC) != 0) {
32  
        m.setAccessible(true);
33  
        multiMapPut(callMC_cache, m.getName(), m);
34  
      }
35  
    c = c.getSuperclass();
36  
  }
37  
}

Author comment

Began life as a copy of #1005370

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1007836
Snippet name: callMC - call function in main class [OLD]
Eternal ID of this version: #1007836/1
Text MD5: a79ed19abd70b68e019b9aa0373aec48
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-11 14:41:22
Source code size: 1102 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 358 / 356
Referenced in: [show references]