Example usage for org.springframework.aop Pointcut getMethodMatcher

List of usage examples for org.springframework.aop Pointcut getMethodMatcher

Introduction

In this page you can find the example usage for org.springframework.aop Pointcut getMethodMatcher.

Prototype

MethodMatcher getMethodMatcher();

Source Link

Document

Return the MethodMatcher for this pointcut.

Usage

From source file:org.springframework.aop.support.AopUtils.java

/**
 * Can the given pointcut apply at all on the given class?
 * This is an important test as it can be used to optimize
 * out a pointcut for a class.//www . j a  v  a  2 s  .  c  o m
 * @param pc pc static or dynamic pointcut to check
 * @param targetClass class we're testing
 * @return whether the pointcut can apply on any method
 */
public static boolean canApply(Pointcut pc, Class targetClass) {
    if (!pc.getClassFilter().matches(targetClass)) {
        return false;
    }

    Set classes = ClassUtils.getAllInterfacesForClassAsSet(targetClass);
    classes.add(targetClass);
    for (Iterator it = classes.iterator(); it.hasNext();) {
        Class clazz = (Class) it.next();
        Method[] methods = clazz.getMethods();
        for (int j = 0; j < methods.length; j++) {
            if (pc.getMethodMatcher().matches(methods[j], targetClass)) {
                return true;
            }
        }
    }

    return false;
}