Class MetaMethodIndex
java.lang.Object
org.codehaus.groovy.runtime.metaclass.MetaMethodIndex
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 ClassesModifier and TypeClassDescriptionstatic classA cache of metamethods indexed by name.static classA cache entry for a metamethod with its parameter types. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMetaMethodIndex(CachedClass theCachedClass) Constructs a new MetaMethodIndex for the given class. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMetaMethod(MetaMethod method, Map<String, MetaMethodIndex.Cache> map) Adds a metamethod to the index.addMethodToList(Object o, MetaMethod toIndex) Adds a metamethod to a method list, handling overrides and duplicates.voidClears all cached metamethods across all cache entries.voidclearCaches(String name) Clears all cached metamethods for methods with the given name.voidCopies all methods to their super method counterparts in the cache index.voidCopies all non-private methods from one method cache map to another.voidcopyNonPrivateNonNewMetaMethods(Map<String, MetaMethodIndex.Cache> from, Map<String, MetaMethodIndex.Cache> to) Copies all non-private, non-new metamethods from one method cache map to another.Gets the method cache header for the given class.final MetaMethodIndex.CachegetMethods(Class<?> cls, String name) Gets the cached methods for a given class and method name.
-
Field Details
-
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
The main class for which this index was created
-
-
Constructor Details
-
MetaMethodIndex
Constructs a new MetaMethodIndex for the given class.- Parameters:
theCachedClass- the cached class for which to build the index
-
-
Method Details
-
getMethods
Gets the cached methods for a given class and method name.- Parameters:
cls- the class to look upname- the method name- Returns:
- the cache entry or null if not found
-
addMetaMethod
Adds a metamethod to the index.- Parameters:
method- the metamethod to addmap- the cache map to add the method to
-
getHeader
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 mapto- 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 mapto- the destination method cache map
-
addMethodToList
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
Clears all cached metamethods for methods with the given name.- Parameters:
name- the method name
-