Top Description Fields Constructors Methods
bsh

pack-priv Class BSHAllocationExpression

extends SimpleNode
Class Inheritance
Imports
java.lang.reflect.Array, .InvocationTargetException

New object, new array, or inner class style allocation with body.

Field Summary

Modifier and TypeField and Description
private static int
Inherited from bsh.SimpleNode:
childrenfirstTokenidJAVACODElastTokenparentsourceFile

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private Object
arrayAllocation(BSHArrayDimensions dimensionsNode, Class<T> type, CallStack callstack, Interpreter interpreter)

private Object
arrayNewInstance(Class<T> type, BSHArrayDimensions dimensionsNode, CallStack callstack)

Create an array of the dimensions specified in dimensionsNode.

private Object
constructObject(Class<T> type, Object[] args, CallStack callstack)

private Object
constructWithClassBody(Class<T> type, Object[] args, BSHBlock block, CallStack callstack, Interpreter interpreter)

private Object
constructWithInterfaceBody(Class<T> type, Object[] args, BSHBlock body, CallStack callstack, Interpreter interpreter)

public Object
eval(CallStack callstack, Interpreter interpreter)

Overrides bsh.SimpleNode.eval.

This is the general signature for evaluation of a node.
private Object
objectAllocation(BSHAmbiguousName nameNode, BSHArguments argumentsNode, CallStack callstack, Interpreter interpreter)

private Object
objectArrayAllocation(BSHAmbiguousName nameNode, BSHArrayDimensions dimensionsNode, CallStack callstack, Interpreter interpreter)

private Object
primitiveArrayAllocation(BSHPrimitiveType typeNode, BSHArrayDimensions dimensionsNode, CallStack callstack, Interpreter interpreter)

Inherited from bsh.SimpleNode:
dumpgetChildgetLineNumbergetSourceFilegetTextjjtAddChildjjtClosejjtGetChildjjtGetNumChildrenjjtGetParentjjtOpenjjtSetParentprunesetSourceFiletoStringtoString

Field Detail

innerClassCountback to summary
private static int innerClassCount

Constructor Detail

BSHAllocationExpressionback to summary
pack-priv BSHAllocationExpression(int id)

Method Detail

arrayAllocationback to summary
private Object arrayAllocation(BSHArrayDimensions dimensionsNode, Class<T> type, CallStack callstack, Interpreter interpreter) throws EvalError
arrayNewInstanceback to summary
private Object arrayNewInstance(Class<T> type, BSHArrayDimensions dimensionsNode, CallStack callstack) throws EvalError

Create an array of the dimensions specified in dimensionsNode. dimensionsNode may contain a number of "undefined" as well as "defined" dimensions.

Background: in Java arrays are implemented in arrays-of-arrays style where, for example, a two dimensional array is a an array of arrays of some base type. Each dimension-type has a Java class type associated with it... so if foo = new int[5][5] then the type of foo is int [][] and the type of foo[0] is int[], etc. Arrays may also be specified with undefined trailing dimensions - meaning that the lower order arrays are not allocated as objects. e.g. if foo = new int [5][]; then foo[0] == null //true; and can later be assigned with the appropriate type, e.g. foo[0] = new int[5]; (See Learning Java, O'Reilly & Associates more background).

To create an array with undefined trailing dimensions using the reflection API we must use an array type to represent the lower order (undefined) dimensions as the "base" type for the array creation... Java will then create the correct type by adding the dimensions of the base type to specified allocated dimensions yielding an array of dimensionality base + specified with the base dimensons unallocated. To create the "base" array type we simply create a prototype, zero length in each dimension, array and use it to get its class (Actually, I think there is a way we could do it with Class.forName() but I don't trust this). The code is simpler than the explanation... see below.

constructObjectback to summary
private Object constructObject(Class<T> type, Object[] args, CallStack callstack) throws EvalError
constructWithClassBodyback to summary
private Object constructWithClassBody(Class<T> type, Object[] args, BSHBlock block, CallStack callstack, Interpreter interpreter) throws EvalError
constructWithInterfaceBodyback to summary
private Object constructWithInterfaceBody(Class<T> type, Object[] args, BSHBlock body, CallStack callstack, Interpreter interpreter) throws EvalError
evalback to summary
public Object eval(CallStack callstack, Interpreter interpreter) throws EvalError

Overrides bsh.SimpleNode.eval.

Doc from bsh.SimpleNode.eval.

This is the general signature for evaluation of a node.

objectAllocationback to summary
private Object objectAllocation(BSHAmbiguousName nameNode, BSHArguments argumentsNode, CallStack callstack, Interpreter interpreter) throws EvalError
objectArrayAllocationback to summary
private Object objectArrayAllocation(BSHAmbiguousName nameNode, BSHArrayDimensions dimensionsNode, CallStack callstack, Interpreter interpreter) throws EvalError
primitiveArrayAllocationback to summary
private Object primitiveArrayAllocation(BSHPrimitiveType typeNode, BSHArrayDimensions dimensionsNode, CallStack callstack, Interpreter interpreter) throws EvalError