Class MethodMap
java.lang.Object
org.apache.velocity.util.introspection.MethodMap
- Version:
- $Id: MethodMap.java 935975 2010-04-20 16:04:55Z nbubna $
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Simple distinguishable exception, used when we run across ambiguous overloading. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
(package private) Map
Keep track of all methods with the same name.private static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a method to a list of methods by name.private static int
Determines which method signature (represented by a class array) is more specific.Find a method.Return a list of methods with the same name.private static Method
getBestMatch
(List methods, Class[] args) private static boolean
isApplicable
(Method method, Class[] classes) Returns true if the supplied method is applicable to actual argument types.private static boolean
isConvertible
(Class formal, Class actual, boolean possibleVarArg) private static boolean
isStrictConvertible
(Class formal, Class actual, boolean possibleVarArg)
-
Field Details
-
MORE_SPECIFIC
private static final int MORE_SPECIFIC- See Also:
-
LESS_SPECIFIC
private static final int LESS_SPECIFIC- See Also:
-
INCOMPARABLE
private static final int INCOMPARABLE- See Also:
-
methodByNameMap
Map methodByNameMapKeep track of all methods with the same name.
-
-
Constructor Details
-
MethodMap
public MethodMap()
-
-
Method Details
-
add
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.- Parameters:
method
-
-
get
Return a list of methods with the same name.- Parameters:
key
-- Returns:
- List list of methods
-
find
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.
- Parameters:
methodName
- name of methodargs
- the actual arguments with which the method is called- Returns:
- the most specific applicable method, or null if no method is applicable.
- Throws:
MethodMap.AmbiguousException
- if there is more than one maximally specific applicable method
-
getBestMatch
-
compare
Determines which method signature (represented by a class array) is more specific. This defines a partial ordering on the method signatures.- Parameters:
c1
- first signature to comparec2
- second signature to compare- Returns:
- MORE_SPECIFIC if c1 is more specific than c2, LESS_SPECIFIC if c1 is less specific than c2, INCOMPARABLE if they are incomparable.
-
isApplicable
Returns true if the supplied method is applicable to actual argument types.- Parameters:
method
- method that will be calledclasses
- arguments to method- Returns:
- true if method is applicable to arguments
-
isConvertible
-
isStrictConvertible
-