/** This is the factory for Name objects which resolve names within this * namespace (e.g. toObject(), toClass(), toLHS()). * <p> * This was intended to support name resolver caching, allowing Name objects * to cache info about the resolution of names for performance reasons. * However this not proven useful yet. * <p> * We'll leave the caching as it will at least minimize Name object * creation. * <p> * (This method would be called getName() if it weren't already used for the * simple name of the NameSpace) * <p> * This method was public for a time, which was a mistake. Use get() * instead. * @param ambigname the ambigname * @return the name resolver */ Name getNameResolver(final String ambigname) { if (!this.names.containsKey(ambigname)) this.names.put(ambigname, new Name(this, ambigname)); return this.names.get(ambigname); }
/** see #toObject(CallStack, Interpreter) @param 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. */ synchronized public Object toObject( BshEvaluatingVisitor visitor, boolean forceClass ) throws UtilEvalError { reset(); Object obj = null; while( evalName != null ) obj = consumeNextObjectField(visitor, forceClass, false/*autoalloc*/ ); if ( obj == null ) throw new InterpreterError("null value in toObject()"); return obj; }
static String suffix(String name) { if(!isCompound(name)) return null; return suffix(name, countParts(name) - 1); }
static String prefix(String value) { if(!isCompound(value)) return null; return prefix(value, countParts(value) - 1); }
static String prefix(String value) { return prefix(value, countParts(value) - 1); }
String methodName = Name.suffix(value, 1); BshClassManager bcm = visitor.getInterpreter().getClassManager(); NameSpace namespace = visitor.getCallstack().top(); if ( !Name.isCompound(value) ) return invokeLocalMethod( visitor, args, callerInfo ); String prefix = Name.prefix(value); if ( prefix.equals("super") && Name.countParts(value) == 2 ) NameSpace classNameSpace = getClassNameSpace( thisNameSpace ); if ( classNameSpace != null ) Object obj = targetName.toObject( visitor );
if ( (evalBaseObject == null && !isCompound(evalName) ) && !forceClass ) Object obj = resolveThisFieldReference( visitor, namespace, evalName, false ); return completeRound( evalName, FINISHED, obj ); String varName = prefix(evalName, 1); if ( ( evalBaseObject == null || evalBaseObject instanceof This ) && !forceClass ) obj = resolveThisFieldReference(visitor, namespace, varName, false ); } else { obj = resolveThisFieldReference(visitor, ((This)evalBaseObject).namespace, varName, true ); return completeRound( varName, suffix(evalName), obj ); int i = 1; String className = null; for(; i <= countParts(evalName); i++) className = prefix(evalName, i); if ( (clas = namespace.getClass(className)) != null ) break; return completeRound(
reset(); LHS lhs; if ( !isCompound(evalName) ) while( evalName != null && isCompound( evalName ) ) obj = consumeNextObjectField( visitor, false/*forcclass*/, true/*autoallocthis*/ );
/** Assign the value to the name. name may evaluate to anything assignable. e.g. a variable or field. */ public void set( String name, Object value ) throws EvalError { // map null to Primtive.NULL coming in... if ( value == null ) value = Primitive.NULL; CallStack callstack = new CallStack(); try { if ( Name.isCompound( name ) ) { LHS lhs = globalNameSpace.getNameResolver( name ).toLHS( callstack, this ); lhs.assign( value, false ); } else // optimization for common case globalNameSpace.setVariable( name, value, false ); } catch ( UtilEvalError e ) { throw e.toEvalError( SimpleNode.JAVACODE, callstack ); } }
if ( Name.isCompound( fullname ) ) try { clas = getNameResolver( fullname ).toClass(); } catch ( ClassNotFoundException e ) { /* not a class */ } else
Object result = ths; NameSpace classNameSpace = getClassNameSpace( thisNameSpace ); if ( classNameSpace != null ) if ( isCompound( evalName ) ) result = classNameSpace.getThis( interpreter ); else
static String suffix(String value) { return suffix(value, countParts(value) - 1); }
Object obj = null; Class<?> clas = null; String name = Name.suffix(ambigName.text, 1); try { // import static method from class clas = namespace.getClass(Name.prefix(ambigName.text)); obj = Reflect.staticMethodImport(clas, name); } catch (Exception e) { e.printStackTrace(); /* ignore try field instead */ }
return this.classCache.get(name); final boolean unqualifiedName = !Name.isCompound(name);
Name.getClassNameSpace( ths.getNameSpace() );
return name.invokeMethod( this, args, node); } catch ( ReflectError e ) { throw new EvalError(
public static boolean isCompound(String value) { return countParts(value) > 1; }
String methodName = Name.suffix(value, 1); BshClassManager bcm = interpreter.getClassManager(); NameSpace namespace = callstack.top(); bcm, classOfStaticMethod, methodName, args, callerInfo ); if ( !Name.isCompound(value) ) return invokeLocalMethod( interpreter, args, callstack, callerInfo ); String prefix = Name.prefix(value); if ( prefix.equals("super") && Name.countParts(value) == 2 ) NameSpace thisNameSpace = ths.getNameSpace(); thisNameSpace.setNode(callerInfo); NameSpace classNameSpace = getClassNameSpace( thisNameSpace ); if ( classNameSpace != null ) Object obj = targetName.toObject( callstack, interpreter );
if ( evalBaseObject == null && !isCompound(evalName) && !forceClass ) { Object obj = resolveThisFieldReference( callstack, namespace, interpreter, evalName, false ); return completeRound( evalName, FINISHED, obj ); String varName = prefix(evalName, 1); if ( ( evalBaseObject == null || evalBaseObject instanceof This ) && !forceClass ) obj = resolveThisFieldReference( callstack, namespace, interpreter, varName, false ); } else { obj = resolveThisFieldReference( callstack, ((This)evalBaseObject).namespace, interpreter, varName, true ); return completeRound( varName, suffix(evalName), obj ); int i = 1; String className = null; for(; i <= countParts(evalName); i++) className = prefix(evalName, i); if ( (clas = namespace.getClass(className)) != null ) break; return completeRound( className,