Class ReflectorLoader


public class ReflectorLoader
extends java.lang.ClassLoader
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).
  • Constructor Summary

    Constructor Description
    ReflectorLoader​(java.lang.ClassLoader parent)
    creates a ReflectorLoader.
  • Method Summary

    Modifier and Type Method Description
    java.lang.Class defineClass​(java.lang.String name, byte[] bytecode, domain)
    helper method to define Reflector classes.
    protected java.lang.Class findClass​(java.lang.String name)
    Tries to find a Groovy class.
    java.lang.Class getLoadedClass​(java.lang.String name)
    try to load one of the defined Reflector classes by name.
    protected java.lang.Class loadClass​(java.lang.String name, boolean resolve)
    Loads a class per name.

    Methods inherited from class java.lang.ClassLoader

    clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ReflectorLoader

      public ReflectorLoader​(java.lang.ClassLoader parent)
      creates a ReflectorLoader.
      parent - the parent loader. This should never be null!
  • Method Details

    • findClass

      protected java.lang.Class findClass​(java.lang.String name) throws java.lang.ClassNotFoundException
      Tries to find a Groovy class.
      findClass in class java.lang.ClassLoader
      the class if found
      java.lang.ClassNotFoundException - if not found
    • loadClass

      protected java.lang.Class loadClass​(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
      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.
      loadClass in class java.lang.ClassLoader
      name - of the class to load
      resolve - is true if the class should be resolved
      See Also:
      Reflector, ClassLoader.loadClass(String, boolean)
    • defineClass

      public java.lang.Class defineClass​(java.lang.String name, byte[] bytecode, domain)
      helper method to define Reflector classes.
      name - of the Reflector
      bytecode - the bytecode
      domain - the protection domain
      the generated class
    • getLoadedClass

      public java.lang.Class getLoadedClass​(java.lang.String name)
      try to load one of the defined Reflector classes by name.
      name - of the Reflector class
      the Reflector class if defined else null.