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

37
LINES

< > BotCompany Repo | #1007832 // callMC_cached [OLD]

JavaX fragment (include) [tags: archive]

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_cached(S method, S[] arg) {
5  
  ret callMC(method, new O[] {arg});
6  
}
7  
8  
static O callMC_cached(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 #1000630

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): cfunsshuasjs, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1007832
Snippet name: callMC_cached [OLD]
Eternal ID of this version: #1007832/8
Text MD5: 0604b162105848aafc288151c86087f1
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): Yes
Created/modified: 2017-04-11 14:11:19
Source code size: 1116 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 362 / 364
Version history: 7 change(s)
Referenced in: [show references]