Package: org.codehaus.groovy.runtime.metaclass

## [Java] Class MetaClassRegistryImpl

- org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl

- All Implemented Interfaces and Traits:
    MetaClassRegistry

      public class MetaClassRegistryImpl
      extends Object
      implements MetaClassRegistry

  A registry of MetaClass instances which caches introspection and reflection information and allows methods to be dynamically added to existing classes at runtime

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static int` | `DONT_LOAD_DEFAULT` |
    `static String` | `EXTENSION_DISABLE_PROPERTY` |
    `static int` | `LOAD_DEFAULT` |
    `static String` | `MODULE_META_INF_FILE` | deprecated: Use ExtensionModuleScanner.MODULE_META_INF_FILE instead

  - ### Constructor Summary

    Constructors
    Constructor and description
    `MetaClassRegistryImpl()`
    `MetaClassRegistryImpl(int loadDefault)`
    `MetaClassRegistryImpl(boolean useAccessible)` Parameters: `useAccessible` - defines whether the AccessibleObject.setAccessible method will be called to enable access to all methods when using reflection
    `MetaClassRegistryImpl(int loadDefault, boolean useAccessible)`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)` Adds a listener for constant metaclasses.
    `` | `public void` | `addNonRemovableMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)` Adds a listener for constant metaclasses.
    `` | `protected void` | `fireConstantMetaClassUpdate(Object obj, Class c, MetaClass oldMC, MetaClass newMc)` Causes the execution of all registered listeners.
    `` | `public static MetaClassRegistry` | `getInstance(int includeExtension)` Singleton of MetaClassRegistry.
    `` | `public FastArray` | `getInstanceMethods()`
    `` | `public final MetaClass` | `getMetaClass(Class theClass)`
    `` | `public MetaClass` | `getMetaClass(Object obj)`
    `` | `public MetaClassCreationHandle` | `getMetaClassCreationHandler()` Gets a handle internally used to create MetaClass implementations WARNING: experimental code, likely to change soon
    `` | `public MetaClassRegistryChangeEventListener[]` | `getMetaClassRegistryChangeEventListeners()` Gets an array of all registered ConstantMetaClassListener instances.
    `` | `public ExtensionModuleRegistry` | `getModuleRegistry()`
    `` | `public FastArray` | `getStaticMethods()`
    `` | `public boolean` | `hasNext()`
    `` | `public Iterator` | `iterator()` Returns an iterator to iterate over all constant metaclasses.
    `` | `public Object` | `next()`
    `` | `public void` | `registerExtensionModuleFromProperties(Properties properties, ClassLoader classLoader, Map<CachedClass, List<MetaMethod>> map)`
    `` | `public void` | `remove()`
    `` | `public void` | `removeMetaClass(Class theClass)`
    `` | `public void` | `removeMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)` Removes a constant metaclass listener.
    `` | `public void` | `setMetaClass(Class theClass, MetaClass theMetaClass)`
    `` | `public void` | `setMetaClass(Object obj, MetaClass theMetaClass)`
    `` | `public void` | `setMetaClassCreationHandle(MetaClassCreationHandle handle)` Sets a handle internally used to create MetaClass implementations.
    `` | `public boolean` | `useAccessible()`

  - ### Inherited Methods Summary

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

- - ### Field Detail

    - #### public static final int DONT_LOAD_DEFAULT

    - #### public static final String EXTENSION_DISABLE_PROPERTY

    - #### public static final int LOAD_DEFAULT

    - #### @Deprecated
      public static final String MODULE_META_INF_FILE

      deprecated:
        Use ExtensionModuleScanner.MODULE_META_INF_FILE instead

  - ### Constructor Detail

    - #### public MetaClassRegistryImpl()

    - #### public MetaClassRegistryImpl(int loadDefault)

    - #### public MetaClassRegistryImpl(boolean useAccessible)

      Parameters:
        `useAccessible` - defines whether the AccessibleObject.setAccessible method will be called to enable access to all methods when using reflection

    - #### public MetaClassRegistryImpl(int loadDefault, boolean useAccessible)

  - ### Method Detail

    - #### @Override
      public void addMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)

      Adds a listener for constant metaclasses.

      Parameters:
        `listener` - the listener

    - #### @Override
      public void addNonRemovableMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)

      Adds a listener for constant metaclasses. This listener cannot be removed!

      Parameters:
        `listener` - the listener

    - #### protected void fireConstantMetaClassUpdate(Object obj, Class c, MetaClass oldMC, MetaClass newMc)

      Causes the execution of all registered listeners. This method is used mostly internal to kick of the listener notification. It can also be used by subclasses to achieve the same.

      Parameters:
        `obj` - object instance if the MetaClass change is on a per-instance metaclass (or null if global)
        `c` - the class
        `oldMC` - the old MetaClass
        `newMc` - the new MetaClass

    - #### public static MetaClassRegistry getInstance(int includeExtension)

      Singleton of MetaClassRegistry.

      Parameters:
        includeExtension
      Returns:
        the registry

    - #### public FastArray getInstanceMethods()

    - #### @Override
      public final MetaClass getMetaClass(Class theClass)

    - #### public MetaClass getMetaClass(Object obj)

    - #### @Override
      public MetaClassCreationHandle getMetaClassCreationHandler()

      Gets a handle internally used to create MetaClass implementations WARNING: experimental code, likely to change soon

      Returns:
        the handle

    - #### @Override
      public MetaClassRegistryChangeEventListener[] getMetaClassRegistryChangeEventListeners()

      Gets an array of all registered ConstantMetaClassListener instances.

    - #### public ExtensionModuleRegistry getModuleRegistry()

    - #### public FastArray getStaticMethods()

    - #### @Override
      public boolean hasNext()

    - #### @Override
      public Iterator iterator()

      Returns an iterator to iterate over all constant metaclasses. This iterator can be seen as making a snapshot of the current state of the registry. The snapshot will include all metaclasses that has been used unless they are already collected. Collected metaclasses will be skipped automatically, so you can expect that each element of the iteration is not null. Calling this method is thread safe, the usage of the iterator is not.

      Returns:
        the iterator.

    - #### @Override
      public Object next()

    - #### public void registerExtensionModuleFromProperties(Properties properties, ClassLoader classLoader, Map<CachedClass, List<MetaMethod>> map)

    - #### @Override
      public void remove()

    - #### @Override
      public void removeMetaClass(Class theClass)

    - #### @Override
      public void removeMetaClassRegistryChangeEventListener(MetaClassRegistryChangeEventListener listener)

      Removes a constant metaclass listener.

      Parameters:
        `listener` - the listener

    - #### @Override
      public void setMetaClass(Class theClass, MetaClass theMetaClass)

    - #### public void setMetaClass(Object obj, MetaClass theMetaClass)

    - #### @Override
      public void setMetaClassCreationHandle(MetaClassCreationHandle handle)

      Sets a handle internally used to create MetaClass implementations. When replacing the handle with a custom version, you should reuse the old handle to keep custom logic and to use the default logic as fall back. WARNING: experimental code, likely to change soon

      Parameters:
        `handle` - the handle

    - #### public boolean useAccessible()