Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.interpreter
Class Interpreter<T>

java.lang.Object
  extended by dk.rode.thesis.interpreter.Interpreter<T>
Type Parameters:
T - The type of value the evaluated expressions evaluate to.

public class Interpreter<T>
extends Object

An interpreter can interpret expressions.

Only expressions evaluating to values of a given type can be used. The type is supplied at construction time.

An interpreter supports break expressions storing typed expressions with a matching (sub-) type.

Author:
Gunni Rode / rode.dk
See Also:
Context

Field Summary
private  Class<T> type
          The super-type of expression values handled by this interpreter.
 
Constructor Summary
Interpreter(Class<T> type)
          Constructor.
Interpreter(TypeLiteral<T> type)
          Constructor.
 
Method Summary
<E extends T>
T
interpret(Context context, Expression<E> expression)
          Interpret the expression syntax tree having the root supplied as expression, and returns the result.
<E extends T>
E
interpret(Context context, Expression<E> expression, Class<? super E> type)
          Interpret the expression syntax tree having the root supplied as expression, and returns the result.
 String toString()
          Returns the string representation of this interpreter.
 Class<T> type()
          Return the super-type of expression values handled by this interpreter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

private final Class<T> type
The super-type of expression values handled by this interpreter.

Never null.

Constructor Detail

Interpreter

public Interpreter(Class<T> type)
Constructor.

Parameters:
type - The super-type of expression values handled by this interpreter.
Throws:
NullPointerException - If type is null.

Interpreter

public Interpreter(TypeLiteral<T> type)
Constructor.

Parameters:
type - The super-type of expression values handled by this interpreter.
Throws:
NullPointerException - If type is null.
Method Detail

interpret

public <E extends T> T interpret(Context context,
                                 Expression<E> expression)
            throws ExpressionException
Interpret the expression syntax tree having the root supplied as expression, and returns the result.

The is no guarantee that the evaluation will ever complete!

Type Parameters:
E - The type of value the evaluation of expression produces.
Parameters:
context - The variable context to use; cannot be null.
expression - The root expression; cannot be null.
Returns:
The result of the evaluation, or null if the evaluation was exited prematurely.
Throws:
NullPointerException - If either argument is null.
ExpressionException - If the evaluation fails.

interpret

public <E extends T> E interpret(Context context,
                                 Expression<E> expression,
                                 Class<? super E> type)
                      throws ExpressionException
Interpret the expression syntax tree having the root supplied as expression, and returns the result.

The is no guarantee that the evaluation will ever complete!

Type Parameters:
E - The type of value the evaluation of expression produces.
Parameters:
context - The variable context to use; cannot be null.
expression - The root expression; cannot be null.
type - The type of value the evaluation of expression produces; cannot be null.
Returns:
The result of the evaluation, or null if the evaluation was exited prematurely.
Throws:
NullPointerException - If either argument is null.
ExpressionException - If the evaluation fails.

toString

public String toString()
Returns the string representation of this interpreter.

Overrides:
toString in class Object
Returns:
The string representation; never null.

type

public Class<T> type()
Return the super-type of expression values handled by this interpreter.

Returns:
The type; never null.
See Also:
TypedExpression.type()

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.