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.

  • 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