public class ClassBuilder extends Object
CodeGenerator
, obtains the generated
source code, compiles it with the selected compiler, loads the
byte-codes into a class loader and provides the resulting
class. Compared with the ClassTransformer
mechanism,
this one requires the code generator to have generated a complete
Java class that is capable of direct compilation and loading.
This means the generated class must be a subclass of the template
so that the JVM can use normal Java inheritance to associate the
template and generated methods.
Here is how to use the plain Java technique to debug generated code:
CodeGenerator
),
set the "plain Java" options:CodeGenerator<Foo> cg = ... cg.plainJavaCapable(true); // Class supports plain Java cg.preferPlainJava(true); // Actually generate plain Java cg.saveCodeForDebugging(true); // Save code for debugging ...Note that saveCodeForDebugging automatically sets the PJ option if the generator is capable. Call preferPlainJava only if you want to try PJ for this particular generated class without saving the generated code.
Most generated classes have been upgraded to support Plain Java compilation. Once this work is complete, the calls to plainJavaCapable can be removed as all generated classes will be capable.
The setting to prefer plain Java is ignored for any remaining generated classes not marked as plain Java capable.
Modifier and Type | Field and Description |
---|---|
static String |
CODE_DIR_OPTION |
Constructor and Description |
---|
ClassBuilder(DrillConfig config,
OptionSet optionManager) |
Modifier and Type | Method and Description |
---|---|
static Class<?> |
getCompiledClass(String code,
String className,
DrillConfig config,
OptionSet options) |
Class<?> |
getImplementationClass(CodeGenerator<?> cg)
Given a code generator which has already generated plain Java
code, compile the code, create a class loader, and return the
resulting Java class.
|
public static final String CODE_DIR_OPTION
public ClassBuilder(DrillConfig config, OptionSet optionManager)
public Class<?> getImplementationClass(CodeGenerator<?> cg) throws ClassTransformationException
cg
- a plain Java capable code generator that has generated
plain Java codeClassTransformationException
public static Class<?> getCompiledClass(String code, String className, DrillConfig config, OptionSet options) throws org.codehaus.commons.compiler.CompileException, ClassNotFoundException, ClassTransformationException, IOException
org.codehaus.commons.compiler.CompileException
ClassNotFoundException
ClassTransformationException
IOException
Copyright © 1970 The Apache Software Foundation. All rights reserved.