示例#1
0
  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));
  }
示例#2
0
  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));
  }
示例#3
0
 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);
       }
     }
   }
 }