Top Description Inners Fields Constructors Methods
org.jruby.java.dispatch

public Class CallableSelector

extends Object
Class Inheritance
Imports
java.lang.reflect.Member, .Method, java.math.BigDecimal, .BigInteger, java.util.ArrayList, .Collections, .List, .Map, org.jruby.Ruby, .RubyBignum, .RubyBoolean, .RubyFixnum, .RubyFloat, .RubyInteger, .RubyProc, .RubyString, .RubySymbol, org.jruby.java.invokers.RubyToJavaInvoker, org.jruby.java.util.ClassUtils, org.jruby.javasupport.JavaCallable, .JavaUtil, .ParameterTypes, org.jruby.runtime.builtin.IRubyObject, org.jruby.util.cli.Options, org.jruby.util.collections.IntHashMap

Method selection logic for calling from Ruby to Java.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
public static interface
CallableSelector.CallableCache<
java callable type
T extends ParameterTypes
>

A cache of "callables" based on method signature hash.

private static interface

Field Summary

Modifier and TypeField and Description
private static final CallableSelector.Matcher
private static final CallableSelector.CallableAcceptor
private static final CallableSelector.CallableAcceptor
private static final CallableSelector.CallableAcceptor
private static final CallableSelector.Matcher
private static final CallableSelector.CallableAcceptor
private static final CallableSelector.Matcher
private static final CallableSelector.Matcher

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static int
private static int
private static int
private static int
private static int
argsHashCode(final IRubyObject[] args)

private static boolean
assignable(Class<?> type, final IRubyObject arg)

private static boolean
private static boolean
private static boolean
private static int
calcExactnessScore(final ParameterTypes callable, final IRubyObject[] args)

private static int
calcTypePreference(Class<?> type, final IRubyObject arg)

private static boolean
duckable(final Class<?> type, final IRubyObject arg)

private static boolean
exactMatch(ParameterTypes paramTypes, IRubyObject... args)

private static <T extends ParameterTypes> T
findCallable(T[] callables, CallableSelector.CallableAcceptor acceptor, IRubyObject[] args)

private static <T extends ParameterTypes> List<T>
findCallableCandidates(final T[] callables, final IRubyObject[] args)

private static <T extends ParameterTypes> T
findMatchingCallableForArgs(final Ruby runtime, final T[] methods, final IRubyObject... args)

private static <T extends ParameterTypes> T
findMatchingCallableForArgsFallback(final Ruby runtime, final T[] methods, final IRubyObject... args)

private static Class<?>
private static int
private static int
public static <T extends ParameterTypes> T
public static <T extends JavaCallable> T
matchingCallableArityFour(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3)

public static JavaCallable
matchingCallableArityFour(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3)
Deprecated

public static <T extends ParameterTypes> T
matchingCallableArityN(Ruby runtime, CallableSelector.CallableCache<T> cache, T[] methods, IRubyObject[] args)

public static <T extends JavaCallable> T
matchingCallableArityN(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject[] args)

public static ParameterTypes
matchingCallableArityN(Ruby runtime, Map<K, V> cache, ParameterTypes[] methods, IRubyObject[] args)
Deprecated

public static JavaCallable
matchingCallableArityN(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject[] args)
Deprecated

public static <T extends ParameterTypes> T
public static <T extends JavaCallable> T
matchingCallableArityOne(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject arg0)

public static JavaCallable
matchingCallableArityOne(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject arg0)
Deprecated

public static <T extends ParameterTypes> T
public static <T extends JavaCallable> T
matchingCallableArityThree(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2)

public static JavaCallable
matchingCallableArityThree(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2)
Deprecated

public static <T extends ParameterTypes> T
public static <T extends JavaCallable> T
matchingCallableArityTwo(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject arg0, IRubyObject arg1)

public static JavaCallable
matchingCallableArityTwo(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject arg0, IRubyObject arg1)
Deprecated

public static <T extends JavaCallable> T
matchingCallableArityZero(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods)

private static Boolean
moreSpecificTypes(final Class<T>[] msTypes, final Class<T>[] cTypes, final boolean lastArgProc)

public static <
the callable type
T extends ParameterTypes
>
IntHashMap<T>

Returns:

cache usable with CallableSelector
newCallableCache
()
Deprecated

Internal helper to allocate a callable map to cache argument method matches.

private static boolean

Returns:

Whether the argument can be directly converted to the target primitive type
primitivable
(final Class<?>
The target type
type
,
final IRubyObject
The argument to convert
arg
)

This method checks whether an argument can be *directly* converted into the target primitive, i.e. without changing from integral to floating-point.

private static int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ASSIGNABLEback to summary
private static final CallableSelector.Matcher ASSIGNABLE
AssignableAndPrimitivableback to summary
private static final CallableSelector.CallableAcceptor AssignableAndPrimitivable
AssignableAndPrimitivableWithVarargsback to summary
private static final CallableSelector.CallableAcceptor AssignableAndPrimitivableWithVarargs
AssignableOrDuckableback to summary
private static final CallableSelector.CallableAcceptor AssignableOrDuckable
DUCKABLEback to summary
private static final CallableSelector.Matcher DUCKABLE
Exactback to summary
private static final CallableSelector.CallableAcceptor Exact
EXACTback to summary
private static final CallableSelector.Matcher EXACT
PRIMITIVABLEback to summary
private static final CallableSelector.Matcher PRIMITIVABLE

Constructor Detail

CallableSelectorback to summary
private CallableSelector()

Method Detail

argsHashCodeback to summary
private static int argsHashCode(IRubyObject a0)
argsHashCodeback to summary
private static int argsHashCode(IRubyObject a0, IRubyObject a1)
argsHashCodeback to summary
private static int argsHashCode(IRubyObject a0, IRubyObject a1, IRubyObject a2)
argsHashCodeback to summary
private static int argsHashCode(IRubyObject a0, IRubyObject a1, IRubyObject a2, IRubyObject a3)
argsHashCodeback to summary
private static int argsHashCode(final IRubyObject[] args)
assignableback to summary
private static boolean assignable(Class<?> type, final IRubyObject arg)
assignableAndPrimitivableback to summary
private static boolean assignableAndPrimitivable(ParameterTypes paramTypes, IRubyObject... args)
assignableAndPrimitivableWithVarargsback to summary
private static boolean assignableAndPrimitivableWithVarargs(ParameterTypes paramTypes, IRubyObject... args)
assignableOrDuckableback to summary
private static boolean assignableOrDuckable(ParameterTypes paramTypes, IRubyObject... args)
calcExactnessScoreback to summary
private static int calcExactnessScore(final ParameterTypes callable, final IRubyObject[] args)
calcTypePreferenceback to summary
private static int calcTypePreference(Class<?> type, final IRubyObject arg)
duckableback to summary
private static boolean duckable(final Class<?> type, final IRubyObject arg)
exactMatchback to summary
private static boolean exactMatch(ParameterTypes paramTypes, IRubyObject... args)
findCallableback to summary
private static <T extends ParameterTypes> T findCallable(T[] callables, CallableSelector.CallableAcceptor acceptor, IRubyObject[] args)
findCallableCandidatesback to summary
private static <T extends ParameterTypes> List<T> findCallableCandidates(final T[] callables, final IRubyObject[] args)
Annotations
@SuppressWarnings:unchecked
findMatchingCallableForArgsback to summary
private static <T extends ParameterTypes> T findMatchingCallableForArgs(final Ruby runtime, final T[] methods, final IRubyObject... args)
findMatchingCallableForArgsFallbackback to summary
private static <T extends ParameterTypes> T findMatchingCallableForArgsFallback(final Ruby runtime, final T[] methods, final IRubyObject... args)
getJavaClassback to summary
private static Class<?> getJavaClass(final IRubyObject arg)
javaClassHashCodeback to summary
private static int javaClassHashCode(final IRubyObject arg)
javaClassOrProcHashCodeback to summary
private static int javaClassOrProcHashCode(final IRubyObject arg)
matchingCallableArityFourback to summary
public static <T extends ParameterTypes> T matchingCallableArityFour(Ruby runtime, CallableSelector.CallableCache<T> cache, T[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3)
matchingCallableArityFourback to summary
public static <T extends JavaCallable> T matchingCallableArityFour(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3)
matchingCallableArityFourback to summary
public static JavaCallable matchingCallableArityFour(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, IRubyObject arg3)

Deprecated

Annotations
@Deprecated
matchingCallableArityNback to summary
public static <T extends ParameterTypes> T matchingCallableArityN(Ruby runtime, CallableSelector.CallableCache<T> cache, T[] methods, IRubyObject[] args)
matchingCallableArityNback to summary
public static <T extends JavaCallable> T matchingCallableArityN(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject[] args)
matchingCallableArityNback to summary
public static ParameterTypes matchingCallableArityN(Ruby runtime, Map<K, V> cache, ParameterTypes[] methods, IRubyObject[] args)

Deprecated

Annotations
@SuppressWarnings:unchecked
@Deprecated
matchingCallableArityNback to summary
public static JavaCallable matchingCallableArityN(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject[] args)

Deprecated

Annotations
@SuppressWarnings:unchecked
@Deprecated
matchingCallableArityOneback to summary
public static <T extends ParameterTypes> T matchingCallableArityOne(Ruby runtime, CallableSelector.CallableCache<T> cache, T[] methods, IRubyObject arg0)
matchingCallableArityOneback to summary
public static <T extends JavaCallable> T matchingCallableArityOne(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject arg0)
matchingCallableArityOneback to summary
public static JavaCallable matchingCallableArityOne(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject arg0)

Deprecated

Annotations
@Deprecated
matchingCallableArityThreeback to summary
public static <T extends ParameterTypes> T matchingCallableArityThree(Ruby runtime, CallableSelector.CallableCache<T> cache, T[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2)
matchingCallableArityThreeback to summary
public static <T extends JavaCallable> T matchingCallableArityThree(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2)
matchingCallableArityThreeback to summary
public static JavaCallable matchingCallableArityThree(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2)

Deprecated

Annotations
@Deprecated
matchingCallableArityTwoback to summary
public static <T extends ParameterTypes> T matchingCallableArityTwo(Ruby runtime, CallableSelector.CallableCache<T> cache, T[] methods, IRubyObject arg0, IRubyObject arg1)
matchingCallableArityTwoback to summary
public static <T extends JavaCallable> T matchingCallableArityTwo(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods, IRubyObject arg0, IRubyObject arg1)
matchingCallableArityTwoback to summary
public static JavaCallable matchingCallableArityTwo(Ruby runtime, Map<K, V> cache, JavaCallable[] methods, IRubyObject arg0, IRubyObject arg1)

Deprecated

Annotations
@Deprecated
matchingCallableArityZeroback to summary
public static <T extends JavaCallable> T matchingCallableArityZero(Ruby runtime, RubyToJavaInvoker<T> invoker, T[] methods)
moreSpecificTypesback to summary
private static Boolean moreSpecificTypes(final Class<T>[] msTypes, final Class<T>[] cTypes, final boolean lastArgProc)
newCallableCacheback to summary
public static <T extends ParameterTypes> IntHashMap<T> newCallableCache()

Deprecated

Internal helper to allocate a callable map to cache argument method matches.

Parameters
<T>
the callable type
Returns:IntHashMap<T>

cache usable with CallableSelector

Annotations
@Deprecated
primitivableback to summary
private static boolean primitivable(final Class<?> type, final IRubyObject arg)

This method checks whether an argument can be *directly* converted into the target primitive, i.e. without changing from integral to floating-point.

Parameters
type:Class<?>

The target type

arg:IRubyObject

The argument to convert

Returns:boolean

Whether the argument can be directly converted to the target primitive type

procArityValueback to summary
private static int procArityValue(final IRubyObject proc)
org.jruby.java.dispatch back to summary

private Interface CallableSelector.CallableAcceptor


Method Summary

Modifier and TypeMethod and Description
public boolean

Method Detail

acceptback to summary
public boolean accept(ParameterTypes types, IRubyObject[] args)
org.jruby.java.dispatch back to summary

public Interface CallableSelector.CallableCache<T extends ParameterTypes>

Known Direct Implementers
org.jruby.javasupport.Java.JCtorCache, org.jruby.javasupport.Java.JCreateMethod
Type Parameters
<T>
java callable type

A cache of "callables" based on method signature hash.

Method Summary

Modifier and TypeMethod and Description
public T
getSignature(int signatureCode)

public void
putSignature(int signatureCode, T callable)

Method Detail

getSignatureback to summary
public T getSignature(int signatureCode)
putSignatureback to summary
public void putSignature(int signatureCode, T callable)
org.jruby.java.dispatch back to summary

private Interface CallableSelector.Matcher


Method Summary

Modifier and TypeMethod and Description
public boolean
match(final Class<?> type, final IRubyObject arg)

Method Detail

matchback to summary
public boolean match(final Class<?> type, final IRubyObject arg)