Package org.codehaus.groovy.runtime.metaclass

# Class MetaMethodIndex

java.lang.Object
org.codehaus.groovy.runtime.metaclass.MetaMethodIndex

public class MetaMethodIndex extends Object
An index of metamethods for a class, organized by method name and signature. Provides efficient lookup of methods for static, normal, and super method calls. Uses caching to optimize method lookup performance.

This class is for internal use by the Groovy runtime's metaclass system.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `MetaMethodIndex.Cache`
  A cache of metamethods indexed by name.
  `static class`
  `MetaMethodIndex.MetaMethodCache`
  A cache entry for a metamethod with its parameter types.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `final Map<Class<?>,Map<String,MetaMethodIndex.Cache>>`
  `indexMap`
  a map of the starter class plus its super classes to save method lists for static/normal/super method calls.
  `final Class<?>`
  `mainClass`
  The main class for which this index was created

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MetaMethodIndex(CachedClass theCachedClass)`
  Constructs a new MetaMethodIndex for the given class.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addMetaMethod(MetaMethod method, Map<String,MetaMethodIndex.Cache> map)`
  Adds a metamethod to the index.
  `Object`
  `addMethodToList(Object o, MetaMethod toIndex)`
  Adds a metamethod to a method list, handling overrides and duplicates.
  `void`
  `clearCaches()`
  Clears all cached metamethods across all cache entries.
  `void`
  `clearCaches(String name)`
  Clears all cached metamethods for methods with the given name.
  `void`
  `copyMethodsToSuper()`
  Copies all methods to their super method counterparts in the cache index.
  `void`
  `copyNonPrivateMethods(Map<String,MetaMethodIndex.Cache> from, Map<String,MetaMethodIndex.Cache> to)`
  Copies all non-private methods from one method cache map to another.
  `void`
  `copyNonPrivateNonNewMetaMethods(Map<String,MetaMethodIndex.Cache> from, Map<String,MetaMethodIndex.Cache> to)`
  Copies all non-private, non-new metamethods from one method cache map to another.
  `Map<String,MetaMethodIndex.Cache>`
  `getHeader(Class<?> cls)`
  Gets the method cache header for the given class.
  `final MetaMethodIndex.Cache`
  `getMethods(Class<?> cls, String name)`
  Gets the cached methods for a given class and method name.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### indexMap

    public final Map<Class<?>,Map<String,MetaMethodIndex.Cache>> indexMap
    a map of the starter class plus its super classes to save method lists for static/normal/super method calls. It also provides a simple cache of one method name and call signature to method per static/normal/super call.

  - ### mainClass

    public final Class<?> mainClass
    The main class for which this index was created

- ## Constructor Details

  - ### MetaMethodIndex

    public MetaMethodIndex(CachedClass theCachedClass)
    Constructs a new MetaMethodIndex for the given class.
    Parameters:
      `theCachedClass` - the cached class for which to build the index

- ## Method Details

  - ### getMethods

    public final MetaMethodIndex.Cache getMethods(Class<?> cls, String name)
    Gets the cached methods for a given class and method name.
    Parameters:
      `cls` - the class to look up
      `name` - the method name
    Returns:
      the cache entry or null if not found

  - ### addMetaMethod

    public void addMetaMethod(MetaMethod method, Map<String,MetaMethodIndex.Cache> map)
    Adds a metamethod to the index.
    Parameters:
      `method` - the metamethod to add
      `map` - the cache map to add the method to

  - ### getHeader

    public Map<String,MetaMethodIndex.Cache> getHeader(Class<?> cls)
    Gets the method cache header for the given class.
    Parameters:
      `cls` - the class
    Returns:
      the method cache map or null if not found

  - ### copyNonPrivateMethods

    public void copyNonPrivateMethods(Map<String,MetaMethodIndex.Cache> from, Map<String,MetaMethodIndex.Cache> to)
    Copies all non-private methods from one method cache map to another.
    Parameters:
      `from` - the source method cache map
      `to` - the destination method cache map

  - ### copyNonPrivateNonNewMetaMethods

    public void copyNonPrivateNonNewMetaMethods(Map<String,MetaMethodIndex.Cache> from, Map<String,MetaMethodIndex.Cache> to)
    Copies all non-private, non-new metamethods from one method cache map to another.
    Parameters:
      `from` - the source method cache map
      `to` - the destination method cache map

  - ### addMethodToList

    public Object addMethodToList(Object o, MetaMethod toIndex)
    Adds a metamethod to a method list, handling overrides and duplicates. Returns either a single MetaMethod, a FastArray of methods, or the original object.
    Parameters:
      `o` - the existing method list (can be null, a MetaMethod, or a FastArray)
      `toIndex` - the metamethod to add
    Returns:
      the updated method list

  - ### copyMethodsToSuper

    public void copyMethodsToSuper()
    Copies all methods to their super method counterparts in the cache index.

  - ### clearCaches

    public void clearCaches()
    Clears all cached metamethods across all cache entries.

  - ### clearCaches

    public void clearCaches(String name)
    Clears all cached metamethods for methods with the given name.
    Parameters:
      `name` - the method name