Interface IClassBodyEvaluator

    • Method Detail

      • setParentClassLoader

        void setParentClassLoader​(@Nullable
                                  ClassLoader parentClassLoader)
        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.

      • setDebuggingInformation

        void setDebuggingInformation​(boolean debugSource,
                                     boolean debugLines,
                                     boolean debugVars)
        Determines what kind of debugging information is included in the generates classes. The default is typically "-g:none".
      • setWarningHandler

        void setWarningHandler​(@Nullable
                               WarningHandler warningHandler)
        By default, warnings are discarded, but an application my install a custom WarningHandler.
        Parameters:
        warningHandler - null to indicate that no warnings be issued
      • setDefaultImports

        void setDefaultImports​(String... defaultImports)
        "Default imports" add to the system import "java.lang", i.e. the evaluator may refer to classes imported by default imports without having to explicitly declare IMPORT statements.

        Notice that JDK 5 "static imports" are also supported, as shown here:

             sc.setDefaultImports(
                 "java.util.Map",                          // Single type import
                 "java.io.*",                              // Type-import-on-demand
                 "static java.util.Collections.EMPTY_MAP", // Single static import
                 "static java.util.Collections.*",         // Static-import-on-demand
             );
      • setClassName

        void setClassName​(String className)
        Sets the name of the generated class. Defaults to DEFAULT_CLASS_NAME. In most cases, there is no need to set this name, because the generated class is loaded into its own ClassLoader where its name cannot collide with classes generated by other evaluators.

        One reason to use this function is to have a class name in a non-default package, which can be relevant when types and members with DEFAULT accessibility are accessed.

      • setExtendedClass

        void setExtendedClass​(@Nullable
                              Class<?> extendedClass)
        Sets a particular superclass that the generated class will extend. If extendedClass is null, the generated class will extend Object.

        The usual reason to set a base class for an evaluator is that the generated class can directly access the superclass's (non-private) members.

      • setImplementedInterfaces

        void setImplementedInterfaces​(Class<?>[] implementedInterfaces)
        Sets a particular set of interfaces that the generated class will implement.
      • createInstance

        Object createInstance​(Reader reader)
                       throws CompileException,
                              IOException
        Scans, parses and compiles a class body from the tokens delivered by the the given Reader, then creates and returns an instance of that class.
        Parameters:
        reader - Source of class body tokens
        Returns:
        An object that extends the extendedType and implements the given implementedTypes
        Throws:
        CompileException
        IOException