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)

static final HashMap<S, L<Method>> callMC_cache = new HashMap;

// varargs assignment fixer for a single string array argument
static Object callMC(S method, S[] arg) {
  ret callMC(method, new O[] {arg});
}

static O callMC(S method, O... args) ctex {
  L<Method> m = callMC_cache.get(method);
  if (m == null) {
    if (callMC_cache.isEmpty()) {
      callMC_makeCache();
      m = callMC_cache.get(method);
    }
    if (m == null) fail("Method named " + method + " not found in main");
  }
  int n = m.size();
  for i to n: {
    Method me = m.get(i);
    if (call_checkArgs(me, args, false))
      ret me.invoke(null, args);
  }
  fail("No method called " + method + " with matching arguments found in main");
}

static synchronized void callMC_makeCache() {
  callMC_cache.clear();
  Class _c = (Class) mc(), c = _c;
  while (c != null) {
    for (Method m : c.getDeclaredMethods())
      if ((m.getModifiers() & Modifier.STATIC) != 0) {
        m.setAccessible(true);
        multiMapPut(callMC_cache, m.getName(), m);
      }
    c = c.getSuperclass();
  }
}

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: 428 / 427
Referenced in: [show references]