Web Site

org.codehaus.janino
Class EvaluatorBase

java.lang.Object
  extended byorg.codehaus.janino.EvaluatorBase
Direct Known Subclasses:
ClassBodyEvaluator, ExpressionEvaluator, ScriptEvaluator, SimpleCompiler

public class EvaluatorBase
extends Object

Utilities for the various "...Evaluator" classes.


Constructor Summary
protected EvaluatorBase(ClassLoader optionalParentClassLoader)
          Construct with the given ClassLoader.
 
Method Summary
protected  Java.Block addClassMethodBlockDeclaration(Location location, Java.CompilationUnit compilationUnit, String className, Class optionalExtendedType, Class[] implementedTypes, boolean staticMethod, Class returnType, String methodName, String[] parameterNames, Class[] parameterTypes, Class[] thrownExceptions)
          To the given Java.CompilationUnit, add A package member class declaration with the given name, superclass and interfaces A public method declaration with the given return type, name, parameter names and values and thrown exceptions A block
protected  Java.PackageMemberClassDeclaration addPackageMemberClassDeclaration(Location location, Java.CompilationUnit compilationUnit, String className, Class optionalExtendedType, Class[] implementedTypes)
          To the given Java.CompilationUnit, add A class declaration with the given name, superclass and interfaces A method declaration with the given return type, name, parameter names and values and thrown exceptions
protected  Java.Type[] classesToTypes(Location location, Class[] classes)
          Convert an array of Classes into an array ofJava.Types.
protected  Java.Type classToType(Location location, Class optionalClass)
          Wrap a reflection Class in a Java.Type object.
protected  ClassLoader compileAndLoad(Java.CompilationUnit compilationUnit, DebuggingInformation debuggingInformation)
          Compile the given compilation unit.
protected  Class compileAndLoad(Java.CompilationUnit compilationUnit, DebuggingInformation debuggingInformation, String newClassName)
          Compile the given compilation unit, load all generated classes, and return the class with the given name.
protected  Java.FormalParameter[] makeFormalParameters(Location location, String[] parameterNames, Class[] parameterTypes)
          Convert name and Class-base parameters into an array of Java.FormalParameters.
protected  void parseImportDeclarations(Java.CompilationUnit compilationUnit, Scanner scanner)
          Parse as many import declarations as possible for the given Java.CompilationUnit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EvaluatorBase

protected EvaluatorBase(ClassLoader optionalParentClassLoader)
Construct with the given ClassLoader.

Notice that from version 2.1.0 to 2.2.0, the parameter was renamed from optionalClassLoader to optionalparentClassLoader together with an incompatible semantic change:

2.1.0
If the optionalClassLoader was a ByteArrayClassLoader, the generated classes were loaded into it, otherwise a new ByteArrayClassLoader was created with the optionalClassLoader as the parent ClassLoader.
2.2.0
A new ByteArrayClassLoader is always created with the optionalClassLoader as the parent ClassLoader.
The old behavior was regarded as ugly because it depends on an argument's type.

Parameters:
optionalParentClassLoader - null == use current thread's context class loader
Method Detail

parseImportDeclarations

protected void parseImportDeclarations(Java.CompilationUnit compilationUnit,
                                       Scanner scanner)
                                throws Scanner.ScanException,
                                       Parser.ParseException,
                                       IOException
Parse as many import declarations as possible for the given Java.CompilationUnit.

Parameters:
compilationUnit -
scanner - Source of tokens
Throws:
Scanner.ScanException
Parser.ParseException
IOException

addPackageMemberClassDeclaration

protected Java.PackageMemberClassDeclaration addPackageMemberClassDeclaration(Location location,
                                                                              Java.CompilationUnit compilationUnit,
                                                                              String className,
                                                                              Class optionalExtendedType,
                                                                              Class[] implementedTypes)
                                                                       throws Parser.ParseException
To the given Java.CompilationUnit, add

Parameters:
location -
compilationUnit -
className -
optionalExtendedType - (null == Object)
implementedTypes -
Returns:
The created Java.ClassDeclaration object
Throws:
Parser.ParseException

addClassMethodBlockDeclaration

protected Java.Block addClassMethodBlockDeclaration(Location location,
                                                    Java.CompilationUnit compilationUnit,
                                                    String className,
                                                    Class optionalExtendedType,
                                                    Class[] implementedTypes,
                                                    boolean staticMethod,
                                                    Class returnType,
                                                    String methodName,
                                                    String[] parameterNames,
                                                    Class[] parameterTypes,
                                                    Class[] thrownExceptions)
                                             throws Parser.ParseException
To the given Java.CompilationUnit, add

Parameters:
location -
compilationUnit -
className -
optionalExtendedType - (null == Object)
implementedTypes -
staticMethod - Whether the method should be declared "static"
returnType - Return type of the declared method
methodName -
parameterNames -
parameterTypes -
thrownExceptions -
Returns:
The created Java.Block object
Throws:
Parser.ParseException

classToType

protected Java.Type classToType(Location location,
                                Class optionalClass)
Wrap a reflection Class in a Java.Type object.


classesToTypes

protected Java.Type[] classesToTypes(Location location,
                                     Class[] classes)
Convert an array of Classes into an array ofJava.Types.


makeFormalParameters

protected Java.FormalParameter[] makeFormalParameters(Location location,
                                                      String[] parameterNames,
                                                      Class[] parameterTypes)
Convert name and Class-base parameters into an array of Java.FormalParameters.


compileAndLoad

protected ClassLoader compileAndLoad(Java.CompilationUnit compilationUnit,
                                     DebuggingInformation debuggingInformation)
                              throws CompileException
Compile the given compilation unit. (A "compilation unit" is typically the contents of a JavaTM source file.)

Parameters:
compilationUnit - The parsed compilation unit
debuggingInformation - What kind of debugging information to generate in the class file
Returns:
The ClassLoader into which the compiled classes were defined
Throws:
CompileException

compileAndLoad

protected Class compileAndLoad(Java.CompilationUnit compilationUnit,
                               DebuggingInformation debuggingInformation,
                               String newClassName)
                        throws CompileException,
                               ClassNotFoundException
Compile the given compilation unit, load all generated classes, and return the class with the given name.

Parameters:
compilationUnit -
debuggingInformation - TODO
newClassName - The fully qualified class name
Returns:
The loaded class
Throws:
CompileException
ClassNotFoundException - A class with the given name was not declared in the compilation unit

Web Site