package gw.rating.flow uses gw.lang.reflect.IType uses gw.rating.flow.util.RateflowTypeUtils uses gw.rating.flow.util.TypeMaps uses gw.api.system.PCLoggerCategory class LocalVariable { var _variableName : String as readonly VariableName var _variableFieldName : String as readonly FieldName var _variableLabel : String as readonly Label var _varType : IType as readonly VarType construct(varName : String, varFieldName : String, varLabel : String, vType : IType) { _variableName = varName _variableFieldName = varFieldName _variableLabel = varLabel _varType = vType } // internal to allow for direct unit testing internal function assignable(toType : IType, fromType : IType) : boolean { if (toType == null or fromType == null) return false if (TypeMaps.isAssignable(toType, fromType)) { return true } else if (gw.api.util.TypeUtil.isNominallyOrStructurallyAssignable(toType, java.math.BigDecimal)) { return gw.api.util.TypeUtil.isNominallyOrStructurallyAssignable(java.lang.Number.Type, fromType) } else { // test boxed types toType = RateflowTypeUtils.getBoxedType(toType) fromType = RateflowTypeUtils.getBoxedType(fromType) return TypeMaps.isAssignable(toType, fromType) } } function checkType(vType : IType) { if (not assignable(VarType, vType)) { if (assignable(vType, VarType)) { _varType = vType } // need to find narrowest common supertype // for now we'll just do a simple one else if ( assignable(java.math.BigDecimal, vType) and assignable(java.math.BigDecimal, VarType)) { _varType = java.math.BigDecimal } else { PCLoggerCategory.RATEFLOW.warn("Cannot change type of variable " +VariableName+ " from " +VarType.Name+ " to " +vType.Name) _varType = java.lang.Object } } // disallow float and double if ({float.Type, java.lang.Float.Type, double.Type, java.lang.Double.Type}.contains(VarType)) { _varType = java.math.BigDecimal } } }