Class SimpleCompiler

    • Method Detail

      • main

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

        public void setParentClassLoader​(@Nullable
                                         java.lang.ClassLoader parentClassLoader)
        Description copied from interface: ISimpleCompiler
        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
        ClassLoaders.BOOTCLASSPATH_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 ISimpleCompiler
      • setDebuggingInformation

        public void setDebuggingInformation​(boolean debugSource,
                                            boolean debugLines,
                                            boolean debugVars)
        Description copied from interface: ISimpleCompiler
        Determines what kind of debugging information is included in the generates classes. The default is typically "-g:none".
        Specified by:
        setDebuggingInformation in interface ISimpleCompiler
      • cook

        public final void cook​(@Nullable
                               java.lang.String fileName,
                               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:
        fileName - Used when reporting errors and warnings
        Throws:
        CompileException
        java.io.IOException
      • cook

        public void cook​(Scanner scanner)
                  throws CompileException,
                         java.io.IOException
        Scans, parses and compiles 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
      • getClassFiles

        public ClassFile[] getClassFiles()
        Returns:
        The ClassFiles that were generated during cooking
      • getBytecodes

        public java.util.Map<java.lang.String,​byte[]> getBytecodes()
        Specified by:
        getBytecodes in interface ICookable
        Returns:
        The generated Java bytecode; maps class name to bytes
      • 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 one of the ICookable.cook(String, java.io.Reader) methods was called.

        Specified by:
        getClassLoader in interface ISimpleCompiler
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object o)
        Two SimpleCompilers are regarded equal iff
        • Both are objects of the same class (e.g. both are ScriptEvaluators)
        • Both generated functionally equal classes as seen by Object.equals(Object)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public void setWarningHandler​(@Nullable
                                      WarningHandler warningHandler)
        Description copied from interface: ISimpleCompiler
        By default, warnings are discarded, but an application my install a custom WarningHandler which is invoked for each warning. If, for some untypical reason, that warning handler wants to terminate the compilation as quickly as possible, then it would throw a CompileException.
        Specified by:
        setWarningHandler in interface ISimpleCompiler
        Parameters:
        warningHandler - null to indicate that no warnings be issued
      • options

        public java.util.EnumSet<JaninoOption> options()
        Returns:
        A reference to the currently effective compilation options; changes to it take effect immediately
      • options

        public SimpleCompiler options​(java.util.EnumSet<JaninoOption> options)
        Sets the options for all future compilations.
      • classToType

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

        protected Java.Type[] classesToTypes​(Location location,
                                             @Nullable
                                             java.lang.Class<?>[] classes)
        Converts an array of Classes into an array ofJava.Types.
      • compileToClassLoader

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