Пример #1
0
 public MethodVisitor visitMethod(int access,
                                  String name,
                                  String desc,
                                  String signature,
                                  String[] exceptions) {
     return (filter.accept(access, name, desc, signature, exceptions) ? pass : direct).visitMethod(access, name, desc, signature, exceptions);
 }
Пример #2
0
 protected boolean _isIncludableMethod(Method m, MethodFilter filter) {
   if (filter != null && !filter.includeMethod(m)) {
     return false;
   }
   /* 07-Apr-2009, tatu: Looks like generics can introduce hidden
    *   bridge and/or synthetic methods. I don't think we want to
    *   consider those...
    */
   if (m.isSynthetic() || m.isBridge()) {
     return false;
   }
   return true;
 }
Пример #3
0
  public Collection<DynamicObject> filterMethods(
      Map<String, InternalMethod> allMethods, MethodFilter filter) {
    final Map<String, InternalMethod> methods =
        ModuleOperations.withoutUndefinedMethods(allMethods);

    final Set<DynamicObject> filtered = new HashSet<>();
    for (InternalMethod method : methods.values()) {
      if (filter.filter(method)) {
        filtered.add(getContext().getSymbolTable().getSymbol(method.getName()));
      }
    }

    return filtered;
  }
Пример #4
0
  /**
   * Perform the given callback operation on all matching methods of the given class and
   * superclasses (or given interface and super-interfaces).
   *
   * <p>The same named method occurring on subclass and superclass will appear twice, unless
   * excluded by the specified {@link MethodFilter}.
   *
   * @param clazz class to start looking at
   * @param mc the callback to invoke for each method
   * @param mf the filter that determines the methods to apply the callback to
   */
  public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf)
      throws IllegalArgumentException {

    // Keep backing up the inheritance hierarchy.
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
      if (mf != null && !mf.matches(method)) {
        continue;
      }
      try {
        mc.doWith(method);
      } catch (IllegalAccessException ex) {
        throw new IllegalStateException(
            "Shouldn't be illegal to access method '" + method.getName() + "': " + ex);
      }
    }
    if (clazz.getSuperclass() != null) {
      doWithMethods(clazz.getSuperclass(), mc, mf);
    } else if (clazz.isInterface()) {
      for (Class<?> superIfc : clazz.getInterfaces()) {
        doWithMethods(superIfc, mc, mf);
      }
    }
  }