Package: org.codehaus.groovy.runtime.metaclass

## [Java] Class MetaMethodIndex

- 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
    Modifiers | Name | 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
    Modifiers | Name | Description
    --- | --- | ---
    `Map<Class<?>, Map<String, Cache>>` | `indexMap` | a map of the starter class plus its super classes to save method lists for static/normal/super method calls.
    `Class<?>` | `mainClass` | The main class for which this index was created

  - ### Constructor Summary

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

  - ### Methods Summary

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

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public final Map<Class<?>, Map<String, 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.

    - #### public final Class<?> mainClass

      The main class for which this index was created

  - ### Constructor Detail

    - #### public MetaMethodIndex(CachedClass theCachedClass)

      Constructs a new MetaMethodIndex for the given class.

      Parameters:
        `theCachedClass` - the cached class for which to build the index

  - ### Method Detail

    - #### public void addMetaMethod(MetaMethod method, Map<String, Cache> map)

      Adds a metamethod to the index.

      Parameters:
        `method` - the metamethod to add
        `map` - the cache map to add the method to

    - #### 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

    - #### public void clearCaches()

      Clears all cached metamethods across all cache entries.

    - #### public void clearCaches(String name)

      Clears all cached metamethods for methods with the given name.

      Parameters:
        `name` - the method name

    - #### public void copyMethodsToSuper()

      Copies all methods to their super method counterparts in the cache index.

    - #### public void copyNonPrivateMethods(Map<String, Cache> from, Map<String, 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

    - #### public void copyNonPrivateNonNewMetaMethods(Map<String, Cache> from, Map<String, 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

    - #### public Map<String, 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

    - #### 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