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

Method setValue

src/bsh/Variable.java:83–113  ·  view source on GitHub ↗

Set the value of the typed variable. @param value should be an object or wrapped bsh Primitive type. if value is null the appropriate default value will be set for the type: e.g. false for boolean, zero for integer types.

( Object value, int context )

Source from the content-addressed store, hash-verified

81 type: e.g. false for boolean, zero for integer types.
82 */
83 public void setValue( Object value, int context )
84 throws UtilEvalError
85 {
86
87 // check this.value
88 if (hasModifier("final")) {
89 if (this.value != null) {
90 throw new UtilEvalError("Final variable '" + getName() + "', can't re-assign.");
91 } else if (value == null && context == DECLARATION) {
92 return;
93 }
94 }
95
96 if ( value == null )
97 value = Primitive.getDefaultValue( type );
98
99 if ( lhs != null )
100 {
101 lhs.assign( Primitive.unwrap(value), false/*strictjava*/ );
102 return;
103 }
104
105 // TODO: should add isJavaCastable() test for strictJava
106 // (as opposed to isJavaAssignable())
107 if ( type != null )
108 value = Types.castObject( value, type,
109 context == DECLARATION ? Types.CAST : Types.ASSIGNMENT
110 );
111
112 this.value= value;
113 }
114
115 /*
116 Note: UtilEvalError here comes from lhs.getValue().

Callers 3

setVariableMethod · 0.95
setTypedVariableMethod · 0.95
VariableMethod · 0.95

Calls 6

hasModifierMethod · 0.95
getNameMethod · 0.95
getDefaultValueMethod · 0.95
unwrapMethod · 0.95
castObjectMethod · 0.95
assignMethod · 0.80

Tested by

no test coverage detected