Skip to content

Commit

Permalink
Add a primitive scoring mechanism to Java method selection for JRUBY-…
Browse files Browse the repository at this point in the history
…2867. We'll need to revisit this after 1.1.4, but this should at least force selection of methods that have the most exact-matching parameters. For a high percentage of cases this will probably be good enough.

git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@7556 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information
headius committed Aug 26, 2008
1 parent 343d78f commit b761531
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/org/jruby/javasupport/Java.java
Expand Up @@ -1222,13 +1222,29 @@ private static ParameterTypes findMatchingCallableForArgs(IRubyObject recv, Map
}
}
private static ParameterTypes findCallable(ParameterTypes[] callables, CallableAcceptor acceptor, IRubyObject... args) {
ParameterTypes bestCallable = null;
int bestScore = -1;
for (int k = 0; k < callables.length; k++) {
ParameterTypes callable = callables[k];
Class<?>[] types = callable.getParameterTypes();

if (acceptor.accept(types, args)) return callable;
if (acceptor.accept(types, args)) {
int currentScore = getExactnessScore(types, args);
if (currentScore > bestScore) {
bestCallable = callable;
bestScore = currentScore;
}
}
}
return null;
return bestCallable;
}

private static int getExactnessScore(Class<?>[] types, IRubyObject[] args) {
int count = 0;
for (int i = 0; i < args.length; i++) {
if (!types[i].equals(argClass(args[i]))) count++;
}
return count;
}
private static RaiseException argTypesDoNotMatch(Ruby runtime, IRubyObject receiver, ParameterTypes[] methods, IRubyObject... args) {
Object o1 = methods[0];
Expand Down

0 comments on commit b761531

Please sign in to comment.