bsh
Class Name

java.lang.Object
  extended bybsh.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 declared scripted BeanShell method.

Name objects are created by the factory method NameSpace getNameResolver(), which caches them subject to a class namespace change. This means that we can cache information about various types of resolution here. Currently very little if any information is cached. However with a future "optimize" setting that defeats certain dynamic behavior we might be able to cache quite a bit.


Field Summary
(package private)  java.lang.Class asClass
          The result is a class
(package private)  java.lang.Class classOfStaticMethod
          The result is a static method call on the following class
 NameSpace namespace
           
(package private)  java.lang.String value
           
 
Constructor Summary
(package private) Name(NameSpace namespace, java.lang.String s)
          This constructor should *not* be used in general.
 
Method Summary
(package private) static int countParts(java.lang.String value)
           
(package private) static NameSpace getClassNameSpace(NameSpace thisNameSpace)
           
 java.lang.Object invokeMethod(Interpreter interpreter, java.lang.Object[] args, CallStack callstack, SimpleNode callerInfo)
          Invoke the method identified by this name.
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)
           
(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)
           
 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

asClass

java.lang.Class asClass
The result is a class


classOfStaticMethod

java.lang.Class classOfStaticMethod
The result is a static method call on the following class

Constructor Detail

Name

Name(NameSpace namespace,
     java.lang.String s)
This constructor should *not* be used in general. Use NameSpace getNameResolver() which supports caching.

See Also:
getNameResolver().
Method Detail

toObject

public java.lang.Object toObject(CallStack callstack,
                                 Interpreter interpreter)
                          throws UtilEvalError
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.

Throws:
UtilEvalError

toObject

public java.lang.Object toObject(CallStack callstack,
                                 Interpreter interpreter,
                                 boolean forceClass)
                          throws UtilEvalError
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.
Throws:
UtilEvalError
See Also:
toObject()

resolveThisFieldReference

java.lang.Object resolveThisFieldReference(CallStack callstack,
                                           NameSpace thisNameSpace,
                                           Interpreter interpreter,
                                           java.lang.String varName,
                                           boolean specialFieldsVisible)
                                     throws UtilEvalError
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.
Throws:
UtilEvalError

getClassNameSpace

static NameSpace getClassNameSpace(NameSpace thisNameSpace)
Returns:
the enclosing class body namespace or null if not in a class.

toClass

public java.lang.Class toClass()
                        throws java.lang.ClassNotFoundException,
                               UtilEvalError
Check the cache, else use toObject() to try to resolve to a class identifier.

Throws:
java.lang.ClassNotFoundException - on class not found.
ClassPathException - (type of EvalError) on special case of ambiguous unqualified name after super import.
UtilEvalError

toLHS

public LHS toLHS(CallStack callstack,
                 Interpreter interpreter)
          throws UtilEvalError
Throws:
UtilEvalError

invokeMethod

public java.lang.Object invokeMethod(Interpreter interpreter,
                                     java.lang.Object[] args,
                                     CallStack callstack,
                                     SimpleNode callerInfo)
                              throws UtilEvalError,
                                     EvalError,
                                     ReflectError,
                                     java.lang.reflect.InvocationTargetException
Invoke the method identified by this name. Performs caching of method resolution using SignatureKey.

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");
                

Throws:
UtilEvalError
EvalError
ReflectError
java.lang.reflect.InvocationTargetException

isCompound

public 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()