org.codehaus.janino |
|
Java Source File Name | Type | Comment |
Access.java | Class | Return value for
IClass.IMember.getAccess . |
AstCompilationUnitGenerator.java | Interface | |
ByteArrayClassLoader.java | Class | This
ClassLoader allows for the loading of a set of JavaTM classes
provided in class file format. |
CachingJavaSourceClassLoader.java | Class | A
org.codehaus.janino.JavaSourceClassLoader that uses a
resource storage provided by the application to cache compiled
classes and thus saving unnecessary recompilations. |
ClassBodyEvaluator.java | Class | 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;
}
The optionalClassLoader serves two purposes:
- It is used to look for classes referenced by the class body.
- It is used to load the generated JavaTM class
into the JVM; directly if it is a subclass of
ByteArrayClassLoader , or by creation of a temporary
ByteArrayClassLoader if not.
To set up a
ClassBodyEvaluator object, proceed as follows:
-
Create the
ClassBodyEvaluator using
ClassBodyEvaluator.ClassBodyEvaluator()
-
Configure the
ClassBodyEvaluator by calling any of the following methods:
-
Call any of the
org.codehaus.janino.Cookable.cook(Scanner) methods to scan,
parse, compile and load the class body into the JVM.
Alternatively, a number of "convenience constructors" exist that execute the steps described
above instantly.
To compile a class body and immediately instantiate an object, one of the
ClassBodyEvaluator.createFastClassBodyEvaluator(Scanner,Class,ClassLoader) methods can be used.
The generated class may optionally extend/implement a given type; the returned instance can
safely be type-casted to that optionalBaseType .
Example:
public interface Foo {
int bar(int a, int b);
}
...
Foo f = (Foo) ClassBodyEvaluator.createFastClassBodyEvaluator(
new Scanner(null, new StringReader("public int bar(int a, int b) { return a + b; }")),
Foo.class, // Base type to extend/implement
(ClassLoader) null // Use current thread's context class loader
);
System.out.println("1 + 2 = " + f.bar(1, 2));
Notice: The optionalBaseType must be accessible from the generated class,
i.e. |
ClassFileIClass.java | Class | A wrapper object that turns a
ClassFile object into a
IClass . |
ClassLoaderIClassLoader.java | Class | An
IClassLoader that loads
IClass es through a reflection
ClassLoader . |
CodeContext.java | Class | The context of the compilation of a function (constructor or method). |
CompileException.java | Class | An exception that reflects an error during compilation. |
Compiler.java | Class | A simplified substitute for the javac tool. |
Cookable.java | Class | "Cooking" means scanning a sequence of JavaTM tokens with a
org.codehaus.janino.Scanner . |
DebuggingInformation.java | Class | |
Descriptor.java | Class | |
ExpressionEvaluator.java | Class | An expression evaluator that evaluates expressions in JavaTM bytecode.
The syntax of the expression to compile is that of a JavaTM expression, as defined
in the Java Language Specification,
2nd edition, section
15.
Notice that a JavaTM expression does not have a concluding semicolon.
Example:
a + 7 * b
(Notice that this expression refers to two parameters "a" and "b", as explained below.)
The expression may optionally be preceeded with a sequence of import directives like
import java.text.*;
new DecimalFormat("####,###.##").format(10200020.345345)
(Notice that the import directive is concluded with a semicolon, while the expression is not.)
The expression evaluator is implemented by creating and compiling a temporary compilation unit
defining one class with one static method with one return statement.
To set up an
ExpressionEvaluator object, proceed as follows:
-
Create the
ExpressionEvaluator using
ExpressionEvaluator.ExpressionEvaluator()
-
Configure the
ExpressionEvaluator by calling any of the following methods:
-
Call any of the
org.codehaus.janino.Cookable.cook(Scanner) methods to scan,
parse, compile and load the expression into the JVM.
Alternatively, a number of "convenience constructors" exist that execute the steps described
above instantly.
After the
ExpressionEvaluator object is set up, the expression can be evaluated as
often with different parameter values (see
ExpressionEvaluator.evaluate(Object[]) ). |
FilterWarningHandler.java | Class | |
IClass.java | Class | A simplified equivalent to "java.lang.reflect". |
IClassLoader.java | Class | Loads an
IClass by type name. |
Java.java | Class | This wrapper class defines classes that represent the elements of the
JavaTM programming language. |
JavaSourceClassLoader.java | Class | A
ClassLoader that, unlike usual
ClassLoader s,
does not load byte code, but reads JavaTM source code and then scans, parses,
compiles and loads it into the virtual machine. |
JavaSourceIClassLoader.java | Class | This
org.codehaus.janino.IClassLoader finds, scans and parses compilation units. |
Location.java | Class | Represents the location of a character in a file, as defined by
file name, line number and column number. |
MethodDescriptor.java | Class | Representation of a "method descriptor" (JVMS 4.3.3). |
Mod.java | Class | This class defines constants and convenience methods for the handling of
modifiers as defined by the JVM. |
Opcode.java | Interface | Definitions of Java bytecode opcodes. |
Parser.java | Class | A parser for the JavaTM programming language. |
ReflectionIClass.java | Class | Wraps a
java.lang.Class in an
org.codehaus.janino.IClass . |
ResourceFinderIClassLoader.java | Class | This
org.codehaus.janino.IClassLoader loads IClasses through a
a
org.codehaus.janino.util.resource.ResourceFinder that designates
org.codehaus.janino.util.ClassFile s. |
Scanner.java | Class | Splits up a character stream into tokens and returns them as
java.lang.String String objects. |
ScriptEvaluator.java | Class | A script evaluator that executes a script in JavaTM bytecode.
The syntax of the script to compile is a sequence of import declarations followed by a
sequence of statements, as defined in the
Java Language Specification, 2nd
edition, sections
7.5
and
14.
Example:
import java.text.*;
System.out.println("HELLO");
System.out.println(new DecimalFormat("####,###.##").format(a));
(Notice that this expression refers to a parameter "a", as explained below.)
The script may complete abnormally, e.g. |
SimpleCompiler.java | Class | A simplified version of
Compiler that can compile only a single
compilation unit. |
UnicodeUnescapeException.java | Class | Represents a problem that occurred while unescaping a unicode escape
sequence through a
org.codehaus.janino.UnicodeUnescapeReader . |
UnicodeUnescapeReader.java | Class | A
FilterReader that unescapes the "Unicode Escapes"
as described in
the
Java Language Specification, 2nd edition.
Notice that it is possible to formulate invalid escape sequences, e.g.
"\u123g" ("g" is not a valid hex character). |
UnitCompiler.java | Class | This class actually implements the JavaTM compiler. |
UnparseVisitor.java | Class | A visitor that unparses (un-compiles) an AST to a
Writer . |
Visitor.java | Class | Basis for the "visitor" pattern as described in "Gamma, Helm, Johnson,
Vlissides: Design Patterns". |
WarningHandler.java | Interface | Interface type for
UnitCompiler.setWarningHandler(WarningHandler) . |