Determine if the type is assignable via Java boxing/unboxing rules.
( Class lhsType, Class rhsType )
| 329 | Determine if the type is assignable via Java boxing/unboxing rules. |
| 330 | */ |
| 331 | static boolean isJavaBoxTypesAssignable( |
| 332 | Class lhsType, Class rhsType ) |
| 333 | { |
| 334 | // Assignment to loose type... defer to bsh extensions |
| 335 | if ( lhsType == null ) |
| 336 | return false; |
| 337 | |
| 338 | // prim can be boxed and assigned to Object |
| 339 | if ( lhsType == Object.class ) |
| 340 | return true; |
| 341 | |
| 342 | // null rhs type corresponds to type of Primitive.NULL |
| 343 | // assignable to any object type but not array |
| 344 | if (rhsType == null) |
| 345 | return !lhsType.isPrimitive() && !lhsType.isArray(); |
| 346 | |
| 347 | // prim numeric type can be boxed and assigned to number |
| 348 | if ( lhsType == Number.class |
| 349 | && rhsType != Character.TYPE |
| 350 | && rhsType != Boolean.TYPE |
| 351 | ) |
| 352 | return true; |
| 353 | |
| 354 | // General case prim type to wrapper or vice versa. |
| 355 | // I don't know if this is faster than a flat list of 'if's like above. |
| 356 | // wrapperMap maps both prim to wrapper and wrapper to prim types, |
| 357 | // so this test is symmetric |
| 358 | if ( Primitive.wrapperMap.get( lhsType ) == rhsType ) |
| 359 | return true; |
| 360 | |
| 361 | return isJavaBaseAssignable(lhsType, rhsType); |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | Test if a type can be converted to another type via BeanShell |
no test coverage detected