bsh
Class Name

java.lang.Object
  |
  +--bsh.Name
All Implemented Interfaces:
java.io.Serializable

class Name
extends java.lang.Object
implements java.io.Serializable

What's in a name? I'll tell you... Name() is a somewhat ambiguous thing in the grammar and so is this.

This class is a name resolver. It holds a possibly ambiguous dot separated name and reference to a namespace in which it allegedly lives. It provides methods that attempt to resolve the name to various types of entities: e.g. an Object, a Class, a localy declared bsh method.

implementing *** Name objects are not to be constructed arbitrarily, but are to be factoried by NameSpace.getNameResolver, which caches them subject to a namespace change. This means that we can cache information about various types of resolution here.


Nested Class Summary
(package private) static class Name.ClassIdentifier
           
 
Field Summary
private  int callstackDepth
           
private  java.lang.Object evalBaseObject
           
private  java.lang.String evalName
           
private  boolean literalCallerReference
          The last round consume the literal 'caller' reference (not super, global, or another This type var).
private  boolean literalThisReference
          The last round consume the literal 'this' reference (not super, global, or another This type var).
 NameSpace namespace
           
(package private)  java.lang.String value
           
 
Constructor Summary
Name(NameSpace namespace, java.lang.String s)
          This constructor should *not* be used in general.
 
Method Summary
private  java.lang.Object consumeNextObjectField(CallStack callstack, Interpreter interpreter, boolean forceClass)
          Get next prefixed object field component
(package private) static int countParts(java.lang.String value)
           
 java.lang.Object invokeLocalMethod(Interpreter interpreter, java.lang.Object[] args, CallStack callstack, SimpleNode callerInfo)
          Invoke a locally declared method or a bsh command.
 java.lang.Object invokeMethod(Interpreter interpreter, java.lang.Object[] args, CallStack callstack, SimpleNode callerInfo)
          Invoke the method identified by name.
(package private) static boolean isCompound(java.lang.String value)
           
(package private) static java.lang.String prefix(java.lang.String value)
           
(package private) static java.lang.String prefix(java.lang.String value, int parts)
           
private  void reset()
           
(package private)  java.lang.Object resolveThisFieldReference(CallStack callstack, NameSpace thisNamespace, Interpreter interpreter, java.lang.String varName, boolean specialFieldsVisible)
          Resolve a variable relative to a This reference.
(package private) static java.lang.String suffix(java.lang.String name)
           
static java.lang.String suffix(java.lang.String value, int parts)
           
 java.lang.Class toClass()
          Check the cache, else use toObject() to try to resolve to a class identifier.
 LHS toLHS(CallStack callstack, Interpreter interpreter)
           
private  BshMethod toLocalMethod(java.lang.Object[] args)
           
 java.lang.Object toObject(CallStack callstack, Interpreter interpreter)
          Resolve possibly complex name to an object value.
 java.lang.Object toObject(CallStack callstack, Interpreter interpreter, boolean forceClass)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

namespace

public NameSpace namespace

value

java.lang.String value

evalName

private java.lang.String evalName

evalBaseObject

private java.lang.Object evalBaseObject

callstackDepth

private int callstackDepth

literalThisReference

private boolean literalThisReference
The last round consume the literal 'this' reference (not super, global, or another This type var). We use this flag to support magic variables that can only be referenced through 'this.xxx', e.g. this.interpreter and this.caller;


literalCallerReference

private boolean literalCallerReference
The last round consume the literal 'caller' reference (not super, global, or another This type var). This is used to limit references to .caller to only after a literal 'this' or compound '.caller'.

Constructor Detail

Name

public Name(NameSpace namespace,
            java.lang.String s)
This constructor should *not* be used in general. Use NameSpace getNameResolver() which supports caching. I wish I could make this "friendly" to just that class.

See Also:
getNameResolver().
Method Detail

reset

private void reset()

toObject

public java.lang.Object toObject(CallStack callstack,
                                 Interpreter interpreter)
                          throws EvalError
Resolve possibly complex name to an object value. Throws EvalError on various failures. A null object value is indicated by a Primitive.NULL. A return type of Primitive.VOID comes from attempting to access an undefined variable. Some cases: myVariable myVariable.foo myVariable.foo.bar java.awt.GridBagConstraints.BOTH my.package.stuff.MyClass.someField.someField... Interpreter reference is necessary to allow resolution of "this.interpreter" magic field. CallStack reference is necessary to allow resolution of "this.caller" magic field. "this.callstack" magic field.

EvalError

toObject

public java.lang.Object toObject(CallStack callstack,
                                 Interpreter interpreter,
                                 boolean forceClass)
                          throws EvalError
Parameters:
forceClass - if true then resolution will only produce a class. This is necessary to disambiguate in cases where the grammar knows that we want a class; where in general the var path may be taken.
EvalError
See Also:
toObject()

consumeNextObjectField

private java.lang.Object consumeNextObjectField(CallStack callstack,
                                                Interpreter interpreter,
                                                boolean forceClass)
                                         throws EvalError
Get next prefixed object field component

EvalError

resolveThisFieldReference

java.lang.Object resolveThisFieldReference(CallStack callstack,
                                           NameSpace thisNamespace,
                                           Interpreter interpreter,
                                           java.lang.String varName,
                                           boolean specialFieldsVisible)
                                     throws EvalError
Resolve a variable relative to a This reference. This is the general variable resolution method, accomodating special fields from the This context. Together the namespace and interpreter comprise the This context. The callstack, if available allows for the this.caller construct. Optionally interpret special "magic" field names: e.g. interpreter.

Parameters:
callstack - may be null, but this is only legitimate in special cases where we are sure resolution will not involve this.caller.
EvalError

toClass

public java.lang.Class toClass()
                        throws EvalError
Check the cache, else use toObject() to try to resolve to a class identifier. Throws EvalError on class not found...

EvalError

toLHS

public LHS toLHS(CallStack callstack,
                 Interpreter interpreter)
          throws EvalError
EvalError

toLocalMethod

private BshMethod toLocalMethod(java.lang.Object[] args)

invokeMethod

public java.lang.Object invokeMethod(Interpreter interpreter,
                                     java.lang.Object[] args,
                                     CallStack callstack,
                                     SimpleNode callerInfo)
                              throws EvalError,
                                     ReflectError,
                                     java.lang.reflect.InvocationTargetException
Invoke the method identified by name. Name contains a wholely unqualfied messy name; resolve it to ( object | static prefix ) + method name and invoke. The interpreter is necessary to support 'this.interpreter' references in the called code. (e.g. debug()); Some cases: // dynamic local(); myVariable.foo(); myVariable.bar.blah.foo(); // static java.lang.Integer.getInteger("foo");

EvalError
ReflectError
java.lang.reflect.InvocationTargetException

invokeLocalMethod

public java.lang.Object invokeLocalMethod(Interpreter interpreter,
                                          java.lang.Object[] args,
                                          CallStack callstack,
                                          SimpleNode callerInfo)
                                   throws EvalError,
                                          ReflectError,
                                          java.lang.reflect.InvocationTargetException
Invoke a locally declared method or a bsh command. If the method is not already declared in the namespace then try to load it as a resource from the /bsh/commands path. Note: instead of invoking the method directly here we should probably call invokeObjectMethod passing a This reference. That would have the side effect of allowing a locally defined invoke() method to handle undeclared method invocations just like in objects. Not sure if this is desirable... It seems that if you invoke a method directly in scope it should be there. Keeping this code separate allows us to differentiate between methods invoked directly in scope and those invoked through object references.

EvalError
ReflectError
java.lang.reflect.InvocationTargetException

isCompound

static boolean isCompound(java.lang.String value)

countParts

static int countParts(java.lang.String value)

prefix

static java.lang.String prefix(java.lang.String value)

prefix

static java.lang.String prefix(java.lang.String value,
                               int parts)

suffix

static java.lang.String suffix(java.lang.String name)

suffix

public static java.lang.String suffix(java.lang.String value,
                                      int parts)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object