/** Creates the variable. * @param name the name * @param type the type * @param value the value * @param mods the mods * @return the variable * @throws UtilEvalError the util eval error */ protected Variable createVariable(final String name, final Class<?> type, final Object value, final Modifiers mods) throws UtilEvalError { return new Variable(name, type, value, mods); }
/** Creates the variable. * @param name the name * @param type the type * @param lhs the lhs * @return the variable * @throws UtilEvalError the util eval error */ protected Variable createVariable(final String name, final Class<?> type, final LHS lhs) throws UtilEvalError { return new Variable(name, type, lhs); }
protected Variable getImportedVar( String name ) throws UtilEvalError { // Try object imports if ( importedObjects != null ) for(int i=0; i<importedObjects.size(); i++) { Object object = importedObjects.get(i); Class clas = object.getClass(); Field field = Reflect.resolveJavaField( clas, name, false/*onlyStatic*/ ); if ( field != null ) return new Variable( name, field.getType(), new LHS( object, field ) ); } // Try static imports if ( importedStatic!= null ) for(int i=0; i<importedStatic.size(); i++) { Class clas = importedStatic.get(i); Field field = Reflect.resolveJavaField( clas, name, true/*onlyStatic*/ ); if ( field != null ) return new Variable( name, field.getType(), new LHS( field ) ); } return null; }
static Variable[] getDeclaredVariables(BSHBlock body, BshEvaluatingVisitor visitor, String defaultPackage) { List<Variable> vars = new ArrayList<Variable>(); for (int child = 0; child < body.jjtGetNumChildren(); child++) { SimpleNode node = (SimpleNode) body.jjtGetChild(child); if (node instanceof BSHTypedVariableDeclaration) { BSHTypedVariableDeclaration tvd = (BSHTypedVariableDeclaration) node; Modifiers modifiers = tvd.modifiers; String type = visitor.getTypeDescriptor(tvd.getTypeNode(), defaultPackage); BSHVariableDeclarator[] vardec = tvd.getDeclarators(); for (BSHVariableDeclarator aVardec : vardec) { String name = aVardec.name; try { Variable var = new Variable(name, type, null/*value*/, modifiers); vars.add(var); } catch (UtilEvalError e) { // value error shouldn't happen } } } } return vars.toArray(new Variable[vars.size()]); }
var = new Variable( name, (Class)null, value, (Modifiers)null ); else var = localVar;
public Variable createVariable( String name, Class type, Object value, Modifiers mods ) { LHS lhs = new LHS( externalMap, name ); // Is this race condition worth worrying about? // value will appear in map before it's really in the interpreter try { lhs.assign( value, false/*strict*/ ); } catch ( UtilEvalError e) { throw new InterpreterError( e.toString() ); } return new Variable( name, type, lhs ); }
variables.put( name, new Variable( name, type, value, modifiers ) );
name, new Variable( name, value, null/*modifiers*/ ) );
Variable var = new Variable(dec.name, type, lhs); var.modifiers = modifiers; var.setValue(value, Variable.ASSIGNMENT);