/** Fill boxed numeric types with default numbers instead of nulls. * @param arr the array to fill. */ private void arrayFillDefaultValue(Object arr) { if (null == arr) return; Class<?> clas = arr.getClass(); Class<?> comp = Types.arrayElementType(clas); if ( !comp.isPrimitive() ) if ( Types.arrayDimensions(clas) > 1 ) for ( int i = 0; i < Array.getLength(arr); i++ ) arrayFillDefaultValue(Array.get(arr, i)); else Arrays.fill((Object[]) arr, Primitive.unwrap( Primitive.getDefaultValue(comp))); } }
return Primitive.NULL; else return Primitive.getDefaultValue(toType);
/** 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. */ public void setValue( Object value, int context ) throws UtilEvalError { // prevent final variable re-assign if (hasModifier("final")) { if (this.value != null) throw new UtilEvalError("Cannot re-assign final variable "+name+"."); if (value == null) return; } // TODO: should add isJavaCastable() test for strictJava // (as opposed to isJavaAssignable()) if ( type != null && type != Object.class && value != null ) { this.value = Types.castObject( value, type, context == DECLARATION ? Types.CAST : Types.ASSIGNMENT ); value = this.value; } this.value = value; if ( this.value == null && context != DECLARATION ) this.value = Primitive.getDefaultValue( type ); if ( lhs != null ) this.value = lhs.assign( this.value, false/*strictjava*/ ); }
/** 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. */ public void setValue( Object value, int context ) throws UtilEvalError { // check this.value if ( hasModifier("final") && this.value != null ) throw new UtilEvalError ("Final variable, can't re-assign."); if ( value == null ) value = Primitive.getDefaultValue( type ); if ( lhs != null ) { lhs.assign( value, false/*strictjava*/ ); return; } // TODO: should add isJavaCastable() test for strictJava // (as opposed to isJavaAssignable()) if ( type != null ) value = Types.castObject( value, type, context == DECLARATION ? Types.CAST : Types.ASSIGNMENT ); this.value= value; }
return checkOnly ? Types.VALID_CAST : getDefaultValue(toType);
: Primitive.getDefaultValue(typeNode.getBaseType());