MCPcopy Index your code
hub / github.com/beanshell/beanshell / eval

Method eval

src/bsh/BSHEnhancedForStatement.java:45–121  ·  view source on GitHub ↗
( CallStack callstack , Interpreter interpreter )

Source from the content-addressed store, hash-verified

43 BSHEnhancedForStatement(int id) { super(id); }
44
45 public Object eval( CallStack callstack , Interpreter interpreter )
46 throws EvalError
47 {
48 Class elementType = null;
49 SimpleNode expression, statement=null;
50
51 NameSpace enclosingNameSpace = callstack.top();
52 SimpleNode firstNode =((SimpleNode)jjtGetChild(0));
53 int nodeCount = jjtGetNumChildren();
54 if (firstNode instanceof BSHType) {
55 elementType=((BSHType)firstNode).getType( callstack, interpreter );
56 expression=((SimpleNode)jjtGetChild(1));
57 if (nodeCount > 2) {
58 statement=((SimpleNode)jjtGetChild(2));
59 }
60 } else {
61 expression=firstNode;
62 if (nodeCount > 1) {
63 statement=((SimpleNode)jjtGetChild(1));
64 }
65 }
66 BlockNameSpace eachNameSpace = new BlockNameSpace( enclosingNameSpace );
67 callstack.swap( eachNameSpace );
68
69 final Object iteratee = expression.eval( callstack, interpreter );
70 if (iteratee == Primitive.NULL) {
71 throw new EvalError("The collection, array, map, iterator, or " + "enumeration portion of a for statement cannot be null.", this, callstack);
72 }
73 CollectionManager cm = CollectionManager.getCollectionManager();
74 if ( !cm.isBshIterable( iteratee ) )
75 throw new EvalError("Can't iterate over type: "
76 +iteratee.getClass(), this, callstack );
77 Iterator iterator = cm.getBshIterator( iteratee );
78
79 Object returnControl = Primitive.VOID;
80 while (iterator.hasNext()) {
81 try {
82 Object value = iterator.next();
83 if (value == null) {
84 value = Primitive.NULL;
85 }
86 if (elementType != null) {
87 eachNameSpace.setTypedVariable(varName/*name*/, elementType/*type*/, value/*value*/, new Modifiers()/*none*/);
88 } else {
89 eachNameSpace.setVariable( varName, value, false );
90 }
91 } catch ( UtilEvalError e ) {
92 throw e.toEvalError("for loop iterator variable:" + varName, this, callstack);
93 }
94
95 boolean breakout = false; // switch eats a multi-level break here?
96 if (statement != null) {
97 // not empty statement
98 Object ret = statement.eval( callstack, interpreter );
99 if (ret instanceof ReturnControl) {
100 switch (((ReturnControl) ret).kind) {
101 case RETURN:
102 returnControl = ret;

Callers

nothing calls this directly

Calls 15

evalMethod · 0.95
getCollectionManagerMethod · 0.95
isBshIterableMethod · 0.95
getBshIteratorMethod · 0.95
setVariableMethod · 0.95
topMethod · 0.80
swapMethod · 0.80
getClassMethod · 0.80
hasNextMethod · 0.80
jjtGetChildMethod · 0.65
jjtGetNumChildrenMethod · 0.65
getTypeMethod · 0.45

Tested by

no test coverage detected