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

Method isJavaBoxTypesAssignable

src/bsh/Types.java:331–362  ·  view source on GitHub ↗

Determine if the type is assignable via Java boxing/unboxing rules.

(
		Class lhsType, Class rhsType )

Source from the content-addressed store, hash-verified

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

Callers 2

isSignatureAssignableMethod · 0.95
isJavaAssignableMethod · 0.95

Calls 3

isJavaBaseAssignableMethod · 0.95
getMethod · 0.65
isPrimitiveMethod · 0.45

Tested by

no test coverage detected