private static org.fest.reflect.field.Invoker<Integer> getPriorityField(Params params) { return Reflection.field("priority").ofType(int.class).in(params); }
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; } }
@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; } }
type = (Annotation) constructor().withParameterTypes(JCas.class).in(typeClass).newInstance(jcas); 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);
public Object createRunner( @Nonnull Class<?> runnerType ) { return Reflection.constructor().in( runnerType ).newInstance(); }
@Test public void callTimedStaticMethodsOnce() { // Call the timed methods and assert they've all been timed once TimedStaticMethodWithVisibilityModifiers.publicTimedStaticMethod(); TimedStaticMethodWithVisibilityModifiers.protectedTimedStaticMethod(); TimedStaticMethodWithVisibilityModifiers.packagePrivateTimedStaticMethod(); staticMethod("privateTimedStaticMethod").in(TimedStaticMethodWithVisibilityModifiers.class).invoke(); 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()))); assertThat("Timer counts are incorrect", registry.getTimers().values(), everyItem(Matchers.<Timer>hasProperty("count", equalTo(1L)))); } }
public void run( @Nonnull GeneratorConfiguration configuration, @Nonnull Object runner ) { Reflection.method( GENERATE_METHOD_NAME ).withParameterTypes( GeneratorConfiguration.class ).in( runner ).invoke( configuration ); }
@VisibleForTesting static void installAWTExceptionHandler(@Nonnull Class<?> exceptionHandlerType, SystemPropertyWriter writer) { try { constructor().in(exceptionHandlerType).info(); } catch (RuntimeException e) { throw new IllegalArgumentException("The exception handler type should have a default constructor"); } writer.updateSystemProperty("sun.awt.exception.handler", exceptionHandlerType.getName()); }
private static org.fest.reflect.field.Invoker<Long> getDelayUntilNsField(JobHolder jobHolder) { return Reflection.field("delayUntilNs").ofType(long.class).in(jobHolder); }
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; } } }
public void setExternalParserForPartOfDocument(int id, String externalParserClassName) throws CollectionException { if (externalParserClassName != null) { Class<?> externalParserClass; try { externalParserClass = Class.forName(externalParserClassName.trim()); } catch (ClassNotFoundException e) { LOGGER.error("ExternalParser " + externalParserClassName + " for document text part " + id + " returns a ClassNotFoundException", e); throw new CollectionException(e); } DocumentTextPartParser parser = (DocumentTextPartParser) constructor().in(externalParserClass).newInstance(); this.docTextData.get(id).setParser(parser); } }
private static org.fest.reflect.field.Invoker<Integer> getNetworkTypeField(Params params) { return Reflection.field("requiredNetworkType").ofType(int.class).in(params); }
private static String classNameFromVmExitErrorTest(Test test) { try { return method("getClassName").withReturnType(String.class).in(test).invoke(); } catch (Exception e) { return UNKNOWN; } }
/** * Overrides the parser and sets an external parser * * @param trim a String containing the full qualified Classname of the parser * @throws CollectionException */ public void setParser(String trim) throws CollectionException { if (trim != null) { externalParser = true; Class<?> externalParserClass; try { externalParserClass = Class.forName(trim); } catch (ClassNotFoundException e) { LOGGER.error("ExternalParser " + trim + " for type or feature " + fullClassName + " returns a ClassNotFoundException", e); throw new CollectionException(e); } this.parser = (TypeParser) constructor().in(externalParserClass).newInstance(); }else{ this.parser = null; } }
private static org.fest.reflect.field.Invoker<Long> getDeadlineMsField(Params params) { return Reflection.field("deadlineMs").ofType(long.class).in(params); }
private static String classNameFromVmExitErrorTest(Test test) { try { return method("getClassName").withReturnType(String.class).in(test).invoke(); } catch (Exception e) { return UNKNOWN; } }
private static org.fest.reflect.field.Invoker<Long> getDelayMsField(Params params) { return Reflection.field("delayMs").ofType(long.class).in(params); }
/** * 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 }); } }
private static org.fest.reflect.field.Invoker<Boolean> getCancelOnDeadlineDeadlineField(Params params) { return Reflection.field("cancelOnDeadline").ofType(Boolean.class).in(params); }
@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; }