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

42
LINES

< > BotCompany Repo | #1022095 // call_withVarargs

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (5239L) is out of date.

sO call_withVarargs(O o, S methodName, O... args) ctex {
  if (o == null) null;
  
  if (o instanceof Class) {
    Class c = (Class) o;
    _MethodCache cache = callOpt_getCache(c);
    
    Method me = cache.findStaticMethod(methodName, args);
    if (me != null)
      ret invokeMethod(me, null, args);
      
    // try varargs
    L<Method> methods = cache.cache.get(methodName);
    if (methods != null) methodSearch: for (Method m : methods) {
      continue unless m.isVarArgs();
      continue unless isStaticMethod(m);
      O[] newArgs = massageArgsForVarArgsCall(m, args);
      if (newArgs != null)
        ret invokeMethod(m, null, newArgs);
    }
    
    fail("Method " + c.getName() + "." + methodName + "(" + formatArgumentClasses(args) + ") not found");
  } else {
    Class c = o.getClass();
    _MethodCache cache = callOpt_getCache(c);

    Method me = cache.findMethod(methodName, args);
    if (me != null)
      ret invokeMethod(me, o, args);
      
    // try varargs
    L<Method> methods = cache.cache.get(methodName);
    if (methods != null) methodSearch: for (Method m : methods) {
      continue unless m.isVarArgs();
      O[] newArgs = massageArgsForVarArgsCall(m, args);
      if (newArgs != null)
        ret invokeMethod(m, o, newArgs);
    }
    
    fail("Method " + c.getName() + "." + methodName + "(" + formatArgumentClasses(args) + ") not found");
  }
}

Author comment

Began life as a copy of #1018503

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022095
Snippet name: call_withVarargs
Eternal ID of this version: #1022095/14
Text MD5: 3ec123cf8e1c87d09e15de35f307247d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-01-21 16:06:59
Source code size: 1436 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 420 / 525
Version history: 13 change(s)
Referenced in: [show references]