[Java] Class ReflectorLoader

  • org.codehaus.groovy.runtime.metaclass.ReflectorLoader

Reflector creation helper. This class is used to define the Reflector classes. For each ClassLoader such a loader will be created by MetaClass. Special about this loader is, that it knows the classes form the Groovy Runtime. The Reflector class is resolved in different ways: During the definition of a class Reflector will resolve to the Reflector class of the runtime, even if there is another Reflector class in the parent loader. After the new class is defined Reflector will resolve like other Groovy classes. This loader is able to resolve all Groovy classes even if the parent does not know them, but the parent serves first (Reflector during a class definition is different).

Authors:
Jochen Theodorou

Constructor Summary

Constructors
Constructor and description
ReflectorLoader (ClassLoader parent)
creates a ReflectorLoader.

Methods Summary

Methods
Type Params Return Type Name and description
Class defineClass(String name, byte[] bytecode, ProtectionDomain domain)
helper method to define Reflector classes.
protected Class findClass(String name)
Tries to find a Groovy class.
Class getLoadedClass(String name)
try to load one of the defined Reflector classes by name.
protected Class loadClass(String name, boolean resolve)
Loads a class per name.

Inherited Methods Summary

Inherited Methods
Methods inherited from class Name
class ClassLoader loadClass, getSystemClassLoader, getResource, getResourceAsStream, getSystemResource, getSystemResourceAsStream, clearAssertionStatus, getParent, getResources, getSystemResources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
class Object wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Constructor Detail

public ReflectorLoader(ClassLoader parent)

creates a ReflectorLoader.

Parameters:
parent - the parent loader. This should never be null!

Method Detail

public Class defineClass(String name, byte[] bytecode, ProtectionDomain domain)

helper method to define Reflector classes.

Parameters:
name - of the Reflector
bytecode - the bytecode
domain - the protection domain
Returns:
the generated class

protected Class findClass(String name)

Tries to find a Groovy class.

throws:
ClassNotFoundException if not found
Returns:
the class if found

public Class getLoadedClass(String name)

try to load one of the defined Reflector classes by name.

Parameters:
name - of the Reflector class
Returns:
the Reflector class if defined else null.

protected Class loadClass(String name, boolean resolve)

Loads a class per name. Unlike a normal loadClass this version behaves different during a class definition. In that case it checks if the class we want to load is Reflector and returns class if the check is successful. If it is not during a class definition it just calls the super class version of loadClass.

Parameters:
name - of the class to load
resolve - is true if the class should be resolved
See Also:
Reflector
ClassLoader.loadClass

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.4.21/html/gapi/org/codehaus/groovy/runtime/metaclass/ReflectorLoader.html