org.apache.commons.jexl2.internal.introspection
Class MethodKey

java.lang.Object
  extended by org.apache.commons.jexl2.internal.introspection.MethodKey

public final class MethodKey
extends Object

A method key usable by the introspector cache.

This stores a method (or class) name and parameters.

This replaces the original key scheme which used to build the key by concatenating the method name and parameters class names as one string with the exception that primitive types were converted to their object class equivalents.

The key is still based on the same information, it is just wrapped in an object instead. Primitive type classes are converted to they object equivalent to make a key; int foo(int) and int foo(Integer) do generate the same key.

A key can be constructed either from arguments (array of objects) or from parameters (array of class). Roughly 3x faster than string key to access the map & uses less memory.


Nested Class Summary
static class MethodKey.AmbiguousException
          Simple distinguishable exception, used when we run across ambiguous overloading.
 
Constructor Summary
MethodKey(String aMethod, Object[] args)
          Creates a key from a method name and a set of arguments.
 
Method Summary
 String debugString()
          Outputs a human readable debug representation of this key.
 boolean equals(Object obj)
          
 Constructor<?> getMostSpecificConstructor(List<Constructor<?>> methods)
          Gets the most specific constructor that is applicable to the parameters of this key.
 Method getMostSpecificMethod(List<Method> methods)
          Gets the most specific method that is applicable to the parameters of this key.
 int hashCode()
          
static boolean isInvocationConvertible(Class<?> formal, Class<?> actual, boolean possibleVarArg)
          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).
static boolean isStrictInvocationConvertible(Class<?> formal, Class<?> actual, boolean possibleVarArg)
          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.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodKey

public MethodKey(String aMethod,
                 Object[] args)
Creates a key from a method name and a set of arguments.

Parameters:
aMethod - the method to generate the key from
args - the intended method arguments
Method Detail

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

toString

public String toString()

Overrides:
toString in class Object

debugString

public String debugString()
Outputs a human readable debug representation of this key.

Returns:
method(p0, p1, ...)

getMostSpecificMethod

public Method getMostSpecificMethod(List<Method> methods)
Gets the most specific method that is applicable to the parameters of this key.

Parameters:
methods - a list of methods.
Returns:
the most specific method.
Throws:
MethodKey.AmbiguousException - if there is more than one.

getMostSpecificConstructor

public Constructor<?> getMostSpecificConstructor(List<Constructor<?>> methods)
Gets the most specific constructor that is applicable to the parameters of this key.

Parameters:
methods - a list of constructors.
Returns:
the most specific constructor.
Throws:
MethodKey.AmbiguousException - if there is more than one.

isInvocationConvertible

public static boolean isInvocationConvertible(Class<?> formal,
                                              Class<?> actual,
                                              boolean possibleVarArg)
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.

Parameters:
formal - the formal parameter type to which the actual parameter type should be convertible
actual - the actual parameter type.
possibleVarArg - whether or not we're dealing with the last parameter in the method declaration
Returns:
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.

isStrictInvocationConvertible

public static boolean isStrictInvocationConvertible(Class<?> formal,
                                                    Class<?> actual,
                                                    boolean possibleVarArg)
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.

Parameters:
formal - the formal parameter type to which the actual parameter type should be convertible
actual - the actual parameter type.
possibleVarArg - whether or not we're dealing with the last parameter in the method declaration
Returns:
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.


Copyright © 2001-2011 The Apache Software Foundation. All Rights Reserved.