org.apache.velocity.util.introspection
Class MethodMap
java.lang.Object
org.apache.velocity.util.introspection.MethodMap
public class MethodMap
extends java.lang.Object
$Id: MethodMap.java,v 1.15.4.1 2004/03/03 23:23:08 geirm Exp $
void | add(Method method) - Add a method to a list of methods by name.
|
Method | find(String methodName, Object[] args) -
Find a method.
|
List | get(String key) - Return a list of methods with the same name.
|
private static LinkedList | getApplicables(List methods, Class[] classes) - Returns all methods that are applicable to actual argument types.
|
private static Method | getMostSpecific(List methods, Class[] classes)
|
private static boolean | isApplicable(Method method, Class[] classes) - Returns true if the supplied method is applicable to actual
argument types.
|
private static boolean | isMethodInvocationConvertible(Class formal, Class actual) - Determines whether a type represented by a class object is
convertible to another type represented by a class object using a
method invocation conversion, treating object types of primitive
types as if they were primitive types (that is, a Boolean actual
parameter type matches boolean primitive formal type).
|
private static boolean | isStrictMethodInvocationConvertible(Class formal, Class actual) - Determines whether a type represented by a class object is
convertible to another type represented by a class object using a
method invocation conversion, without matching object and primitive
types.
|
private static int | moreSpecific(Class[] c1, Class[] c2) - Determines which method signature (represented by a class array) is more
specific.
|
INCOMPARABLE
private static final int INCOMPARABLE
LESS_SPECIFIC
private static final int LESS_SPECIFIC
MORE_SPECIFIC
private static final int MORE_SPECIFIC
methodByNameMap
(package private) Map methodByNameMap
Keep track of all methods with the same name.
add
public void add(Method method)
Add a method to a list of methods by name.
For a particular class we are keeping track
of all the methods with the same name.
find
public Method find(String methodName,
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 called
- the most specific applicable method, or null if no
method is applicable.
get
public List get(String key)
Return a list of methods with the same name.
getApplicables
private static LinkedList getApplicables(List methods,
Class[] classes)
Returns all methods that are applicable to actual argument types.
methods
- list of all candidate methodsclasses
- the actual types of the arguments
- a list that contains only applicable methods (number of
formal and actual arguments matches, and argument types are assignable
to formal types through a method invocation conversion).
isApplicable
private static boolean isApplicable(Method method,
Class[] classes)
Returns true if the supplied method is applicable to actual
argument types.
isMethodInvocationConvertible
private static boolean isMethodInvocationConvertible(Class formal,
Class actual)
Determines whether a type represented by a class object is
convertible to another type represented by a class object using a
method invocation conversion, treating object types of primitive
types as if they were primitive types (that is, a Boolean actual
parameter type matches boolean primitive formal type). This behavior
is because this method is used to determine applicable methods for
an actual parameter list, and primitive types are represented by
their object duals in reflective method calls.
formal
- the formal parameter type to which the actual
parameter type should be convertibleactual
- the actual parameter type.
- true if either formal type is assignable from actual type,
or formal is a primitive type and actual is its corresponding object
type or an object type of a primitive type that can be converted to
the formal type.
isStrictMethodInvocationConvertible
private static boolean isStrictMethodInvocationConvertible(Class formal,
Class actual)
Determines whether a type represented by a class object is
convertible to another type represented by a class object using a
method invocation conversion, without matching object and primitive
types. This method is used to determine the more specific type when
comparing signatures of methods.
formal
- the formal parameter type to which the actual
parameter type should be convertibleactual
- the actual parameter type.
- true if either formal type is assignable from actual type,
or formal and actual are both primitive types and actual can be
subject to widening conversion to formal.
moreSpecific
private static int moreSpecific(Class[] c1,
Class[] c2)
Determines which method signature (represented by a class array) is more
specific. This defines a partial ordering on the method signatures.
c1
- first signature to comparec2
- second signature to compare
- MORE_SPECIFIC if c1 is more specific than c2, LESS_SPECIFIC if
c1 is less specific than c2, INCOMPARABLE if they are incomparable.
Copyright B) 2002 Apache Software Foundation. All Rights Reserved.