public class MethodMap
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
MethodMap.AmbiguousException
Simple distinguishable exception, used when
we run across ambiguous overloading.
|
private class |
MethodMap.Match |
Modifier and Type | Field and Description |
---|---|
(package private) TypeConversionHandler |
conversionHandler |
private static int |
EQUIVALENT |
private static int |
EXPLICITLY_CONVERTIBLE |
private static int |
IMPLCITLY_CONVERTIBLE |
private static int |
INCOMPARABLE |
private static int |
LESS_SPECIFIC |
(package private) java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> |
methodByNameMap
Keep track of all methods with the same name.
|
private static int |
MORE_SPECIFIC |
private static int |
NOT_CONVERTIBLE |
private static int |
STRICTLY_CONVERTIBLE |
Constructor and Description |
---|
MethodMap()
Default constructor
|
MethodMap(TypeConversionHandler conversionHandler)
Constructor with provided conversion handler
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.reflect.Method method)
Add a method to a list of methods by name.
|
private int |
compare(java.lang.reflect.Type[] t1,
java.lang.reflect.Type[] t2)
Determines which method signature (represented by a class array) is more
specific.
|
java.lang.reflect.Method |
find(java.lang.String methodName,
java.lang.Object[] args)
Find a method.
|
java.util.List<java.lang.reflect.Method> |
get(java.lang.String key)
Return a list of methods with the same name.
|
private int |
getApplicability(java.lang.reflect.Method method,
java.lang.Class<?>[] classes)
Returns the applicability of the supplied method against actual argument types.
|
private java.lang.reflect.Method |
getBestMatch(java.util.List<java.lang.reflect.Method> methods,
java.lang.Class<?>[] args) |
private boolean |
isConvertible(java.lang.reflect.Type formal,
java.lang.Class<?> actual,
boolean possibleVarArg)
Returns true if
actual is convertible to formal by implicit Java method call conversions |
private boolean |
isExplicitlyConvertible(java.lang.reflect.Type formal,
java.lang.Class<?> actual,
boolean possibleVarArg)
Returns true if
actual is convertible to formal using an explicit converter |
private static boolean |
isStrictConvertible(java.lang.reflect.Type formal,
java.lang.Class<?> actual,
boolean possibleVarArg)
Returns true if
actual is strictly convertible to formal (aka without implicit
boxing/unboxing) |
private static boolean |
onlyNullOrObjects(java.lang.Class<?>[] args) |
private static final int INCOMPARABLE
private static final int MORE_SPECIFIC
private static final int EQUIVALENT
private static final int LESS_SPECIFIC
private static final int NOT_CONVERTIBLE
private static final int EXPLICITLY_CONVERTIBLE
private static final int IMPLCITLY_CONVERTIBLE
private static final int STRICTLY_CONVERTIBLE
TypeConversionHandler conversionHandler
java.util.Map<java.lang.String,java.util.List<java.lang.reflect.Method>> methodByNameMap
public MethodMap()
public MethodMap(TypeConversionHandler conversionHandler)
conversionHandler
- conversion handlerpublic void add(java.lang.reflect.Method method)
method
- public java.util.List<java.lang.reflect.Method> get(java.lang.String key)
key
- public java.lang.reflect.Method find(java.lang.String methodName, java.lang.Object[] args) throws MethodMap.AmbiguousException
Find a method. Attempts to find the most specific applicable method using the algorithm described in the JLS section 15.12.2 (with the exception that it can't distinguish a primitive type argument from an object type argument, since in reflection primitive type arguments are represented by their object counterparts, so for an argument of type (say) java.lang.Integer, it will not be able to decide between a method that takes int and a method that takes java.lang.Integer as a parameter.
This turns out to be a relatively rare case where this is needed - however, functionality like this is needed.
methodName
- name of methodargs
- the actual arguments with which the method is calledMethodMap.AmbiguousException
- if there is more than one maximally
specific applicable methodprivate static boolean onlyNullOrObjects(java.lang.Class<?>[] args)
private java.lang.reflect.Method getBestMatch(java.util.List<java.lang.reflect.Method> methods, java.lang.Class<?>[] args)
private int compare(java.lang.reflect.Type[] t1, java.lang.reflect.Type[] t2)
t1
- first signature to comparet2
- second signature to compareprivate int getApplicability(java.lang.reflect.Method method, java.lang.Class<?>[] classes)
method
- method that will be calledclasses
- arguments to methodprivate boolean isConvertible(java.lang.reflect.Type formal, java.lang.Class<?> actual, boolean possibleVarArg)
actual
is convertible to formal
by implicit Java method call conversionsformal
- actual
- possibleVarArg
- private static boolean isStrictConvertible(java.lang.reflect.Type formal, java.lang.Class<?> actual, boolean possibleVarArg)
actual
is strictly convertible to formal
(aka without implicit
boxing/unboxing)formal
- actual
- possibleVarArg
- private boolean isExplicitlyConvertible(java.lang.reflect.Type formal, java.lang.Class<?> actual, boolean possibleVarArg)
actual
is convertible to formal
using an explicit converterformal
- actual
- possibleVarArg
-