Class SimpleCompiler

    • Field Detail

      • debugSource

        protected boolean debugSource
      • debugLines

        protected boolean debugLines
      • debugVars

        protected boolean debugVars
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setParentClassLoader

        public void setParentClassLoader​(java.lang.ClassLoader optionalParentClassLoader)
        Description copied from interface: ICookable
        The "parent class loader" is used to load referenced classes. Useful values are:
        System.getSystemClassLoader() The running JVM's class path
        Thread.currentThread().getContextClassLoader() or null The class loader effective for the invoking thread
        ICookable.BOOT_CLASS_LOADER The running JVM's boot class path
        The parent class loader defaults to the current thread's context class loader.
        Specified by:
        setParentClassLoader in interface ICookable
      • setDebuggingInformation

        public void setDebuggingInformation​(boolean debugSource,
                                            boolean debugLines,
                                            boolean debugVars)
        Description copied from interface: ICookable
        Determines what kind of debugging information is included in the generates classes. The default is typically '-g:none', and '-g:all' if the system property 'org.codehaus.janino.source_debugging.enable' is set to 'true'.
        Specified by:
        setDebuggingInformation in interface ICookable
      • cook

        public final void cook​(java.lang.String optionalFileName,
                               java.io.Reader r)
                        throws CompileException,
                               java.io.IOException
        Scans, parses and compiles a given compilation unit from the given Reader. After completion, getClassLoader() returns a ClassLoader that allows for access to the compiled classes.
        Specified by:
        cook in interface ICookable
        Specified by:
        cook in class Cookable
        Parameters:
        optionalFileName - Used when reporting errors and warnings.
        Throws:
        CompileException
        java.io.IOException
        See Also:
        ICookable.cook(String, Reader)
      • cook

        public void cook​(Scanner scanner)
                  throws CompileException,
                         java.io.IOException
        Scans, parses and ompiles a given compilation unit from the given scanner. After completion, getClassLoader() returns a ClassLoader that allows for access to the compiled classes.
        Throws:
        CompileException
        java.io.IOException
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Description copied from interface: ISimpleCompiler
        Returns a ClassLoader object through which the previously compiled classes can be accessed. This ClassLoader can be used for subsequent ISimpleCompilers in order to compile compilation units that use types (e.g. declare derived types) declared in the previous one.

        This method must only be called after exactly on of the ICookable.cook(String, java.io.Reader) methods was called.

        Specified by:
        getClassLoader in interface ISimpleCompiler
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • classToType

        protected Java.Type classToType​(Location location,
                                        java.lang.Class clazz)
        Wrap a reflection Class in a Java.Type object.
      • classesToTypes

        protected Java.Type[] classesToTypes​(Location location,
                                             java.lang.Class[] classes)
        Convert an array of Classes into an array ofJava.Types.
      • compileToClassLoader

        protected final java.lang.ClassLoader compileToClassLoader​(Java.CompilationUnit compilationUnit)
                                                            throws CompileException
        Compile the given compilation unit. (A "compilation unit" is typically the contents of a Java™ source file.)
        Parameters:
        compilationUnit - The parsed compilation unit
        Returns:
        The ClassLoader into which the compiled classes were defined
        Throws:
        CompileException
      • assertNotCooked

        protected void assertNotCooked()
        Throw an IllegalStateException if this Cookable is already cooked.