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

24
LINES

< > BotCompany Repo | #1008683 // numberOfMethodArguments

JavaX fragment (include)

1  
static int numberOfMethodArguments(O o, S method) {
2  
  Class c;
3  
  bool mustBeStatic = false;
4  
  if (o instanceof Class) {
5  
    c = (Class) o;
6  
    mustBeStatic = true;
7  
  } else
8  
    c = o.getClass();
9  
      
10  
  Class _c = c;
11  
  int n = -1;
12  
  while (c != null) {
13  
    for (Method m : c.getDeclaredMethods()) {
14  
      if (!m.getName().equals(method)) continue;
15  
      if (mustBeStatic && !methodIsStatic(m)) continue;
16  
      int nn = l(m.getParameterTypes());
17  
      if (n == -1) n = nn;
18  
      else if (n != nn) fail("Variable number of method arguments: " + _c + "." + method);
19  
    }
20  
    c = c.getSuperclass();
21  
  }
22  
  if (n == -1) fail("Method not found: " + _c + "." + method);
23  
  ret n;
24  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv

No comments. add comment

Snippet ID: #1008683
Snippet name: numberOfMethodArguments
Eternal ID of this version: #1008683/4
Text MD5: 966ad5c2bc725bd517e1f65482735c42
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-11-05 00:29:36
Source code size: 697 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 536 / 3443
Version history: 3 change(s)
Referenced in: [show references]