bsh
Class BlockNameSpace

java.lang.Object
  extended bybsh.NameSpace
      extended bybsh.BlockNameSpace
All Implemented Interfaces:
BshClassManager.Listener, NameSource, java.io.Serializable

class BlockNameSpace
extends NameSpace

A specialized namespace for Blocks (e.g. the body of a "for" statement). The Block acts like a child namespace but only for typed variables declared within it (block local scope) or untyped variables explicitly set in it via setBlockVariable(). Otherwise variable assignment (including untyped variable usage) acts like it is part of the containing block.


Nested Class Summary
 
Nested classes inherited from class bsh.NameSource
NameSource.Listener
 
Field Summary
 
Fields inherited from class bsh.NameSpace
callerInfoNode, classInstance, classStatic, importedClasses, isClass, isMethod, JAVACODE, nameSourceListeners
 
Constructor Summary
BlockNameSpace(NameSpace parent)
           
 
Method Summary
 This getSuper(Interpreter declaringInterpreter)
          super is our parent's super
(package private)  This getThis(Interpreter declaringInterpreter)
          Get a 'this' reference is our parent's 'this' for the object closure.
 void importClass(java.lang.String name)
          delegate import to our parent
 void importPackage(java.lang.String name)
          delegate import to our parent
 void setBlockVariable(java.lang.String name, java.lang.Object value)
          Set an untyped variable in the block namespace.
 void setMethod(java.lang.String name, BshMethod method)
          Note: this is primarily for internal use.
 void setVariable(java.lang.String name, java.lang.Object value, boolean strictJava, boolean recurse)
          Override the standard namespace behavior to make assignments happen in our parent (enclosing) namespace, unless the variable has already been assigned here via a typed declaration or through the special setBlockVariable() (used for untyped args in try/catch).
 
Methods inherited from class bsh.NameSpace
addNameSourceListener, cacheClass, classLoaderChanged, clear, doSuperImport, get, getAllNames, getAllNamesAux, getClass, getClassInstance, getClassManager, getCommand, getDeclaredVariables, getGlobal, getImportedMethod, getImportedVar, getInvocationLine, getInvocationText, getMethod, getMethod, getMethodNames, getMethods, getName, getNameResolver, getNode, getPackage, getParent, getVariable, getVariable, getVariableImpl, getVariableNames, identifierToClass, importCommands, importObject, importStatic, invokeMethod, invokeMethod, loadDefaultImports, nameSpaceChanged, prune, setClassInstance, setClassManager, setClassStatic, setLocalVariable, setName, setNode, setPackage, setParent, setTypedVariable, setTypedVariable, setVariable, toString, unsetVariable, unwrapVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BlockNameSpace

public BlockNameSpace(NameSpace parent)
               throws EvalError
Method Detail

setVariable

public void setVariable(java.lang.String name,
                        java.lang.Object value,
                        boolean strictJava,
                        boolean recurse)
                 throws UtilEvalError
Override the standard namespace behavior to make assignments happen in our parent (enclosing) namespace, unless the variable has already been assigned here via a typed declaration or through the special setBlockVariable() (used for untyped args in try/catch).

i.e. only allow typed var declaration to happen in this namespace. Typed vars are handled in the ordinary way local scope. All untyped assignments are delegated to the enclosing context.

Overrides:
setVariable in class NameSpace
Parameters:
strictJava - specifies whether strict java rules are applied.
recurse - determines whether we will search for the variable in our parent's scope before assigning locally.
Throws:
UtilEvalError
See Also:

Setting a new variable (which didn't exist before) or removing a variable causes a namespace change.


setBlockVariable

public void setBlockVariable(java.lang.String name,
                             java.lang.Object value)
                      throws UtilEvalError
Set an untyped variable in the block namespace. The BlockNameSpace would normally delegate this set to the parent. Typed variables are naturally set locally. This is used in try/catch block argument.

Throws:
UtilEvalError

getThis

This getThis(Interpreter declaringInterpreter)
Get a 'this' reference is our parent's 'this' for the object closure. e.g. Normally a 'this' reference to a BlockNameSpace (e.g. if () { } ) resolves to the parent namespace (e.g. the namespace containing the "if" statement).

Overrides:
getThis in class NameSpace
See Also:
#getBlockThis( Interpreter )

getSuper

public This getSuper(Interpreter declaringInterpreter)
super is our parent's super

Overrides:
getSuper in class NameSpace

importClass

public void importClass(java.lang.String name)
delegate import to our parent

Overrides:
importClass in class NameSpace

importPackage

public void importPackage(java.lang.String name)
delegate import to our parent

Overrides:
importPackage in class NameSpace

setMethod

public void setMethod(java.lang.String name,
                      BshMethod method)
               throws UtilEvalError
Description copied from class: NameSpace
Note: this is primarily for internal use.

Overrides:
setMethod in class NameSpace
Throws:
UtilEvalError
See Also:
Interpreter.source( String ), Interpreter.eval( String )