net.janino
Class ClassBodyEvaluator

java.lang.Object
  |
  +--net.janino.EvaluatorBase
        |
        +--net.janino.ClassBodyEvaluator

public class ClassBodyEvaluator
extends EvaluatorBase

Parses a class body and returns it as a java.lang.Class object ready for use with java.lang.reflect.

Example:

   import java.util.*;

   static private int a = 1;
   private int b = 2;

   public void func(int c, int d) {
       return func2(c, d);
   }

   private static void func2(int e, int f) {
       return e * f;
   }
 


Constructor Summary
ClassBodyEvaluator(Scanner scanner, java.lang.Class extendedType, java.lang.Class[] implementedTypes, java.lang.ClassLoader classLoader)
          See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).
ClassBodyEvaluator(Scanner scanner, java.lang.ClassLoader classLoader)
          See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).
ClassBodyEvaluator(Scanner scanner, java.lang.String className, java.lang.Class extendedType, java.lang.Class[] implementedTypes, java.lang.ClassLoader classLoader)
          Parse and compile a class body, i.e. a series of member definitions.
ClassBodyEvaluator(java.lang.String script)
          See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).
ClassBodyEvaluator(java.lang.String fileName, java.io.InputStream is)
          See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).
ClassBodyEvaluator(java.lang.String fileName, java.io.Reader reader)
          See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).
 
Method Summary
 java.lang.Class evaluate()
          Returns the java.lang.Class object compiled from the class body.
 
Methods inherited from class net.janino.EvaluatorBase
addClassDeclaration, addClassMethodBlockDeclaration, classesToTypes, classToType, compileAndLoad, compileAndLoad, makeFormalParameters, parseImportDeclarations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassBodyEvaluator

public ClassBodyEvaluator(java.lang.String script)
                   throws Java.CompileException,
                          Parser.ParseException,
                          Scanner.ScanException,
                          java.io.IOException
See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).

ClassBodyEvaluator

public ClassBodyEvaluator(java.lang.String fileName,
                          java.io.InputStream is)
                   throws Java.CompileException,
                          Parser.ParseException,
                          Scanner.ScanException,
                          java.io.IOException
See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).

ClassBodyEvaluator

public ClassBodyEvaluator(java.lang.String fileName,
                          java.io.Reader reader)
                   throws Java.CompileException,
                          Parser.ParseException,
                          Scanner.ScanException,
                          java.io.IOException
See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).

ClassBodyEvaluator

public ClassBodyEvaluator(Scanner scanner,
                          java.lang.ClassLoader classLoader)
                   throws Java.CompileException,
                          Parser.ParseException,
                          Scanner.ScanException,
                          java.io.IOException
See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).

ClassBodyEvaluator

public ClassBodyEvaluator(Scanner scanner,
                          java.lang.Class extendedType,
                          java.lang.Class[] implementedTypes,
                          java.lang.ClassLoader classLoader)
                   throws Java.CompileException,
                          Parser.ParseException,
                          Scanner.ScanException,
                          java.io.IOException
See ClassBodyEvaluator(Scanner, String, Class, Class[], ClassLoader classLoader).

ClassBodyEvaluator

public ClassBodyEvaluator(Scanner scanner,
                          java.lang.String className,
                          java.lang.Class extendedType,
                          java.lang.Class[] implementedTypes,
                          java.lang.ClassLoader classLoader)
                   throws Java.CompileException,
                          Parser.ParseException,
                          Scanner.ScanException,
                          java.io.IOException
Parse and compile a class body, i.e. a series of member definitions.

The "classLoader" serves two purposes:

A number of constructors exist that provide useful default values for the various parameters, or parse the class body from a String, an InputStream or a Reader instead of a Scanner.
Parameters:
scanner - source of tokens
className - the name of the temporary class (uncritical)
extendedType - class to extend or null
implementedTypes - interfaces to implement
classLoader - loads referenced classes and defines the generated class
Method Detail

evaluate

public java.lang.Class evaluate()
Returns the java.lang.Class object compiled from the class body.