Class MethodKey

java.lang.Object
org.codehaus.groovy.runtime.MethodKey
Direct Known Subclasses:
DefaultCachedMethodKey, DefaultMethodKey, TemporaryMethodKey

public abstract class MethodKey extends Object
An abstract base class for a key used for comparators and Map keys to look up a method by name and parameter types
  • Constructor Details

    • MethodKey

      public MethodKey(Class sender, String name, boolean isCallToSuper)
      Constructs a MethodKey for a method invocation.
      Parameters:
      sender - the class that sends the method call
      name - the method name
      isCallToSuper - whether this is a super method call
  • Method Details

    • createCopy

      public MethodKey createCopy()
      Creates an immutable copy that we can cache.
    • equals

      public boolean equals(Object that)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(MethodKey that)
      Compares sender, super-call flag, name, parameter count, and parameter types. The senders are compared with !=. Each parameter type is compared by identity, not by Object.equals(Object).

      A null that fails immediately.

      Parameters:
      that - the other key
      Returns:
      true when the sender, super-call flag, name, count, and each parameter type match
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getName

      public String getName()
      Returns the method name passed to the constructor.
      Returns:
      the method name
    • getParamterTypes

      public List getParamterTypes()
      Returns the parameter types in index order. A count of zero or less yields Collections.EMPTY_LIST, which cannot be modified. Otherwise the result is a new ArrayList and 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

      public abstract Class getParameterType(int index)
      Returns the parameter type at index. 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 contributes 1 + type.hashCode(), the super-call flag contributes 1 or 0, and the sender contributes 1 + sender.hashCode(). hashCode() caches this value and substitutes 0xcafebabe when the computed value is 0.
      Returns:
      the uncached hash, which may be 0