#8 Allowing Namespaces to Demand-Load Without Being the Current

open
nobody
None
5
2005-08-31
2005-08-31
Anonymous
No

Here is a fixed up version of the getImportedMethod of
the NameSpace class. Once inside a namespace, commands
would be demand-imported properly. I was hoping that if
you had a namespace object inside your current
namespace you could do the following even if the
command had not yet been demand-loaded:

aNamspace.cmd();

Before making the change below, the above call would
have failed unless the command was already loaded into
that namespace.

protected BshMethod getImportedMethod( String name,
Class [] sig )
throws UtilEvalError
{
// Try object imports
if ( importedObjects != null )
for(int i=0; i<importedObjects.size(); i++)
{
Object object = importedObjects.elementAt(i);
Class clas = object.getClass();
Method method = Reflect.resolveJavaMethod(
getClassManager(), clas, name, sig,
false/*onlyStatic*/ );
if ( method != null )
return new BshMethod( method, object );
}

// Try static imports
if ( importedStatic!= null )
for(int i=0; i<importedStatic.size(); i++)
{
Class clas = (Class)importedStatic.elementAt(i);
Method method = Reflect.resolveJavaMethod(
getClassManager(), clas, name, sig,
true/*onlyStatic*/ );
if ( method != null )
return new BshMethod( method, null/*object*/ );
}

// Try command imports (New Code below)
if ( importedCommands != null && thisReference != null) {
Object method = getCommand(name, sig,
thisReference.declaringInterpreter);

if (method instanceof BshMethod) {
return (BshMethod)method;
}
}

return null;
}

Discussion