public class ClassBodyEvaluator extends Cookable implements IClassBodyEvaluator
ClassBodyEvaluator object, proceed as described for IClassBodyEvaluator. Alternatively,
a number of "convenience constructors" exist that execute the described steps instantly.
Notice that this implementation of IClassBodyEvaluator is prone to "Java injection", i.e. an
application could get more than one class body compiled by passing a bogus input document.
Also notice that the parsing of leading IMPORT declarations is heuristic and has certain limitations; see
parseImportDeclarations(Reader).
IClassBodyEvaluatorDEFAULT_CLASS_NAME| Constructor and Description |
|---|
ClassBodyEvaluator() |
| Modifier and Type | Method and Description |
|---|---|
void |
cook(String fileName,
Reader r) |
protected void |
cook(String fileName,
String[] imports,
Reader r) |
Object |
createInstance(Reader reader) |
Map<String,byte[]> |
getBytecodes() |
Class<?> |
getClazz() |
String[] |
getDefaultImports() |
protected Reader |
newFileName(String fileName,
Reader reader)
Sets the given file name, and the current line number to 1, and the current column number to 1, when the first
char is read from the reader. |
protected static String[] |
parseImportDeclarations(Reader r)
Heuristically parses IMPORT declarations at the beginning of the character stream produced by the given
Reader. |
void |
setClassName(String className) |
void |
setCompileErrorHandler(ErrorHandler compileErrorHandler) |
void |
setDebuggingInformation(boolean debugSource,
boolean debugLines,
boolean debugVars) |
void |
setDefaultImports(String... defaultImports) |
void |
setExtendedClass(Class<?> extendedType) |
void |
setExtendedType(Class<?> extendedClass)
Deprecated.
Use
setExtendedClass(Class) instead |
void |
setImplementedInterfaces(Class<?>[] implementedTypes) |
void |
setImplementedTypes(Class<?>[] implementedInterfaces)
Deprecated.
Use
setImplementedInterfaces(Class[]) instead |
void |
setParentClassLoader(ClassLoader parentClassLoader) |
void |
setSourceVersion(int version) |
void |
setTargetVersion(int version) |
void |
setWarningHandler(WarningHandler warningHandler) |
cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFilepublic void setClassName(String className)
setClassName in interface IClassBodyEvaluatorpublic void setDefaultImports(String... defaultImports)
setDefaultImports in interface IClassBodyEvaluatorpublic String[] getDefaultImports()
getDefaultImports in interface IClassBodyEvaluatorpublic void setExtendedClass(@Nullable Class<?> extendedType)
setExtendedClass in interface IClassBodyEvaluator@Deprecated public void setExtendedType(@Nullable Class<?> extendedClass)
setExtendedClass(Class) insteadsetExtendedType in interface IClassBodyEvaluatorpublic void setImplementedInterfaces(Class<?>[] implementedTypes)
setImplementedInterfaces in interface IClassBodyEvaluator@Deprecated public void setImplementedTypes(Class<?>[] implementedInterfaces)
setImplementedInterfaces(Class[]) insteadsetImplementedTypes in interface IClassBodyEvaluatorpublic void setParentClassLoader(@Nullable ClassLoader parentClassLoader)
setParentClassLoader in interface IClassBodyEvaluatorpublic void setDebuggingInformation(boolean debugSource,
boolean debugLines,
boolean debugVars)
setDebuggingInformation in interface IClassBodyEvaluatorpublic void setSourceVersion(int version)
setSourceVersion in interface ICookablepublic void setTargetVersion(int version)
setTargetVersion in interface ICookablepublic void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)
setCompileErrorHandler in interface IClassBodyEvaluatorpublic void setWarningHandler(@Nullable WarningHandler warningHandler)
setWarningHandler in interface IClassBodyEvaluatorpublic void cook(@Nullable String fileName, Reader r) throws CompileException, IOException
cook in interface ICookablecook in class CookableCompileExceptionIOExceptionprotected void cook(@Nullable String fileName, String[] imports, Reader r) throws CompileException, IOException
imports - E.g. "java.io.*" or "static java.util.Arrays.asList"r - The class body to cook, without leading IMPORT declarationsCompileExceptionIOExceptionpublic Class<?> getClazz()
getClazz in interface IClassBodyEvaluatorClass created by the preceding call to Cookable.cook(Reader)public Map<String,byte[]> getBytecodes()
getBytecodes in interface ICookableprotected Reader newFileName(@Nullable String fileName, Reader reader)
char is read from the reader.protected static String[] parseImportDeclarations(Reader r) throws IOException
Reader. After this method returns, all characters up to and including that last IMPORT declaration have been
read from the Reader.
This method does not handle comments and string literals correctly, i.e. if a pattern that looks like an IMPORT declaration appears within a comment or a string literal, it will be taken as an IMPORT declaration.
r - A Reader that supports MARK, e.g. a BufferedReader{ "java.util.*", "static java.util.Map.Entry" }IOExceptionpublic Object createInstance(Reader reader) throws CompileException, IOException
createInstance in interface IClassBodyEvaluatorCompileExceptionIOExceptionCopyright © 2022. All rights reserved.