程序包 infra.aop

接口 MethodMatcher

所有已知子接口:
IntroductionAwareMethodMatcher
所有已知实现类:
AbstractAspectJAdvice.AdviceExcludingMethodMatcher, AbstractRegexpMethodPointcut, AnnotationMethodMatcher, AspectJExpressionPointcut, ControlFlowPointcut, DynamicMethodMatcher, DynamicMethodMatcherPointcut, InstantiationModelAwarePointcutAdvisorImpl.PerTargetInstantiationModelPointcut, JdkRegexpMethodPointcut, MethodMatcher.ClassFilterAwareUnionIntroductionAwareMethodMatcher, MethodMatcher.ClassFilterAwareUnionMethodMatcher, MethodMatcher.IntersectionIntroductionAwareMethodMatcher, MethodMatcher.IntersectionMethodMatcher, MethodMatcher.NegateMethodMatcher, MethodMatcher.UnionIntroductionAwareMethodMatcher, MethodMatcher.UnionMethodMatcher, NameMatchMethodPointcut, Pointcut.GetterPointcut, Pointcut.SetterPointcut, StaticMethodMatcher, StaticMethodMatcherPointcut, StaticMethodMatcherPointcutAdvisor, TrueMethodMatcher

public interface MethodMatcher
Part of a Pointcut: Checks whether the target method is eligible for advice.

A MethodMatcher may be evaluated statically or at runtime (dynamically). Static matching involves method and (possibly) method attributes. Dynamic matching also makes arguments for a particular call available, and any effects of running previous advice applying to the join-point.

If an implementation returns false from its isRuntime() method, evaluation can be performed statically, and the result will be the same for all invocations of this method, whatever their arguments. This means that if the isRuntime() method returns false, the 1-arg matches(MethodInvocation) method will never be invoked.

If an implementation returns true from its 2-arg matches(java.lang.reflect.Method, Class) method and its isRuntime() method returns true, the 1-arg matches(MethodInvocation) method will be invoked immediately before each potential execution of the related advice, to decide whether the advice should run. All previous advice, such as earlier interceptors in an interceptor chain, will have run, so any state changes they have produced in parameters or ThreadLocal state will be available at the time of evaluation.

WARNING: Concrete implementations of this interface must provide proper implementations of Object.equals(Object), Object.hashCode(), and Object.toString() in order to allow the matcher to be used in caching scenarios — for example, in proxies generated by CGLIB. As of 4.0, the toString() implementation must generate a unique string representation that aligns with the logic used to implement equals(). See concrete implementations of this interface within the framework for examples.

从以下版本开始:
3.0
作者:
Rod Johnson, TODAY 2019-10-20 22:43
另请参阅:
  • 字段详细资料

    • TRUE

      static final MethodMatcher TRUE
      Canonical instance that matches all methods.
  • 方法详细资料

    • matches

      boolean matches(Method method, Class<?> targetClass)
      Checking whether the given method matches.
      参数:
      method - the candidate method
      targetClass - the target class
      返回:
      whether or not this method matches on application startup.
    • isRuntime

      boolean isRuntime()
      Is this MethodMatcher dynamic, that is, must a final call be made on the matches(MethodInvocation) method at runtime even if the 2-arg matches method returns true?

      Can be invoked when an AOP proxy is created, and need not be invoked again before each method invocation,

      返回:
      whether or not a runtime match via the 1-arg matches(MethodInvocation) method is required if static matching passed
    • matches

      boolean matches(MethodInvocation invocation)
      Check whether there a runtime (dynamic) match for this method, which must have matched statically.

      This method is invoked only if the 2-arg matches method returns true for the given method and target class, and if the isRuntime() method returns true. Invoked immediately before potential running of the advice, after any advice earlier in the advice chain has run.

      参数:
      invocation - runtime invocation contains the candidate method and target class, arguments to the method
      返回:
      whether there's a runtime match
      另请参阅:
    • union

      static MethodMatcher union(MethodMatcher mm1, MethodMatcher mm2)
      Match all methods that either (or both) of the given MethodMatchers matches.
      参数:
      mm1 - the first MethodMatcher
      mm2 - the second MethodMatcher
      返回:
      a distinct MethodMatcher that matches all methods that either of the given MethodMatchers matches
    • union

      static MethodMatcher union(MethodMatcher mm1, ClassFilter cf1, MethodMatcher mm2, ClassFilter cf2)
      Match all methods that either (or both) of the given MethodMatchers matches.
      参数:
      mm1 - the first MethodMatcher
      cf1 - the corresponding ClassFilter for the first MethodMatcher
      mm2 - the second MethodMatcher
      cf2 - the corresponding ClassFilter for the second MethodMatcher
      返回:
      a distinct MethodMatcher that matches all methods that either of the given MethodMatchers matches
    • intersection

      static MethodMatcher intersection(MethodMatcher mm1, MethodMatcher mm2)
      Match all methods that both of the given MethodMatchers match.
      参数:
      mm1 - the first MethodMatcher
      mm2 - the second MethodMatcher
      返回:
      a distinct MethodMatcher that matches all methods that both of the given MethodMatchers match
    • negate

      static MethodMatcher negate(MethodMatcher methodMatcher)
      Return a method matcher that represents the logical negation of the specified matcher instance.
      参数:
      methodMatcher - the MethodMatcher to negate
      返回:
      a matcher that represents the logical negation of the specified matcher
      从以下版本开始:
      4.0
    • matches

      static boolean matches(MethodMatcher mm, Method method, Class<?> targetClass, boolean hasIntroductions)
      Apply the given MethodMatcher to the given Method, supporting an IntroductionAwareMethodMatcher (if applicable).
      参数:
      mm - the MethodMatcher to apply (may be an IntroductionAwareMethodMatcher)
      method - the candidate method
      targetClass - the target class
      hasIntroductions - true if the object on whose behalf we are asking is the subject on one or more introductions; false otherwise
      返回:
      whether or not this method matches statically