private void setRunning(MessageQueue mq) { Reflection.field("running").ofType(AtomicBoolean.class).in(mq).get().set(true); }
public static JobHolder createNewJobHolder(Params params, Timer timer) { long delay = getDelayMsField(params).get(); long deadline = getDeadlineMsField(params).get(); boolean cancelOnDeadline = Boolean.TRUE.equals(getCancelOnDeadlineDeadlineField(params).get()); DummyJob job = new DummyJob(params); //noinspection WrongConstant return new JobHolder.Builder() .priority(params.getPriority()) .groupId(params.getGroupId()) .job(job) .id(job.getId()) .persistent(params.isPersistent()) .tags(job.getTags()) .createdNs(timer.nanoTime()) .deadline(deadline > 0 ? timer.nanoTime() + deadline * JobManager.NS_PER_MS : Params.FOREVER, cancelOnDeadline) .delayUntilNs(delay > 0 ? timer.nanoTime() + delay * JobManager.NS_PER_MS : JobManager.NOT_DELAYED_JOB_DELAY) .requiredNetworkType(getNetworkTypeField(params).get()) .runningSessionId(JobManager.NOT_RUNNING_SESSION_ID).build(); }
/** * Returns the value of the field managed by this class. * * @return the value of the field managed by this class. * @throws ReflectionError if the value of the field cannot be retrieved. */ public T get() { return Invoker.<T> get(field, accessible, target); }
static Object getNestedField(String fieldName, Object target) { Field field = lookupInClassHierarchy(fieldName, typeOf(target)); return get(field, field.isAccessible(), target); }
@Provides public WebApplication webApp( @NotNull GuiceContainer guiceContainer ) { WebApplication copy = webApplicationReference; if ( copy == null ) { WebComponent component = Reflection.field( "webComponent" ).ofType( WebComponent.class ).in( guiceContainer ).get(); copy = Reflection.field( "application" ).ofType( WebApplication.class ).in( component ).get(); webApplicationReference = copy; } return copy; }
@Override @Nullable public Component focusOwner() { return field("focusOwner").ofType(Component.class).in(KeyboardFocusManager.class).get(); } }
@Nullable protected Object resolveId( @Nonnull Object object ) { try { return Reflection.field( "id" ).ofType( Long.class ).in( object ).get(); } catch ( ReflectionError ignore ) { ignore.printStackTrace(); } return null; }
@Nullable protected Object resolveId( @NotNull Object object ) { try { return Reflection.field( "id" ).ofType( Long.class ).in( object ).get(); } catch ( ReflectionError ignore ) { ignore.printStackTrace(); } return null; }
public JAnnotationFieldReference( @Nonnull JFieldVar ns ) { this.ns = ns; this.owner = Reflection.field( FIELD_OWNER ).ofType( JDefinedClass.class ).in( ns ).get(); }
@Nullable protected Object resolveId( @NotNull Object object ) { try { return Reflection.field( "id" ).ofType( Long.class ).in( object ).get(); } catch ( ReflectionError ignore ) { ignore.printStackTrace(); } return null; }
@Nullable protected Object resolveId( @NotNull Object object ) { try { return Reflection.field( "id" ).ofType( Long.class ).in( object ).get(); } catch ( ReflectionError ignore ) { ignore.printStackTrace(); } return null; }
@RunsInCurrentThread @Nonnull private static Container dockFor(final @Nonnull JToolBar toolBar) { try { return checkNotNull(field("dockingSource").ofType(Container.class).in(toolBar.getUI()).get()); } catch (RuntimeException e) { throw actionFailure("Unabled to determine dock for JToolBar"); } }
T target = get(); DecoratorInvocationHandler<T> handler = new PostDecorator<T>(target, decorator); @SuppressWarnings("unchecked")
private static int modifiersFrom(@Nonnull String s) { if ("NO_MASK".equals(s)) { return NO_MASK; } try { Integer modifiers = field(s).ofType(int.class).in(InputEvent.class).get(); return checkNotNull(modifiers); } catch (ReflectionError e) { throw new ParsingException(concat("Unable to retrieve modifiers from text ", quote(s)), e.getCause()); } } }
T target = get(); DecoratorInvocationHandler<T> handler = new PreDecorator<T>(target, decorator); @SuppressWarnings("unchecked")
private boolean isCanceled() { try { int state = Preconditions.checkNotNull(field("state").ofType(int.class).in(task).get()); return state == CANCELED; } catch (RuntimeException e) { handleException(e); } return false; }
private static int keyCodeFrom(@Nonnull String s) { try { Integer keyCode = field("VK_" + s).ofType(int.class).in(KeyEvent.class).get(); return checkNotNull(keyCode); } catch (ReflectionError e) { throw new ParsingException(concat("Unable to retrieve key code from text ", quote(s)), e.getCause()); } }
private float[] getCurrentPosition(final ColorPicker colorPicker) { final float mAngle = field("mAngle") .ofType(float.class) .in(colorPicker) .get(); return getPosition(colorPicker, mAngle); }
@Test public void shouldUnregisterLifecycleCallbacksOnActivityDestroyed() throws Exception { speakerbox.getCallbacks().onActivityDestroyed(activity); ArrayList callbackList = field("mActivityLifecycleCallbacks") .ofType(ArrayList.class) .in(application) .get(); assertThat(callbackList).isEmpty(); }
private float[] getPosition(final ColorPicker colorPicker, final float angle) { final float mTranslationOffset = field("mTranslationOffset") .ofType(float.class) .in(colorPicker) .get(); final float[] calculatedPointerPosition = method("calculatePointerPosition") .withReturnType(float[].class) .withParameterTypes(float.class) .in(colorPicker) .invoke(angle); final int[] locationOnScreen = new int[2]; colorPicker.getLocationOnScreen(locationOnScreen); calculatedPointerPosition[0] += mTranslationOffset + locationOnScreen[0]; calculatedPointerPosition[1] += mTranslationOffset + locationOnScreen[1]; return calculatedPointerPosition; } }