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 )
| 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(). |
no test coverage detected