public class ClassBodyEvaluator extends SimpleCompiler 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_NAMEBOOT_CLASS_LOADER| Constructor and Description |
|---|
ClassBodyEvaluator() |
| Modifier and Type | Method and Description |
|---|---|
void |
cook(String optionalFileName,
Reader r) |
protected void |
cook(String optionalFileName,
String[] imports,
Reader r) |
Object |
createInstance(Reader reader) |
Class<?> |
getClazz() |
protected Reader |
newFileName(String optionalFileName,
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 |
setDefaultImports(String... optionalDefaultImports) |
void |
setExtendedClass(Class<?> optionalExtendedType) |
void |
setExtendedType(Class<?> optionalExtendedClass)
Deprecated.
Use
setExtendedClass(Class) instead |
void |
setImplementedInterfaces(Class<?>[] implementedTypes) |
void |
setImplementedTypes(Class<?>[] implementedInterfaces)
Deprecated.
Use
setImplementedInterfaces(Class[]) instead |
addOffset, getClassLoader, setCompileErrorHandler, setDebuggingInformation, setNoPermissions, setParentClassLoader, setParentClassLoader, setPermissions, setWarningHandlercook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, readStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetClassLoader, setNoPermissions, setPermissionscook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, setCompileErrorHandler, setDebuggingInformation, setParentClassLoader, setWarningHandlerpublic void setClassName(String className)
setClassName in interface IClassBodyEvaluatorpublic void setDefaultImports(@Nullable String... optionalDefaultImports)
setDefaultImports in interface IClassBodyEvaluatorpublic void setExtendedClass(@Nullable Class<?> optionalExtendedType)
setExtendedClass in interface IClassBodyEvaluator@Deprecated public void setExtendedType(@Nullable Class<?> optionalExtendedClass)
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 cook(@Nullable String optionalFileName, Reader r) throws CompileException, IOException
cook in interface ICookablecook in class SimpleCompilerCompileExceptionIOExceptionprotected void cook(@Nullable String optionalFileName, 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 declarationsCompileExceptionIOExceptionprotected Reader newFileName(@Nullable String optionalFileName, Reader reader)
char is read from the reader.public Class<?> getClazz()
getClazz in interface IClassBodyEvaluatorClass created by the preceding call to Cookable.cook(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 © 2019. All rights reserved.