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

32
LINES

< > BotCompany Repo | #1034746 // methodApplicabilityScore_withPrimitiveWidening

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

Transpiled version (5384L) is out of date.

1  
// returns Int.MAX_VALUE if not applicable
2  
// returns -score if conversions are needed
3  
// or +score if no conversions are needed
4  
// Lower score is better
5  
static int methodApplicabilityScore_withPrimitiveWidening(Executable m, O[] args) {
6  
  Class<?>[] types = m.getParameterTypes();
7  
  if (types.length != l(args)) ret Int.MAX_VALUE;
8  
  int score = 0;
9  
  bool widenings;
10  
  for (int i = 0; i < types.length; i++) {
11  
    O a = args[i];
12  
    Class c = types[i];
13  
     
14  
    // null can be assigned to any non-primitive type
15  
    if (a == null) {
16  
      if (c.isPrimitive())
17  
        ret Int.MAX_VALUE;
18  
     } else {
19  
       Class t = a.getClass();
20  
       
21  
       int s = typeConversionScoreWithUnboxing(t, c);
22  
       printVars ifdef typeConversionScore_debug("typeConversionScoreWithUnboxing", +t, +c, +s);
23  
24  
       if (s == Int.MAX_VALUE)
25  
         ret Int.MAX_VALUE;
26  
       if (s < 0) set widenings;
27  
       score += abs(s);
28  
     }
29  
  }
30  
  
31  
  ret widenings ? -score : score;
32  
}

Author comment

Began life as a copy of #1007854

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034746
Snippet name: methodApplicabilityScore_withPrimitiveWidening
Eternal ID of this version: #1034746/7
Text MD5: d9e6563f74949da1a5a528f354cd2d06
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-19 20:25:59
Source code size: 989 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 171 / 251
Version history: 6 change(s)
Referenced in: [show references]