janino.net

org.codehaus.janino
Class ScriptEvaluator

  extended by org.codehaus.commons.compiler.Cookable
      extended by org.codehaus.janino.SimpleCompiler
          extended by org.codehaus.janino.ClassBodyEvaluator
              extended by org.codehaus.janino.ScriptEvaluator
All Implemented Interfaces:
IClassBodyEvaluator, ICookable, IScriptEvaluator, ISimpleCompiler
Direct Known Subclasses:
ExpressionEvaluator

public class ScriptEvaluator
extends ClassBodyEvaluator
implements IScriptEvaluator

A number of "convenience constructors" exist that execute the setup steps instantly. Their use is discouraged.


Field Summary
protected  boolean[] optionalOverrideMethod
          Whether methods override a method declared by a supertype; null means "none".
protected  [] optionalReturnTypes
          The methods' return types; null means "none".
protected  boolean[] optionalStaticMethod
          Whether methods are static; null means "all".
 
Fields inherited from interface org.codehaus.commons.compiler.IClassBodyEvaluator
DEFAULT_CLASS_NAME
 
Fields inherited from interface org.codehaus.commons.compiler.ICookable
BOOT_CLASS_LOADER, SYSTEM_PROPERTY_SOURCE_DEBUGGING_DIR, SYSTEM_PROPERTY_SOURCE_DEBUGGING_ENABLE
 
Constructor Summary
ScriptEvaluator()
          Constructs a script evaluator with all the default settings (return type void
ScriptEvaluator(Scanner scanner,  optionalExtendedType, [] implementedTypes,  returnType, [] parameterNames, [] parameterTypes, [] thrownExceptions,  optionalParentClassLoader)
          Equivalent to ScriptEvaluator se = new ScriptEvaluator(); se.setExtendedType(optionalExtendedType); se.setImplementedTypes(implementedTypes); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(scanner);
ScriptEvaluator(Scanner scanner,  returnType, [] parameterNames, [] parameterTypes, [] thrownExceptions,  optionalParentClassLoader)
          Equivalent to ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(scanner);
ScriptEvaluator(Scanner scanner,  className,  optionalExtendedType, [] implementedTypes, boolean staticMethod,  returnType,  methodName, [] parameterNames, [] parameterTypes, [] thrownExceptions,  optionalParentClassLoader)
          Equivalent to ScriptEvaluator se = new ScriptEvaluator(); se.setClassName(className); se.setExtendedType(optionalExtendedType); se.setImplementedTypes(implementedTypes); se.setStaticMethod(staticMethod); se.setReturnType(returnType); se.setMethodName(methodName); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(scanner);
ScriptEvaluator( script)
          Equivalent to ScriptEvaluator se = new ScriptEvaluator(); se.cook(script);
ScriptEvaluator( script,  returnType)
          Equivalent to ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.cook(script);
ScriptEvaluator( script,  returnType, [] parameterNames, [] parameterTypes)
          Equivalent to ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.cook(script);
ScriptEvaluator( script,  returnType, [] parameterNames, [] parameterTypes, [] thrownExceptions)
          Equivalent to ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.cook(script);
ScriptEvaluator( optionalFileName,  is,  returnType, [] parameterNames, [] parameterTypes, [] thrownExceptions,  optionalParentClassLoader)
          Equivalent to ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(optionalFileName, is);
ScriptEvaluator( optionalFileName,  reader,  returnType, [] parameterNames, [] parameterTypes, [] thrownExceptions,  optionalParentClassLoader)
          Equivalent to ScriptEvaluator se = new ScriptEvaluator(); se.setReturnType(returnType); se.setParameters(parameterNames, parameterTypes); se.setThrownExceptions(thrownExceptions); se.setParentClassLoader(optionalParentClassLoader); se.cook(reader);
 
Method Summary
 void cook(Parser[] parsers)
           
 void cook([] readers)
          Same as ICookable.cook(Reader), but for multiple scripts.
 void cook(Scanner scanner)
          Scans, parses and ompiles a given compilation unit from the given scanner.
 void cook(Scanner[] scanners)
          Like cook(Scanner), but cooks a set of scripts into one class.
 void cook([] strings)
          Same as ICookable.cook(String), but for multiple scripts.
 void cook([] optionalFileNames, [] readers)
          On a 2 GHz Intel Pentium Core Duo under Windows XP with an IBM 1.4.2 JDK, compiling 10000 expressions "a + b" (integer) takes about 4 seconds and 56 MB of main memory.
 void cook([] optionalFileNames, [] strings)
          Same as ICookable.cook(String, String), but for multiple scripts.
  createFastEvaluator( reader,  interfaceToImplement, [] parameterNames)
          If the parameter and return types of the expression are known at compile time, then a "fast" script evaluator can be instantiated through this method.
  createFastEvaluator(Scanner scanner,  interfaceToImplement, [] parameterNames)
          Notice: This method is not declared in IScriptEvaluator, and is hence only available in this implementation of org.codehaus.commons.compiler.
  createFastEvaluator( script,  interfaceToImplement, [] parameterNames)
           
static  createFastScriptEvaluator(Scanner scanner,  interfaceToImplement, [] parameterNames,  optionalParentClassLoader)
          Deprecated. Use createFastScriptEvaluator(Scanner, String[], String, Class, Class, String[], ClassLoader) instead
static  createFastScriptEvaluator(Scanner scanner, [] optionalDefaultImports,  className,  optionalExtendedClass,  interfaceToImplement, [] parameterNames,  optionalParentClassLoader)
          Deprecated. Use createFastEvaluator(Scanner,Class,String[]) instead:
static  createFastScriptEvaluator(Scanner scanner,  className,  optionalExtendedType,  interfaceToImplement, [] parameterNames,  optionalParentClassLoader)
          Deprecated. Use createFastScriptEvaluator(Scanner, String[], String, Class, Class, String[], ClassLoader) instead
static  createFastScriptEvaluator( script,  interfaceToImplement, [] parameterNames)
          Deprecated. Use createFastScriptEvaluator(Scanner, String[], String, Class, Class, String[], ClassLoader) instead
  createInstance( reader)
          Don't use.
  evaluate(int idx, [] arguments)
          Same as IScriptEvaluator.evaluate(Object[]), but for multiple scripts.
  evaluate([] arguments)
          Calls the script with concrete parameter values.
protected   getDefaultReturnType()
           
  getMethod()
          Returns the loaded .
  getMethod(int idx)
          Same as IScriptEvaluator.getMethod(), but for multiple scripts.
static [] guessParameterNames(Scanner scanner)
          Guess the names of the parameters used in the given expression.
protected  Java.MethodDeclarator makeMethodDeclaration(Location location, Java.Annotation[] annotations, boolean staticMethod,  returnType,  methodName, [] parameterTypes, [] parameterNames, [] thrownExceptions, <Java.BlockStatement> statements)
          To the given Java.ClassDeclaration, add A public method declaration with the given return type, name, parameter names and values and thrown exceptions A block
protected  <Java.BlockStatement> makeStatements(int idx, Parser parser)
          Fills the given block by parsing statements until EOF and adding them to the block.
 void setMethodName( methodName)
          Define the name of the generated method.
 void setMethodNames([] methodNames)
          Same as IScriptEvaluator.setMethodName(String), but for multiple scripts.
 void setOverrideMethod(boolean overrideMethod)
          Defines whether the generated method overrides a methods declared in a supertype.
 void setOverrideMethod(boolean[] overrideMethod)
          Same as IScriptEvaluator.setOverrideMethod(boolean), but for multiple scripts.
 void setParameters([][] parameterNames, [][] parameterTypes)
          Same as IScriptEvaluator.setParameters(String[], Class[]), but for multiple scripts.
 void setParameters([] parameterNames, [] parameterTypes)
          Define the names and types of the parameters of the generated method.
 void setReturnType( returnType)
          Defines the return types of the generated methods.
 void setReturnTypes([] returnTypes)
          Defines the return types of the generated methods.
 void setStaticMethod(boolean staticMethod)
          Defines whether the generated method should be STATIC or not.
 void setStaticMethod(boolean[] staticMethod)
          Same as IScriptEvaluator.setStaticMethod(boolean), but for multiple scripts.
 void setThrownExceptions([] thrownExceptions)
          Define the exceptions that the generated method may throw.
 void setThrownExceptions([][] thrownExceptions)
          Same as IScriptEvaluator.setThrownExceptions(Class[]), but for multiple scripts.
 
Methods inherited from class org.codehaus.janino.ClassBodyEvaluator
addPackageMemberClassDeclaration, compileToClass, createFastClassBodyEvaluator, createFastClassBodyEvaluator, getClazz, makeCompilationUnit, setClassName, setDefaultImports, setExtendedClass, setExtendedType, setImplementedInterfaces, setImplementedTypes
 
Methods inherited from class org.codehaus.janino.SimpleCompiler
assertNotCooked, classesToTypes, classToType, compileToClassLoader, cook, cook, equals, getClassLoader, hashCode, main, setCompileErrorHandler, setDebuggingInformation, setParentClassLoader, setWarningHandler
 
Methods inherited from class org.codehaus.commons.compiler.Cookable
cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, readString
 
Methods inherited from class java.lang.
, , , , , , , ,
 
Methods inherited from interface org.codehaus.commons.compiler.IClassBodyEvaluator
getClazz, setClassName, setDefaultImports, setExtendedClass, setExtendedType, setImplementedInterfaces, setImplementedTypes
 
Methods inherited from interface org.codehaus.commons.compiler.ICookable
cook, cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, setCompileErrorHandler, setDebuggingInformation, setParentClassLoader, setWarningHandler
 

Field Detail

optionalOverrideMethod

protected boolean[] optionalOverrideMethod
Whether methods override a method declared by a supertype; null means "none".


optionalStaticMethod

protected boolean[] optionalStaticMethod
Whether methods are static; null means "all".


optionalReturnTypes

protected [] optionalReturnTypes
The methods' return types; null means "none".

Constructor Detail

ScriptEvaluator

public ScriptEvaluator( script)
                throws CompileException
Equivalent to
 ScriptEvaluator se = new ScriptEvaluator();
 se.cook(script);

Throws:
CompileException
See Also:
ScriptEvaluator(), Cookable.cook(String)

ScriptEvaluator

public ScriptEvaluator( script,
                        returnType)
                throws CompileException
Equivalent to
 ScriptEvaluator se = new ScriptEvaluator();
 se.setReturnType(returnType);
 se.cook(script);

Throws:
CompileException
See Also:
ScriptEvaluator(), setReturnType(Class), Cookable.cook(String)

ScriptEvaluator

public ScriptEvaluator( script,
                        returnType,
                       [] parameterNames,
                       [] parameterTypes)
                throws CompileException
Equivalent to
 ScriptEvaluator se = new ScriptEvaluator();
 se.setReturnType(returnType);
 se.setParameters(parameterNames, parameterTypes);
 se.cook(script);

Throws:
CompileException
See Also:
ScriptEvaluator(), setReturnType(Class), setParameters(String[], Class[]), Cookable.cook(String)

ScriptEvaluator

public ScriptEvaluator( script,
                        returnType,
                       [] parameterNames,
                       [] parameterTypes,
                       [] thrownExceptions)
                throws CompileException
Equivalent to
 ScriptEvaluator se = new ScriptEvaluator();
 se.setReturnType(returnType);
 se.setParameters(parameterNames, parameterTypes);
 se.setThrownExceptions(thrownExceptions);
 se.cook(script);

Throws:
CompileException
See Also:
ScriptEvaluator(), setReturnType(Class), setParameters(String[], Class[]), setThrownExceptions(Class[]), Cookable.cook(String)

ScriptEvaluator

public ScriptEvaluator( optionalFileName,
                        is,
                        returnType,
                       [] parameterNames,
                       [] parameterTypes,
                       [] thrownExceptions,
                        optionalParentClassLoader)
                throws CompileException,
                       
Equivalent to
 ScriptEvaluator se = new ScriptEvaluator();
 se.setReturnType(returnType);
 se.setParameters(parameterNames, parameterTypes);
 se.setThrownExceptions(thrownExceptions);
 se.setParentClassLoader(optionalParentClassLoader);
 se.cook(optionalFileName, is);

Throws:
CompileException
See Also:
ScriptEvaluator(), setReturnType(Class), setParameters(String[], Class[]), setThrownExceptions(Class[]), SimpleCompiler.setParentClassLoader(ClassLoader), Cookable.cook(String, InputStream)

ScriptEvaluator

public ScriptEvaluator( optionalFileName,
                        reader,
                        returnType,
                       [] parameterNames,
                       [] parameterTypes,
                       [] thrownExceptions,
                        optionalParentClassLoader)
                throws CompileException,
                       
Equivalent to
 ScriptEvaluator se = new ScriptEvaluator();
 se.setReturnType(returnType);
 se.setParameters(parameterNames, parameterTypes);
 se.setThrownExceptions(thrownExceptions);
 se.setParentClassLoader(optionalParentClassLoader);
 se.cook(reader);

Throws:
CompileException
See Also:
ScriptEvaluator(), setReturnType(Class), setParameters(String[], Class[]), setThrownExceptions(Class[]), SimpleCompiler.setParentClassLoader(ClassLoader), Cookable.cook(String, Reader)

ScriptEvaluator

public ScriptEvaluator(Scanner scanner,
                        returnType,
                       [] parameterNames,
                       [] parameterTypes,
                       [] thrownExceptions,
                        optionalParentClassLoader)
                throws CompileException,
                       
Equivalent to
 ScriptEvaluator se = new ScriptEvaluator();
 se.setReturnType(returnType);
 se.setParameters(parameterNames, parameterTypes);
 se.setThrownExceptions(thrownExceptions);
 se.setParentClassLoader(optionalParentClassLoader);
 se.cook(scanner);

Throws:
CompileException
See Also:
ScriptEvaluator(), setReturnType(Class), setParameters(String[], Class[]), setThrownExceptions(Class[]), SimpleCompiler.setParentClassLoader(ClassLoader), Cookable.cook(Reader)

ScriptEvaluator

public ScriptEvaluator(Scanner scanner,
                        optionalExtendedType,
                       [] implementedTypes,
                        returnType,
                       [] parameterNames,
                       [] parameterTypes,
                       [] thrownExceptions,
                        optionalParentClassLoader)
                throws CompileException,
                       
Equivalent to
 ScriptEvaluator se = new ScriptEvaluator();
 se.setExtendedType(optionalExtendedType);
 se.setImplementedTypes(implementedTypes);
 se.setReturnType(returnType);
 se.setParameters(parameterNames, parameterTypes);
 se.setThrownExceptions(thrownExceptions);
 se.setParentClassLoader(optionalParentClassLoader);
 se.cook(scanner);

Throws:
CompileException
See Also:
ScriptEvaluator(), ClassBodyEvaluator.setExtendedClass(Class), ClassBodyEvaluator.setImplementedInterfaces(Class[]), setReturnType(Class), setParameters(String[], Class[]), setThrownExceptions(Class[]), SimpleCompiler.setParentClassLoader(ClassLoader), Cookable.cook(Reader)

ScriptEvaluator

public ScriptEvaluator(Scanner scanner,
                        className,
                        optionalExtendedType,
                       [] implementedTypes,
                       boolean staticMethod,
                        returnType,
                        methodName,
                       [] parameterNames,
                       [] parameterTypes,
                       [] thrownExceptions,
                        optionalParentClassLoader)
                throws CompileException,
                       
Equivalent to
 ScriptEvaluator se = new ScriptEvaluator();
 se.setClassName(className);
 se.setExtendedType(optionalExtendedType);
 se.setImplementedTypes(implementedTypes);
 se.setStaticMethod(staticMethod);
 se.setReturnType(returnType);
 se.setMethodName(methodName);
 se.setParameters(parameterNames, parameterTypes);
 se.setThrownExceptions(thrownExceptions);
 se.setParentClassLoader(optionalParentClassLoader);
 se.cook(scanner);

Throws:
CompileException
See Also:
ScriptEvaluator(), ClassBodyEvaluator.setClassName(String), ClassBodyEvaluator.setExtendedClass(Class), ClassBodyEvaluator.setImplementedInterfaces(Class[]), setStaticMethod(boolean), setReturnType(Class), setMethodName(String), setParameters(String[], Class[]), setThrownExceptions(Class[]), SimpleCompiler.setParentClassLoader(ClassLoader), Cookable.cook(Reader)

ScriptEvaluator

public ScriptEvaluator()
Constructs a script evaluator with all the default settings (return type void

Method Detail

setOverrideMethod

public void setOverrideMethod(boolean overrideMethod)
Description copied from interface: IScriptEvaluator
Defines whether the generated method overrides a methods declared in a supertype.

Specified by:
setOverrideMethod in interface IScriptEvaluator

setStaticMethod

public void setStaticMethod(boolean staticMethod)
Description copied from interface: IScriptEvaluator
Defines whether the generated method should be STATIC or not. Defaults to true.

Specified by:
setStaticMethod in interface IScriptEvaluator

setReturnType

public void setReturnType( returnType)
Defines the return types of the generated methods.

Specified by:
setReturnType in interface IScriptEvaluator
Parameters:
returnType - The method's return type; null means the "default return type", which is the type returned by getDefaultReturnType() (void.class for ScriptEvaluator and Object.class for ExpressionEvaluator)
See Also:
getDefaultReturnType(), ExpressionEvaluator.getDefaultReturnType()

setMethodName

public void setMethodName( methodName)
Description copied from interface: IScriptEvaluator
Define the name of the generated method. Defaults to an unspecified name.

Specified by:
setMethodName in interface IScriptEvaluator

setParameters

public void setParameters([] parameterNames,
                          [] parameterTypes)
Description copied from interface: IScriptEvaluator
Define the names and types of the parameters of the generated method.

names and types must have the same number of elements.

The parameters can be of primitive type, e.g. double.class.

The default is to have zero parameters.

Specified by:
setParameters in interface IScriptEvaluator

setThrownExceptions

public void setThrownExceptions([] thrownExceptions)
Description copied from interface: IScriptEvaluator
Define the exceptions that the generated method may throw.

Specified by:
setThrownExceptions in interface IScriptEvaluator

cook

public final void cook(Scanner scanner)
                throws CompileException,
                       
Description copied from class: SimpleCompiler
Scans, parses and ompiles a given compilation unit from the given scanner. After completion, SimpleCompiler.getClassLoader() returns a that allows for access to the compiled classes.

Overrides:
cook in class ClassBodyEvaluator
Throws:
CompileException

evaluate

public  evaluate([] arguments)
                throws 
Description copied from interface: IScriptEvaluator
Calls the script with concrete parameter values.

Each argument must have the same type as specified through the parameterTypes parameter of IScriptEvaluator.setParameters(String[], Class[]).

Arguments of primitive type must passed with their wrapper class objects.

The object returned has the class as specified through IScriptEvaluator.setReturnType(Class).

This method is thread-safe.

Specified by:
evaluate in interface IScriptEvaluator
Parameters:
arguments - The actual parameter values
Throws:

getMethod

public  getMethod()
Description copied from interface: IScriptEvaluator
Returns the loaded .

This method must only be called after exactly one of the ICookable.cook(String, Reader) methods was called.

Specified by:
getMethod in interface IScriptEvaluator

setOverrideMethod

public void setOverrideMethod(boolean[] overrideMethod)
Description copied from interface: IScriptEvaluator
Same as IScriptEvaluator.setOverrideMethod(boolean), but for multiple scripts.

Specified by:
setOverrideMethod in interface IScriptEvaluator

setStaticMethod

public void setStaticMethod(boolean[] staticMethod)
Description copied from interface: IScriptEvaluator
Same as IScriptEvaluator.setStaticMethod(boolean), but for multiple scripts.

Specified by:
setStaticMethod in interface IScriptEvaluator

setReturnTypes

public void setReturnTypes([] returnTypes)
Defines the return types of the generated methods.

Specified by:
setReturnTypes in interface IScriptEvaluator
Parameters:
returnTypes - The methods' return types; null elements mean the "default return type", which is the type returned by getDefaultReturnType() (void.class for ScriptEvaluator and Object.class for ExpressionEvaluator)
See Also:
getDefaultReturnType(), ExpressionEvaluator.getDefaultReturnType()

setMethodNames

public void setMethodNames([] methodNames)
Description copied from interface: IScriptEvaluator
Same as IScriptEvaluator.setMethodName(String), but for multiple scripts.

Define the names of the generated methods. By default the methods have distinct and implementation-specific names.

If two scripts have the same name, then they must have different parameter types (see IScriptEvaluator.setParameters(String[][], Class[][])).

Specified by:
setMethodNames in interface IScriptEvaluator

setParameters

public void setParameters([][] parameterNames,
                          [][] parameterTypes)
Description copied from interface: IScriptEvaluator
Same as IScriptEvaluator.setParameters(String[], Class[]), but for multiple scripts.

Specified by:
setParameters in interface IScriptEvaluator

setThrownExceptions

public void setThrownExceptions([][] thrownExceptions)
Description copied from interface: IScriptEvaluator
Same as IScriptEvaluator.setThrownExceptions(Class[]), but for multiple scripts.

Specified by:
setThrownExceptions in interface IScriptEvaluator

cook

public final void cook(Scanner[] scanners)
                throws CompileException,
                       
Like cook(Scanner), but cooks a set of scripts into one class. Notice that if any of the scripts causes trouble, the entire compilation will fail. If you need to report which of the scripts causes the exception, you may want to use the optionalFileName argument of Scanner.Scanner(String, Reader) to distinguish between the individual token sources.

On a 2 GHz Intel Pentium Core Duo under Windows XP with an IBM 1.4.2 JDK, compiling 10000 expressions "a + b" (integer) takes about 4 seconds and 56 MB of main memory. The generated class file is 639203 bytes large.

The number and the complexity of the scripts is restricted by the , where the most limiting factor is the 64K entries limit of the constant pool. Since every method with a distinct name requires one entry there, you can define at best 32K (very simple) scripts. If and only if the number of scanners is one, then that single script may contain leading IMPORT directives.

Throws:
- Any of the preceeding set...() had an array size different from that of scanners
CompileException

cook

public final void cook(Parser[] parsers)
                throws CompileException,
                       
Throws:
CompileException
See Also:
cook(Scanner[])

cook

public final void cook([] readers)
                throws CompileException,
                       
Description copied from interface: IScriptEvaluator
Same as ICookable.cook(Reader), but for multiple scripts.

Specified by:
cook in interface IScriptEvaluator
Throws:
CompileException

cook

public final void cook([] optionalFileNames,
                       [] readers)
                throws CompileException,
                       
On a 2 GHz Intel Pentium Core Duo under Windows XP with an IBM 1.4.2 JDK, compiling 10000 expressions "a + b" (integer) takes about 4 seconds and 56 MB of main memory. The generated class file is 639203 bytes large.

The number and the complexity of the scripts is restricted by the , where the most limiting factor is the 64K entries limit of the constant pool. Since every method with a distinct name requires one entry there, you can define at best 32K (very simple) scripts.

Specified by:
cook in interface IScriptEvaluator
Throws:
CompileException

cook

public final void cook([] strings)
                throws CompileException
Description copied from interface: IScriptEvaluator
Same as ICookable.cook(String), but for multiple scripts.

Specified by:
cook in interface IScriptEvaluator
Throws:
CompileException

cook

public final void cook([] optionalFileNames,
                       [] strings)
                throws CompileException
Description copied from interface: IScriptEvaluator
Same as ICookable.cook(String, String), but for multiple scripts.

Specified by:
cook in interface IScriptEvaluator
Throws:
CompileException

getDefaultReturnType

protected  getDefaultReturnType()
Returns:
void.class
See Also:
setReturnTypes(Class[])

makeStatements

protected <Java.BlockStatement> makeStatements(int idx,
                                                   Parser parser)
                                            throws CompileException,
                                                   
Fills the given block by parsing statements until EOF and adding them to the block.

Throws:
CompileException

makeMethodDeclaration

protected Java.MethodDeclarator makeMethodDeclaration(Location location,
                                                      Java.Annotation[] annotations,
                                                      boolean staticMethod,
                                                       returnType,
                                                       methodName,
                                                      [] parameterTypes,
                                                      [] parameterNames,
                                                      [] thrownExceptions,
                                                      <Java.BlockStatement> statements)
To the given Java.ClassDeclaration, add

Parameters:
returnType - Return type of the declared method

createFastScriptEvaluator


public static  createFastScriptEvaluator( script,
                                                           interfaceToImplement,
                                                          [] parameterNames)
                                        throws CompileException
Deprecated. Use createFastScriptEvaluator(Scanner, String[], String, Class, Class, String[], ClassLoader) instead

Throws:
CompileException

createFastScriptEvaluator


public static  createFastScriptEvaluator(Scanner scanner,
                                                           interfaceToImplement,
                                                          [] parameterNames,
                                                           optionalParentClassLoader)
                                        throws CompileException,
                                               
Deprecated. Use createFastScriptEvaluator(Scanner, String[], String, Class, Class, String[], ClassLoader) instead

Throws:
CompileException

createFastScriptEvaluator


public static  createFastScriptEvaluator(Scanner scanner,
                                                           className,
                                                           optionalExtendedType,
                                                           interfaceToImplement,
                                                          [] parameterNames,
                                                           optionalParentClassLoader)
                                        throws CompileException,
                                               
Deprecated. Use createFastScriptEvaluator(Scanner, String[], String, Class, Class, String[], ClassLoader) instead

Throws:
CompileException

createFastScriptEvaluator


public static  createFastScriptEvaluator(Scanner scanner,
                                                          [] optionalDefaultImports,
                                                           className,
                                                           optionalExtendedClass,
                                                           interfaceToImplement,
                                                          [] parameterNames,
                                                           optionalParentClassLoader)
                                        throws CompileException,
                                               
Deprecated. Use createFastEvaluator(Scanner,Class,String[]) instead:

 ScriptEvaluator se = new ScriptEvaluator();
 se.setDefaultImports.(optionalDefaultImports);
 se.setClassName.(className);
 se.setExtendedClass.(optionalExtendedClass);
 se.setParentClassLoader(optionalParentClassLoader);
 return se.createFastEvaluator(scanner,
 interfaceToImplement, parameterNames);
 

Throws:
CompileException

createInstance

public final  createInstance( reader)
Don't use.

Specified by:
createInstance in interface IClassBodyEvaluator
Overrides:
createInstance in class ClassBodyEvaluator
Parameters:
reader - Source of class body tokens
Returns:
An object that extends the optionalExtendedType and implements the given implementedTypes

createFastEvaluator

public  createFastEvaluator( reader,
                                   interfaceToImplement,
                                  [] parameterNames)
                           throws CompileException,
                                  
Description copied from interface: IScriptEvaluator
If the parameter and return types of the expression are known at compile time, then a "fast" script evaluator can be instantiated through this method.

Script evaluation is faster than through IScriptEvaluator.evaluate(Object[]), because it is not done through reflection but through direct method invocation.

Example:

 public interface Foo {
     int bar(int a, int b);
 }
 ...
 IScriptEvaluator se = CompilerFactoryFactory.getDefaultCompilerFactory().newScriptEvaluator();

 // Optionally configure the SE her:
 se.setClassName("Bar");
 se.setDefaultImports(new String[] { "java.util.*" });
 se.setExtendedClass(SomeOtherClass.class);
 se.setParentClassLoader(someClassLoader);

 Foo f = (Foo) se.createFastScriptEvaluator(
     "return a - b;",
     Foo.class,
     new String[] { "a", "b" }
 );
 System.out.println("1 - 2 = " + f.bar(1, 2));
 
All other configuration (implemented type, static method, return type, method name, parameter names and types, thrown exceptions) are predetermined by the interfaceToImplement. Notice: The interfaceToImplement must either be declared public, or with package scope in the same package as the generated class (see IClassBodyEvaluator.setClassName(String)).

Specified by:
createFastEvaluator in interface IScriptEvaluator
Parameters:
reader - Produces the stream of script tokens
interfaceToImplement - Must declare exactly one method
parameterNames - The names of the parameters of that method
Returns:
An object that implements the given interface
Throws:
CompileException

createFastEvaluator

public  createFastEvaluator( script,
                                   interfaceToImplement,
                                  [] parameterNames)
                           throws CompileException
Specified by:
createFastEvaluator in interface IScriptEvaluator
Parameters:
script - Contains the sequence of script tokens
Throws:
CompileException
See Also:
IScriptEvaluator.createFastEvaluator(Reader, Class, String[])

createFastEvaluator

public  createFastEvaluator(Scanner scanner,
                                   interfaceToImplement,
                                  [] parameterNames)
                           throws CompileException,
                                  
Notice: This method is not declared in IScriptEvaluator, and is hence only available in this implementation of org.codehaus.commons.compiler. To be independent from this particular implementation, try to switch to createFastEvaluator(Reader, Class, String[]).

Parameters:
scanner - Source of tokens to read
Throws:
CompileException
See Also:
createFastEvaluator(Reader, Class, String[])

guessParameterNames

public static [] guessParameterNames(Scanner scanner)
                                    throws CompileException,
                                           
Guess the names of the parameters used in the given expression. The strategy is to look at all "ambiguous names" in the expression (e.g. in "a.b.c.d()", the ambiguous name is "a.b.c"), and then at the components of the ambiguous name.

Throws:
CompileException
See Also:
Scanner.Scanner(String, Reader)

evaluate

public  evaluate(int idx,
                       [] arguments)
                throws 
Description copied from interface: IScriptEvaluator
Same as IScriptEvaluator.evaluate(Object[]), but for multiple scripts.

Specified by:
evaluate in interface IScriptEvaluator
Throws:

getMethod

public  getMethod(int idx)
Description copied from interface: IScriptEvaluator
Same as IScriptEvaluator.getMethod(), but for multiple scripts.

Specified by:
getMethod in interface IScriptEvaluator

janino.net