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.

// returns Int.MAX_VALUE if not applicable
// returns -score if conversions are needed
// or +score if no conversions are needed
// Lower score is better
static int methodApplicabilityScore_withPrimitiveWidening(Executable m, O[] args) {
  Class<?>[] types = m.getParameterTypes();
  if (types.length != l(args)) ret Int.MAX_VALUE;
  int score = 0;
  bool widenings;
  for (int i = 0; i < types.length; i++) {
    O a = args[i];
    Class c = types[i];
     
    // null can be assigned to any non-primitive type
    if (a == null) {
      if (c.isPrimitive())
        ret Int.MAX_VALUE;
     } else {
       Class t = a.getClass();
       
       int s = typeConversionScoreWithUnboxing(t, c);
       printVars ifdef typeConversionScore_debug("typeConversionScoreWithUnboxing", +t, +c, +s);

       if (s == Int.MAX_VALUE)
         ret Int.MAX_VALUE;
       if (s < 0) set widenings;
       score += abs(s);
     }
  }
  
  ret widenings ? -score : score;
}

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: 91 / 148
Version history: 6 change(s)
Referenced in: [show references]