/** * legacy ImageJ directly refers to compiler that may not be loaded (since it * may not be on class path). Thus have a safe accessor that does not cause * runtime exceptions when user misconfigures their java tools. Instead we * should avoid issues here and we should safely report the issue to the user * if they try to run the Compile/Run plugin. */ private Field getCompilerField(String fieldName) { try { return Types.field(ij.plugin.Compiler.class, fieldName); } catch (Throwable t) { return null; } }
/** Tests {@link Types#fieldType(Field, Class)}. */ @Test public void testFieldType() { final Field field = Types.field(Thing.class, "thing"); // T final Type tType = Types.fieldType(field, Thing.class); assertEquals("capture of ?", tType.toString()); // N extends Number final Type nType = Types.fieldType(field, NumberThing.class); assertEquals("capture of ?", nType.toString()); // Integer final Type iType = Types.fieldType(field, IntegerThing.class); assertSame(Integer.class, iType); }
/** @deprecated Use {@link Types#field} instead. */ @Deprecated public static Field getField(final Class<?> c, final String fieldName) { try { return Types.field(c, fieldName); } catch (final IllegalArgumentException e) { return null; } }
@Test public void testCanConvertToGenericCollection() { final CastingConverter cc = new CastingConverter(); final Field destField = Types.field(getClass(), "collection"); final Type destType = Types.fieldType(destField, getClass()); assertTrue(cc.canConvert(ArrayList.class, destType)); }
/** @deprecated Use {@link Types#field} instead. */ @Deprecated public static Field getField(final Class<?> c, final String fieldName) { try { return Types.field(c, fieldName); } catch (final IllegalArgumentException e) { return null; } }
/** Tests {@link Types#raws}. */ @Test public void testRaws() { final Field field = Types.field(Thing.class, "thing"); // Object assertAllTheSame(Types.raws(Types.fieldType(field, Thing.class)), Object.class); // N extends Number assertAllTheSame(Types.raws(Types.fieldType(field, NumberThing.class)), Number.class); // Integer assertAllTheSame(Types.raws(Types.fieldType(field, IntegerThing.class)), Integer.class); // Serializable & Cloneable assertAllTheSame(Types.raws(Types.fieldType(field, ComplexThing.class)), Serializable.class, Cloneable.class); }
private Roi getIJ1DefaultRoi() { final Field field = Types.field(ij.plugin.OverlayCommands.class, "defaultRoi"); final Object obj = ClassUtils.getValue(field, null); return (Roi) obj; }
private String getIJ1WandMode() { final Field field = Types.field(WandToolOptions.class, "mode"); return (String) ClassUtils.getValue(field, null); }
private void setIJ1DefaultStrokeWidth(final double width) { final Field field = Types.field(RectToolOptions.class, "defaultStrokeWidth"); ClassUtils.setValue(field, null, width); }
private double getIJ1DefaultStrokeWidth() { final Field field = Types.field(RectToolOptions.class, "defaultStrokeWidth"); return (Double) ClassUtils.getValue(field, null); }
/** @deprecated Use {@link Types#field} instead. */ @Deprecated public static Field getField(final String className, final String fieldName) { try { return Types.field(Types.load(className), fieldName); } catch (final IllegalArgumentException e) { return null; } }
/** @deprecated Use {@link Types#field} instead. */ @Deprecated public static Field getField(final String className, final String fieldName) { try { return Types.field(Types.load(className), fieldName); } catch (final IllegalArgumentException e) { return null; } }
private void setIJ1WandMode(final String mode) { final Field field = Types.field(WandToolOptions.class, "mode"); ClassUtils.setValue(field, null, mode); }
private double getIJ1WandTolerance() { final Field field = Types.field(WandToolOptions.class, "tolerance"); return (Double) ClassUtils.getValue(field, null); }
private void setIJ1WandTolerance(final double tol) { final Field field = Types.field(WandToolOptions.class, "tolerance"); ClassUtils.setValue(field, null, tol); }
/** Convenience method to get the {@link Type} of a field. */ private Type type(final Class<?> c, final String fieldName) { return Types.field(c, fieldName).getGenericType(); }
return field(c.getSuperclass(), name);
/** * Convenience method to automatically get a field from a field name and call * {@link ClassUtils#setValue(java.lang.reflect.Field, Object, Object)}. */ private void setFieldValue(final Object o, final String fieldName, final Object value) { ClassUtils.setValue(Types.field(o.getClass(), fieldName), o, value); }
/** * Convenience method to automatically get a field from a field name and call * {@link ClassUtils#setValue(java.lang.reflect.Field, Object, Object)}. */ private void setFieldValue(final Object o, final String fieldName, final Object value) { ClassUtils.setValue(Types.field(o.getClass(), fieldName), o, value); }
/** Tests {@link Types#field}. */ @Test public void testField() { final Field field = Types.field(Thing.class, "thing"); assertEquals("thing", field.getName()); assertSame(Object.class, field.getType()); assertTrue(field.getGenericType() instanceof TypeVariable); assertEquals("T", ((TypeVariable<?>) field.getGenericType()).getName()); }