@Nonnull public static JAnnotationUse param( @Nonnull JAnnotationUse annotation, @Nonnull String key, @Nonnull JFieldVar ref ) { Reflection.method( METHOD_ADD_VALUE ).withParameterTypes( String.class, JAnnotationValue.class ) .in( annotation ).invoke( key, new JAnnotationFieldReference( ref ) ); return annotation; } }
public void run( @Nonnull GeneratorConfiguration configuration, @Nonnull Object runner ) { Reflection.method( GENERATE_METHOD_NAME ).withParameterTypes( GeneratorConfiguration.class ).in( runner ).invoke( configuration ); }
boolean isNativeDragActive() { try { Class<?> type = Class.forName("sun.awt.dnd.SunDragSourceContextPeer"); try { method("checkDragDropInProgress").in(type).invoke(); return false; } catch (ReflectionError e) { Throwable cause = e.getCause(); if (!(cause instanceof InvocationTargetException)) { return false; } return (((InvocationTargetException) cause).getTargetException() instanceof InvalidDnDOperationException); } } catch (Exception ignored) { return false; } } }
private static String classNameFromVmExitErrorTest(Test test) { try { return method("getClassName").withReturnType(String.class).in(test).invoke(); } catch (Exception e) { return UNKNOWN; } }
private static String classNameFromVmExitErrorTest(Test test) { try { return method("getClassName").withReturnType(String.class).in(test).invoke(); } catch (Exception e) { return UNKNOWN; } }
/** * Starts the application. * * @throws org.fest.reflect.exception.ReflectionError if the "main" method cannot be invoked. */ public void start() { method("main").withParameterTypes(String[].class).in(applicationType).invoke(new Object[] { args }); } }
@Nullable private static RepaintManager currentRepaintManager() { try { Object repaintManager = method("appContextGet").withReturnType(Object.class).withParameterTypes(Object.class) .in(SwingUtilities.class).invoke(RepaintManager.class); if (repaintManager instanceof RepaintManager) { return (RepaintManager) repaintManager; } } catch (RuntimeException e) { return null; } return null; }
@RunsInCurrentThread static void toggleExpandState(final @Nonnull JTree tree, final @Nonnull Point pathLocation) { TreePath path = tree.getPathForLocation(pathLocation.x, pathLocation.y); TreeUI treeUI = tree.getUI(); assertThat(treeUI).isInstanceOf(BasicTreeUI.class); method("toggleExpandState").withParameterTypes(TreePath.class).in(treeUI).invoke(path); }
@RunsInCurrentThread protected boolean isResizable(@Nonnull Container c) { try { Boolean resizable = method("isResizable").withReturnType(boolean.class).in(c).invoke(); return checkNotNull(resizable); } catch (ReflectionError e) { return false; } }
@Test public void callGaugesAfterSetterCalls() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Gauges are not registered correctly", registry.getGauges().keySet(), is(equalTo(absoluteMetricNames()))); long value = Math.round(Math.random() * Long.MAX_VALUE); // Call the setter methods instance.setPublicGauge(value); instance.setPackagePrivateGauge(value); instance.setProtectedGauge(value); method("setPrivateGauge").withParameterTypes(long.class).in(instance).invoke(value); // And assert the gauges are up-to-date assertThat("Gauge values are incorrect", registry.getGauges().values(), everyItem(Matchers.<Gauge>hasProperty("value", equalTo(value)))); } }
@Test public void callTimedMethodsOnce() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames()))); // Call the timed methods and assert they've all been timed once instance.publicTimedMethod(); instance.protectedTimedMethod(); instance.packagePrivateTimedMethod(); method("privateTimedMethod").in(instance).invoke(); assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(1L)))); } }
@Test public void callTimedMethodsOnce() { assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME)); MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME); assertThat("Timers are not registered correctly", registry.getTimers().keySet(), is(equalTo(absoluteMetricNames()))); // Call the timed methods and assert they've all been timed once instance.publicTimedMethod(); instance.protectedTimedMethod(); instance.packagePrivateTimedMethod(); method("privateTimedMethod").in(instance).invoke(); assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(1L)))); } }
method(methodName).withParameterTypes(featureClass).in(type) .invoke(parseValueStringToValueType(concreteFeature.getValue(), concreteFeature.getFullClassName())); } else if (concreteFeature.getFullClassName().equals("String") || concreteFeature.getFullClassName().equals("java.lang.String")) { featureClass = Class.forName(concreteFeature.getFullClassName()); method(methodName).withParameterTypes(featureClass).in(type).invoke(concreteFeature.getValue()); } else { String featureClassName = concreteFeature.getFullClassName(); featureClass = Class.forName(featureClassName); TOP top = concreteFeature.getTypeTemplate().getParser().getTypeBuilder().buildType(concreteFeature, jcas); method(methodName).withParameterTypes(featureClass).in(type).invoke(top);
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; } }