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

Method assign

src/bsh/LHS.java:189–253  ·  view source on GitHub ↗

Assign a value to the LHS.

( Object val, boolean strictJava )

Source from the content-addressed store, hash-verified

187 Assign a value to the LHS.
188 */
189 public Object assign( Object val, boolean strictJava )
190 throws UtilEvalError
191 {
192 if ( type == VARIABLE )
193 {
194 // Set the variable in namespace according to localVar flag
195 if ( localVar )
196 nameSpace.setLocalVariable( varName, val, strictJava );
197 else
198 nameSpace.setVariable( varName, val, strictJava );
199 } else
200 if ( type == FIELD )
201 {
202 try {
203 // This should probably be in Reflect.java
204 Reflect.setAccessible(field);
205 field.set( object, Primitive.unwrap(val));
206 return val;
207 }
208 catch( NullPointerException e) {
209 throw new UtilEvalError(
210 "LHS ("+field.getName()+") not a static field.",e);
211 }
212 catch( IllegalAccessException e2) {
213 throw new UtilEvalError(
214 "LHS ("+field.getName()+") can't access field: "+e2,e2);
215 }
216 catch( IllegalArgumentException e3)
217 {
218 String type = val instanceof Primitive ?
219 ((Primitive)val).getType().getName()
220 : val.getClass().getName();
221 throw new UtilEvalError(
222 "Argument type mismatch. " + (val == null ? "null" : type )
223 + " not assignable to field "+field.getName());
224 }
225 }
226 else
227 if ( type == PROPERTY )
228 {
229 CollectionManager cm = CollectionManager.getCollectionManager();
230 if ( cm.isMap( object ) )
231 cm.putInMap( object/*map*/, propName, Primitive.unwrap(val) );
232 else
233 try {
234 Reflect.setObjectProperty(object, propName, val);
235 }
236 catch(ReflectError e) {
237 Interpreter.debug("Assignment: " + e.getMessage());
238 throw new UtilEvalError("No such property: " + propName);
239 }
240 } else
241 if ( type == INDEX )
242 try {
243 Reflect.setIndex(object, index, val);
244 } catch ( UtilTargetError e1 ) { // pass along target error
245 throw e1;
246 } catch ( Exception e ) {

Callers 6

initInstanceMethod · 0.95
evalMethod · 0.95
generateClassImplMethod · 0.95
setMethod · 0.95
lhsUnaryOperationMethod · 0.80
setValueMethod · 0.80

Calls 15

setAccessibleMethod · 0.95
unwrapMethod · 0.95
getCollectionManagerMethod · 0.95
isMapMethod · 0.95
putInMapMethod · 0.95
setObjectPropertyMethod · 0.95
debugMethod · 0.95
setIndexMethod · 0.95
setLocalVariableMethod · 0.80
getClassMethod · 0.80
setVariableMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected