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 CacheAttributeSourcePointcut extends StaticMethodMatcherPointcut implements Serializable {

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

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

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