public static ArtMethod hook(Constructor<?> originalMethod, Method replacementMethod) { Assertions.argumentNotNull(originalMethod, "originalMethod"); Assertions.argumentNotNull(replacementMethod, "replacementMethod"); if (replacementMethod.getReturnType() != Void.TYPE) throw new IllegalArgumentException("return types of replacementMethod has to be 'void'"); return hook(ArtMethod.of(originalMethod), ArtMethod.of(replacementMethod)); }
public static ArtMethod hook(Method originalMethod, Method replacementMethod) { Assertions.argumentNotNull(originalMethod, "originalMethod"); Assertions.argumentNotNull(replacementMethod, "replacementMethod"); if (originalMethod == replacementMethod || originalMethod.equals(replacementMethod)) throw new IllegalArgumentException("originalMethod and replacementMethod can't be the same"); if (!replacementMethod.getReturnType().isAssignableFrom(originalMethod.getReturnType())) throw new IllegalArgumentException( "return types of originalMethod and replacementMethod do not match"); return hook(ArtMethod.of(originalMethod), ArtMethod.of(replacementMethod)); }
public static void hook(Class clazz) { for (Method method : Assertions.argumentNotNull(clazz, "clazz").getDeclaredMethods()) { if (method.isAnnotationPresent(Hook.class)) { try { hook(method); } catch (RuntimeException e) { logw(e); } } } }