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

54
LINES

< > BotCompany Repo | #1018502 // call_uncached

JavaX fragment (include)

1  
// varargs assignment fixer for a single string array argument
2  
static Object call_uncached(Object o, String method, String[] arg) {
3  
  return call_uncached(o, method, new Object[] {arg});
4  
}
5  
6  
static Object call_uncached(Object o, String method, Object... args) ctex {
7  
  if (o == null) null;
8  
  if (o instanceof Class) {
9  
    Method m = call_uncached_findStaticMethod((Class) o, method, args, false);
10  
    makeAccessible(m);
11  
    return invokeMethod(m, null, args);
12  
  /*} else if (o instanceof DynamicMethods) {
13  
    ret ((DynamicMethods) o)._dynCall(method, args);*/
14  
  } else {
15  
    Method m = call_uncached_findMethod(o, method, args, false);
16  
    makeAccessible(m, true);
17  
    return invokeMethod(m, o, args);
18  
  }
19  
}
20  
21  
static Method call_uncached_findStaticMethod(Class c, String method, Object[] args, boolean debug) {
22  
  Class _c = c;
23  
  while (c != null) {
24  
    for (Method m : c.getDeclaredMethods()) {
25  
      if (debug)
26  
        System.out.println("Checking method " + m.getName() + " with " + m.getParameterTypes().length + " parameters");;
27  
      if (!m.getName().equals(method)) {
28  
        if (debug) System.out.println("Method name mismatch: " + method);
29  
        continue;
30  
      }
31  
32  
      if ((m.getModifiers() & java.lang.reflect.Modifier.STATIC) == 0 || !call_checkArgs(m, args, debug))
33  
        continue;
34  
35  
      return m;
36  
    }
37  
    c = c.getSuperclass();
38  
  }
39  
  throw new RuntimeException("Method '" + method + "' (static) with " + args.length + " parameter(s) not found in " + _c.getName());
40  
}
41  
42  
static Method call_uncached_findMethod(Object o, String method, Object[] args, boolean debug) {
43  
  Class c = o.getClass();
44  
  while (c != null) {
45  
    for (Method m : c.getDeclaredMethods()) {
46  
      if (debug)
47  
        System.out.println("Checking method " + m.getName() + " with " + m.getParameterTypes().length + " parameters");;
48  
      if (m.getName().equals(method) && call_checkArgs(m, args, debug))
49  
        return m;
50  
    }
51  
    c = c.getSuperclass();
52  
  }
53  
  throw new RuntimeException("Method '" + method + "' (non-static) with " + args.length + " parameter(s) not found in " + o.getClass().getName());
54  
}

Author comment

Began life as a copy of #1000630

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018502
Snippet name: call_uncached
Eternal ID of this version: #1018502/4
Text MD5: b8b7ed876acc60d89ac346d0211b7c23
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-31 14:02:49
Source code size: 2144 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 310 / 345
Version history: 3 change(s)
Referenced in: [show references]