/** Re-throw as an eval error, prefixing msg to the message and specifying the node. If a node already exists the addNode is ignored. @see #setNode(bsh.ast.SimpleNode) <p> @param msg may be null for no additional message. */ public EvalError toEvalError( String msg, SimpleNode node, CallStack callstack ) { if ( Interpreter.DEBUG ) printStackTrace(); if ( msg == null ) msg = ""; else msg = msg + ": "; return new EvalError( msg+getMessage(), node, callstack, this ); }
static boolean booleanUnaryOperation(Boolean B, int kind) throws UtilEvalError { boolean operand = B.booleanValue(); switch(kind) { case BANG: return !operand; } throw new UtilEvalError("Operator inappropriate for boolean"); }
public EvalError toEvalError ( SimpleNode node, CallStack callstack ) { return toEvalError( null, node, callstack ); }
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; }
throw new UtilEvalError("Can't assign to 'this'." ); throw new UtilEvalError( "LHS evaluation: " + e.getMessage() ); throw new UtilEvalError("Can't assign to class: " + value ); throw new UtilEvalError("Error in LHS: " + value ); || evalName.equals("caller") throw new UtilEvalError( "Can't assign to special variable: "+evalName ); throw new UtilEvalError("Field access: "+e);
public void initService() { bsh = new Interpreter (); BshClassManager bcm = bsh.getClassManager(); try { bcm.setClassPath(getServer().getLoader().getURLs()); } catch (UtilEvalError e) { e.printStackTrace(); } bcm.setClassLoader(getServer().getLoader()); } public void startService() {
/** Unassign the variable name. Name should evaluate to a variable. */ public void unset( String name ) throws EvalError { /* We jump through some hoops here to handle arbitrary cases like unset("bsh.foo"); */ CallStack callstack = new CallStack(); try { LHS lhs = globalNameSpace.getNameResolver( name ).toLHS( callstack, this ); if ( lhs.type != LHS.VARIABLE ) throw new EvalError("Can't unset, not a variable: "+name, SimpleNode.JAVACODE, new CallStack()); lhs.nameSpace.unsetVariable( name ); } catch ( UtilEvalError e ) { throw new EvalError( e.getMessage(), SimpleNode.JAVACODE, new CallStack(), e); } }
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 ); }
+ "`"+paramNames[k]+"'" + " for method: " + name + " : " + e.getMessage(), callerInfo, callstack ); paramType, argValues[i], paramModifiers[k]); } catch ( UtilEvalError e2 ) { throw e2.toEvalError( "Typed method parameter assignment", callerInfo, callstack ); interpreter.getStrictJava() ); } catch ( UtilEvalError e3 ) { throw e3.toEvalError( "Typed method parameter assignment", callerInfo, callstack ); paramModifiers[lastParamIndex]); } catch (UtilEvalError e1) { throw e1.toEvalError("Typed method parameter assignment", callerInfo, callstack); if ( retControl != null ) node = retControl.returnPoint; throw e.toEvalError( "Incorrect type returned from method: " + name + e.getMessage(), node, callstack );
throw new UtilEvalError("Can't assign to 'this'." ); throw new UtilEvalError( "LHS evaluation: " + e.getMessage(), e); throw new UtilEvalError("Can't assign to class: " + value ); throw new UtilEvalError("Error in LHS: " + value ); || evalName.equals("caller") throw new UtilEvalError( "Can't assign to special variable: "+evalName ); throw new UtilEvalError("Field access: "+e, e);
/** Unassign the variable name. Name should evaluate to a variable. */ public void unset( String name ) throws EvalError { /* We jump through some hoops here to handle arbitrary cases like unset("bsh.foo"); */ CallStack callstack = new CallStack(); try { LHS lhs = globalNameSpace.getNameResolver( name ).toLHS( new BshEvaluatingVisitor(callstack, this) ); if ( lhs.type != LHS.VARIABLE ) throw new EvalError("Can't unset, not a variable: "+name, SimpleNode.JAVACODE, new CallStack() ); //lhs.assign( null, false ); lhs.nameSpace.unsetVariable( name ); } catch ( UtilEvalError e ) { throw new EvalError( e.getMessage(), SimpleNode.JAVACODE, new CallStack() ); } }
public static boolean booleanUnaryOperation(Boolean B, int kind) throws UtilEvalError { boolean operand = B.booleanValue(); switch(kind) { case BANG: return !operand; default: throw new UtilEvalError("Operator inappropriate for boolean"); } }
public EvalError toEvalError ( SimpleNode node, CallStack callstack ) { return toEvalError( null, node, callstack ); }
+ "`"+paramNames[i]+"'" + " for method: " + name + " : " + e.getMessage(), callerInfo, visitor.getCallstack() ); throw e2.toEvalError( "Typed method parameter assignment", callerInfo, visitor.getCallstack() ); visitor.getInterpreter().getStrictJava() ); } catch ( UtilEvalError e3 ) { throw e3.toEvalError( callerInfo, visitor.getCallstack() ); if ( retControl != null ) node = retControl.returnPoint; throw e.toEvalError( "Incorrect type returned from method: " + name + e.getMessage(), node, visitor.getCallstack() );
existing.setValue(value, Variable.ASSIGNMENT); } catch (final UtilEvalError e) { throw new UtilEvalError( "Variable assignment: " + name + ": " + e.getMessage(), e); throw new UtilEvalError( "(Strict Java mode) Assignment to undeclared variable: " + name);
/** Re-throw as an eval error, prefixing msg to the message and specifying the node. If a node already exists the addNode is ignored. @see #setNode( bsh.SimpleNode ) <p> @param msg may be null for no additional message. */ public EvalError toEvalError( String msg, SimpleNode node, CallStack callstack ) { if ( Interpreter.DEBUG.get() ) printStackTrace(); if ( msg == null ) msg = ""; else msg += ": "; return new EvalError( msg + this.getMessage(), node, callstack, this ); }
public int intValue() throws UtilEvalError { if(value instanceof Number) return((Number)value).intValue(); else throw new UtilEvalError("Primitive not a number"); }
public Class ambiguousNameToClass( BSHAmbiguousName node ) throws EvalError { try { return node.getName( callstack.top() ).toClass(); } catch ( ClassNotFoundException e ) { throw new EvalError( e.getMessage(), node, callstack, e ); } catch ( UtilEvalError e2 ) { // ClassPathException is a type of UtilEvalError throw e2.toEvalError( node, callstack ); } }
currentInitializer, baseType, Types.CAST ); } catch ( UtilEvalError e ) { throw e.toEvalError( "Error in array initializer", this, callstack ); initializers = Types.castObject(initializers, originalBaseType, Types.CAST); } catch (UtilEvalError e) { throw new EvalError(e.getMessage(), this, callstack, e);
existing.setValue( value, Variable.ASSIGNMENT ); } catch ( UtilEvalError e ) { throw new UtilEvalError( "Variable assignment: " + name + ": " + e.getMessage()); throw new UtilEvalError( "(Strict Java mode) Assignment to undeclared variable: " +name );