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 existant 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.
    • Constructor Detail

      • CompilerIClassLoader

        public CompilerIClassLoader​(ResourceFinder sourceFinder,
                                    IClassLoader optionalParentIClassLoader)
        Parameters:
        sourceFinder - Where to look for source files
        optionalParentIClassLoader - IClassLoader through which IClasses are to be loaded
    • Method Detail

      • findIClass

        protected IClass findIClass​(java.lang.String type)
                             throws java.lang.ClassNotFoundException
        Description copied from class: IClassLoader
        Find a new IClass by descriptor; return null if a class for that descriptor could not be found.

        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/Cls; (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 synchronized.

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

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

        Notice that the CU is not compiled here!

        Throws:
        java.lang.ClassNotFoundException
      • defineIClassFromClassFileResource

        private IClass defineIClassFromClassFileResource​(Resource classFileResource)
                                                  throws java.lang.ClassNotFoundException
        Open the given classFileResource, read its contents, define it in the IClassLoader, and resolve it (this step may involve loading more classes).
        Throws:
        java.lang.ClassNotFoundException