Package org.codehaus.groovy.runtime
Class MethodKey
java.lang.Object
org.codehaus.groovy.runtime.MethodKey
- Direct Known Subclasses:
DefaultCachedMethodKey,DefaultMethodKey,TemporaryMethodKey
An abstract base class for a key used for comparators and Map keys to look up a method by
name and parameter types
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates an immutable copy that we can cache.protected intComputes an uncached hash from the name, each parameter type, the super-call flag, and the sender.booleanbooleanCompares sender, super-call flag, name, parameter count, and parameter types.getName()Returns the method name passed to the constructor.abstract intReturns how many parameter types this key has.abstract ClassgetParameterType(int index) Returns the parameter type atindex.Returns the parameter types in index order.inthashCode()toString()
-
Constructor Details
-
MethodKey
Constructs a MethodKey for a method invocation.- Parameters:
sender- the class that sends the method callname- the method nameisCallToSuper- whether this is a super method call
-
-
Method Details
-
createCopy
Creates an immutable copy that we can cache. -
equals
-
equals
Compares sender, super-call flag, name, parameter count, and parameter types. The senders are compared with!=. Each parameter type is compared by identity, not byObject.equals(Object).A null
thatfails immediately.- Parameters:
that- the other key- Returns:
truewhen the sender, super-call flag, name, count, and each parameter type match
-
hashCode
public int hashCode() -
toString
-
getName
Returns the method name passed to the constructor.- Returns:
- the method name
-
getParamterTypes
Returns the parameter types in index order. A count of zero or less yieldsCollections.EMPTY_LIST, which cannot be modified. Otherwise the result is a newArrayListand is not a view of this key.- Returns:
- the parameter types
-
getParameterCount
public abstract int getParameterCount()Returns how many parameter types this key has.- Returns:
- the parameter count
-
getParameterType
Returns the parameter type atindex.equals(MethodKey)compares these classes by identity.- Parameters:
index- zero-based parameter index- Returns:
- the class at that index
-
createHashCode
protected int createHashCode()Computes an uncached hash from the name, each parameter type, the super-call flag, and the sender. Each step multiplies by 37. A parameter contributes1 + type.hashCode(), the super-call flag contributes 1 or 0, and the sender contributes1 + sender.hashCode().hashCode()caches this value and substitutes0xcafebabewhen the computed value is 0.- Returns:
- the uncached hash, which may be 0
-