@Test public void testOnlyIf() throws IOException { final Hack.HackedMethod1<Simple, Void, IOException, Unchecked, Unchecked, Integer> constructor = Hack.onlyIf(true).into(Simple.class).constructor().throwing(IOException.class).withParam(int.class); assertNotNull(constructor); final Simple simple = constructor.invoke(0).statically(); assertNotNull(simple); final Hack.HackedMethod1<Simple, Void, IOException, Unchecked, Unchecked, Integer> fallback_constructor = Hack.onlyIf(false).into(Simple.class).constructor().throwing(IOException.class).withParam(int.class); assertNotNull(fallback_constructor); final Simple value = fallback_constructor.invoke(0).statically(); assertNull(value); final Hack.HackedMethod1<Integer, Simple, IOException, Unchecked, Unchecked, Void> foo_wrong = Hack.into(Simple.class).method("foo").throwing(IOException.class).returning(int.class).withParam(Void.class); assertNull(foo_wrong); final Hack.HackedField<Simple, Integer> field = Hack.onlyIf(true).into(Simple.class).field("mIntField").ofType(int.class); assertNotNull(field); field.set(simple, 3); assertEquals(3, (int) field.get(simple)); final Hack.HackedField<Simple, Integer> absent_field = Hack.onlyIf(false).into(Simple.class).field("mIntField").ofType(int.class); assertNull(absent_field); final Hack.HackedField<Simple, Integer> fallback_field = Hack.onlyIf(false).into(Simple.class).field("mIntField").fallbackTo(-1); assertNotNull(fallback_field); fallback_field.set(simple, 3); assertEquals(-1, (int) fallback_field.get(simple)); }
@SuppressWarnings("unchecked") public static <C> Hack.HackedClass<C> onlyIf(final boolean condition, final Hacking<Hack.HackedClass<C>> hacking) { if (condition) return hacking.hack(); return (Hack.HackedClass<C>) FALLBACK; }
Hack { @SuppressWarnings("unchecked") public static <C> Hack.HackedClass<C> onlyIf(final boolean condition, final Hacking<Hack.HackedClass<C>> hacking) { if (condition) return hacking.hack(); return (Hack.HackedClass<C>) FALLBACK; } }
Hack { @SuppressWarnings("unchecked") public static <C> Hack.HackedClass<C> onlyIf(final boolean condition, final Hacking<Hack.HackedClass<C>> hacking) { if (condition) return hacking.hack(); return (Hack.HackedClass<C>) FALLBACK; } private  Hack(); }
Hack { @SuppressWarnings("unchecked") public static <C> Hack.HackedClass<C> onlyIf(final boolean condition, final Hacking<Hack.HackedClass<C>> hacking) { if (condition) return hacking.hack(); return (Hack.HackedClass<C>) FALLBACK; } private  Hack(); static HackedObject into(final Object source); static R mirrorStaticMethod(final String tag, final R fallback, final Object... args); static void verifyAllMirrorsIn(final Class<?> enclosing); static HackedClass<T> into(final @NonNull Class<T> clazz); static HackedClass<T> into(final String class_name); @SuppressWarnings("unchecked") static Hack.HackedClass<C> onlyIf(final boolean condition, final Hacking<Hack.HackedClass<C>> hacking); static ConditionalHack onlyIf(final boolean condition); static AssertionFailureHandler setAssertionFailureHandler(final @Nullable AssertionFailureHandler handler); }
Hack { @SuppressWarnings("unchecked") public static <C> Hack.HackedClass<C> onlyIf(final boolean condition, final Hacking<Hack.HackedClass<C>> hacking) { if (condition) return hacking.hack(); return (Hack.HackedClass<C>) FALLBACK; } private  Hack(); static HackedObject into(final Object source); static R mirrorStaticMethod(final String tag, final R fallback, final Object... args); static void verifyAllMirrorsIn(final Class<?> enclosing); static HackedClass<T> into(final @NonNull Class<T> clazz); static HackedClass<T> into(final String class_name); @SuppressWarnings("unchecked") static Hack.HackedClass<C> onlyIf(final boolean condition, final Hacking<Hack.HackedClass<C>> hacking); static ConditionalHack onlyIf(final boolean condition); static AssertionFailureHandler setAssertionFailureHandler(final @Nullable AssertionFailureHandler handler); static Class<?> ANY_TYPE; }