use of org.robolectric.util.ReflectionHelpers.ClassParameter in project robolectric by robolectric.
the class AndroidInterceptorsIntegrationTest method invokeDynamic.
@SuppressWarnings({ "unchecked", "TypeParameterUnusedInFormals" })
private static <T> T invokeDynamic(Class<?> cls, String methodName, Class<?> returnType, ClassParameter<?>... params) throws Throwable {
MethodType methodType = MethodType.methodType(returnType, Arrays.stream(params).map(param -> param.clazz).toArray(Class[]::new));
CallSite callsite = InvokeDynamicSupport.bootstrapIntrinsic(MethodHandles.lookup(), methodName, methodType, cls.getName());
return (T) callsite.dynamicInvoker().invokeWithArguments(Arrays.stream(params).map(param -> param.val).collect(Collectors.toList()));
}
use of org.robolectric.util.ReflectionHelpers.ClassParameter in project robolectric by robolectric.
the class ShadowSensorManager method createSensorEvent.
/**
* Creates a {@link SensorEvent} for the given {@link Sensor} type with the given value array
* size, which the caller should set based on the type of sensor which is being emulated.
*
* <p>Callers can then specify individual values for the event. For example, for a proximity event
* a caller may wish to specify the distance value:
*
* <pre>{@code
* event.values[0] = distance;
* }</pre>
*
* <p>See {@link SensorEvent#values} for more information about values.
*/
public static SensorEvent createSensorEvent(int valueArraySize, int sensorType) {
checkArgument(valueArraySize > 0);
ClassParameter<Integer> valueArraySizeParam = new ClassParameter<>(int.class, valueArraySize);
SensorEvent sensorEvent = ReflectionHelpers.callConstructor(SensorEvent.class, valueArraySizeParam);
sensorEvent.sensor = ShadowSensor.newInstance(sensorType);
return sensorEvent;
}
Aggregations