/** We have the variable: either it was declared here with a type, giving it block local scope or an untyped var was explicitly set here via setBlockVariable(). */ private boolean weHaveVar( String name ) { // super.variables.containsKey( name ) not any faster, I checked try { return super.getVariableImpl( name, false ) != null; } catch ( UtilEvalError e ) { return false; } }
public static Variable getVariable(NameSpace ns, String name) { if (null == ns) return null; try { return ns.getVariableImpl(name, false); } catch (Exception e) { return null; } }
/** We have the variable: either it was declared here with a type, giving it block local scope or an untyped var was explicitly set here via setBlockVariable(). */ private boolean weHaveVar( String name ) { // super.variables.containsKey( name ) not any faster, I checked try { return super.getVariableImpl( name, false ) != null; } catch ( UtilEvalError e ) { return false; } }
/** Get the specified variable in this namespace. * @param name the name * @param recurse If recurse is true then we recursively search through * parent namespaces for the variable. * <p> * Note: this method is primarily intended for use internally. If you * use this method outside of the bsh package you will have to use * Primitive.unwrap() to get primitive values. * @return The variable value or Primitive.VOID if it is not defined. * @throws UtilEvalError the util eval error * @see Primitive#unwrap(Object) */ public Object getVariable(final String name, final boolean recurse) throws UtilEvalError { final Variable var = this.getVariableImpl(name, recurse); return this.unwrapVariable(var); }
/** Get the specified variable in this namespace. @param recurse If recurse is true then we recursively search through parent namespaces for the variable. <p> Note: this method is primarily intended for use internally. If you use this method outside of the bsh package you will have to use Primitive.unwrap() to get primitive values. @see Primitive#unwrap( Object ) @return The variable value or Primitive.VOID if it is not defined. */ public Object getVariable( String name, boolean recurse ) throws UtilEvalError { Variable var = getVariableImpl( name, recurse ); return unwrapVariable( var ); }
/** Locate a variable and return the Variable object with optional recursion * through parent name spaces. * <p/> * If this namespace is static, return only static variables. * @param name the name * @param recurse the recurse * @return the Variable value or null if it is not defined * @throws UtilEvalError the util eval error */ protected Variable getVariableImpl(final String name, final boolean recurse) throws UtilEvalError { Variable var = null; if (this.variables.containsKey(name)) return this.variables.get(name); else var = this.getImportedVar(name); // try parent if (recurse && var == null && this.parent != null) var = this.parent.getVariableImpl(name, recurse); return var; }
var = super.getVariableImpl( name, recurse ); } else Variable localVar = super.getVariableImpl( name, false );
var = super.getVariableImpl( name, recurse ); } else Variable localVar = super.getVariableImpl( name, false );
/** Locate a variable and return the Variable object with optional recursion through parent name spaces. <p/> If this namespace is static, return only static variables. @return the Variable value or null if it is not defined */ protected Variable getVariableImpl( String name, boolean recurse ) throws UtilEvalError { Variable var = null; // Change import precedence if we are a class body/instance // Get imported first. if ( var == null && isClass ) var = getImportedVar( name ); if ( var == null && variables != null ) var = (Variable)variables.get(name); // Change import precedence if we are a class body/instance if ( var == null && !isClass ) var = getImportedVar( name ); // try parent if ( recurse && (var == null) && (parent != null) ) var = parent.getVariableImpl( name, recurse ); return var; }
Variable var = super.getVariableImpl(name, false); if (!_inGet && var == null) { _firstGet = true; try { this.setVariable(name, v != null ? v : Primitive.NULL, false); var = super.getVariableImpl(name, false); this.unsetVariable(name); //restore } finally {
/** Get Variable for value at specified index. * @param index 0 for lhs val1 else 1 * @param callstack the evaluation call stack * @return the variable in call stack name space for the ambiguous node text * @throws UtilEvalError thrown by getVariableImpl. */ private Variable getVariableAtNode(int index, CallStack callstack) throws UtilEvalError { Node nameNode = null; if (jjtGetChild(index).jjtGetNumChildren() > 0 && (nameNode = jjtGetChild(index).jjtGetChild(0)) instanceof BSHAmbiguousName) return callstack.top().getVariableImpl( ((BSHAmbiguousName) nameNode).text, true); return null; }
final Variable existing = this.getVariableImpl(name, recurse);
if (isGeneratedClass(clas) && null != ns && ns.isClass) if (staticOnly) { Variable var = ns.getVariableImpl(fieldName, true); Object val = Primitive.VOID; if ( null != var && (!var.hasModifier("private") Variable var = ns.getVariableImpl(fieldName, true); Object val = Primitive.VOID; if ( null != var && (!var.hasModifier("private")
/** Get an LHS reference to an object field. This method also deals with the field style property access. In the field does not exist we check for a property setter. */ static LHS getLHSObjectField( Object object, String fieldName ) throws UtilEvalError, ReflectError { if ( object instanceof This ) return new LHS( ((This)object).namespace, fieldName, false ); try { Invocable f = resolveExpectedJavaField( object.getClass(), fieldName, false/*staticOnly*/ ); return new LHS(object, f); } catch ( ReflectError e ) { NameSpace ns = getThisNS(object); if (isGeneratedClass(object.getClass()) && null != ns && ns.isClass) { Variable var = ns.getVariableImpl(fieldName, true); if ( null != var && (!var.hasModifier("private") || haveAccessibility()) ) return new LHS(ns, fieldName); } // not a field, try property access if ( hasObjectPropertySetter( object.getClass(), fieldName ) ) return new LHS( object, fieldName ); else throw e; } }
throws UtilEvalError { final Variable existing = this.getVariableImpl(name, false/* recurse */);
public Object eval(CallStack callstack, Interpreter interpreter) throws EvalError { renderTypeNode(); this.type = evalType(callstack, interpreter); if (!AutoCloseable.class.isAssignableFrom(this.getType())) throw new EvalError("The resource type "+ this.type.getName() +" does not implement java.lang.AutoCloseable.", this, callstack); this.name = this.getDeclarators()[0].name; // we let BSHTypedVariableDeclaration do the heavy lifting super.eval(callstack, interpreter); try { this.varThis = callstack.top().getVariableImpl(this.getName(), true); } catch (UtilEvalError e) { throw e.toEvalError("Unable to evaluate the try-with-resource " + this.getName() + ". With message:" + e.getMessage(), this, callstack); } return Primitive.VOID; }
Variable existing = getVariableImpl( name, false/*recurse*/ );
Variable existing = getVariableImpl( name, recurse );
throw new InterpreterError("null variable value"); final Variable existing = this.getVariableImpl(name, recurse);
static LHS getLHSStaticField(Class<?> clas, String fieldName) throws UtilEvalError, ReflectError { try { Invocable f = resolveExpectedJavaField( clas, fieldName, true/*onlystatic*/); return new LHS(f); } catch ( ReflectError e ) { NameSpace ns = getThisNS(clas); if (isGeneratedClass(clas) && null != ns && ns.isClass) { Variable var = ns.getVariableImpl(fieldName, true); if ( null != var && (!var.hasModifier("private") || haveAccessibility()) ) return new LHS(ns, fieldName); } // not a field, try property access if ( hasObjectPropertySetter( clas, fieldName ) ) return new LHS( clas, fieldName ); else throw e; } }