package com.elab.redis.interceptor;

import com.elab.redis.utils.CacheParseUtil;
import org.springframework.aop.support.StaticMethodMatcherPointcut;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author ： liukx
 * @time ： 2020/7/9 - 20:02
 */
public class LockCacheAttributeSourcePointcut extends StaticMethodMatcherPointcut implements Serializable {

    private Set<Class<? extends Annotation>> cacheOperationAnnotations = new LinkedHashSet<>(8);

    public void addAnnotations(Class<? extends Annotation> annotation) {
        cacheOperationAnnotations.add(annotation);
    }

    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        if (CacheParseUtil.isContainAnnotations(cacheOperationAnnotations, method)) {
            return true;
        }
        return false;
    }
}
