Class Compiler.CompilerIClassLoader

  • Enclosing class:
    Compiler

    private class Compiler.CompilerIClassLoader
    extends IClassLoader
    A specialized IClassLoader that loads IClasses from the following sources:
    1. An already-parsed compilation unit
    2. A class file in the output directory (if existent and younger than source file)
    3. A source file in any of the source path directories
    4. The parent class loader

    Notice that the Compiler.CompilerIClassLoader is an inner class of Compiler and heavily uses Compiler's members.

    • Method Detail

      • findIClass

        @Nullable
        protected IClass findIClass​(java.lang.String type)
                             throws java.lang.ClassNotFoundException
        Description copied from class: IClassLoader
        Finds a new IClass by descriptor and calls IClassLoader.defineIClass(IClass).

        Similar ClassLoader.findClass(java.lang.String), this method must

        The format of a descriptor is defined in JVMS 4.3.2. Typical descriptors are:

        • I (Integer)
        • Lpkg1/pkg2/Clazz; (Class declared in package)
        • Lpkg1/pkg2/Outer$Inner; Member class

        Notice that this method is never called for array types.

        Notice that this method is never called from more than one thread at a time. In other words, implementations of this method need not be thread-safe.

        Specified by:
        findIClass in class IClassLoader
        Parameters:
        type - field descriptor of the IClass to load, e.g. "Lpkg1/pkg2/Outer$Inner;"
        Returns:
        null if a the type could not be found
        Throws:
        java.lang.ClassNotFoundException - An exception was raised while loading the IClass
      • defineIClassFromSourceResource

        private IClass defineIClassFromSourceResource​(Resource sourceResource,
                                                      java.lang.String className)
                                               throws java.lang.ClassNotFoundException
        Parses the compilation unit stored in the given sourceResource, remembers it in Compiler.this.parsedCompilationUnits (it may declare other classes that are needed later), finds the declaration of the type with the given className, and defines it in the IClassLoader.

        Notice that the compilation unit is not compiled here!

        Throws:
        java.lang.ClassNotFoundException
      • defineIClassFromClassFileResource

        private IClass defineIClassFromClassFileResource​(Resource classFileResource)
                                                  throws java.lang.ClassNotFoundException
        Opens the given classFileResource, reads its contents, defines it in the IClassLoader, and resolves it (this step may involve loading more classes).
        Throws:
        java.lang.ClassNotFoundException