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

25
LINES

< > BotCompany Repo | #1035462 // methodApplicabilityScore_withPrimitiveWidening_onTypes

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

Libraryless. Click here for Pure Java version (259L/2K).

// returns Int.MAX_VALUE if not applicable
// returns -score if conversions are needed
// or +score if no conversions are needed
// Lower score is better
// assumes no arguments are null
static int methodApplicabilityScore_withPrimitiveWidening_onTypes(Executable m, Class[] argTypes) {
  Class<?>[] types = m.getParameterTypes();
  if (types.length != l(argTypes)) ret Int.MAX_VALUE;
  int score = 0;
  bool widenings;
  for (int i = 0; i < types.length; i++) {
    Class t = argTypes[i];
    Class c = types[i];
     
     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 #1034746

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035462
Snippet name: methodApplicabilityScore_withPrimitiveWidening_onTypes
Eternal ID of this version: #1035462/4
Text MD5: 7a11343681743768419e71f4211cb7ef
Transpilation MD5: b0434d9442d895847f841a62750799e2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-21 16:38:39
Source code size: 842 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 65 / 103
Version history: 3 change(s)
Referenced in: [show references]