/**
 * Copyright (c) 2015-2017, Michael Yang 杨福海 (fuhai999@gmail.com).
 * <p>
 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.jboot.aop.interceptor.cache;

import com.jfinal.template.Engine;
import io.jboot.utils.StringUtils;

import javax.inject.Named;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class Kits {

    static final Engine ENGINE = new Engine("JbootCacheRender");

    /**
     * use jfinal engine render text
     *
     * @param template
     * @param method
     * @param arguments
     * @return
     */
    static String engineRender(String template, Method method, Object[] arguments) {

        Annotation[][] annotationss = method.getParameterAnnotations();
        Map<String, Object> datas = new HashMap();
        for (int i = 0; i < annotationss.length; i++) {
            for (int j = 0; j < annotationss[i].length; j++) {
                Annotation annotation = annotationss[i][j];
                if (annotation.annotationType() == Named.class) {
                    Named named = (Named) annotation;
                    datas.put(named.value(), arguments[i]);
                } else if (annotation.annotationType() == com.google.inject.name.Named.class) {
                    com.google.inject.name.Named named = (com.google.inject.name.Named) annotation;
                    datas.put(named.value(), arguments[i]);
                }
            }
        }

        return ENGINE.getTemplateByString(template).renderToString(datas);
    }

    static String buildCacheKey(String key, Class clazz, Method method, Object[] arguments) {
        if (StringUtils.isBlank(key)) {
            return String.format("%s#%s", clazz.getName(), method.getName());
        }

        if (!key.contains("#(") || !key.contains(")")) {
            return key;
        }

        return Kits.engineRender(key, method, arguments);
    }
}

@@ -870,16 +870,52 @@
 Method;%0A
+import java.lang.reflect.Parameter;%0A
 import j
@@ -932,16 +932,16 @@
 ashMap;%0A
-
 import j
@@ -1267,24 +1267,441 @@
 guments) %7B%0A%0A
+        Map%3CString, Object%3E datas = new HashMap();%0A        int x = 0;%0A        /**%0A         * %E5%9C%A8java8%E4%B8%8B%EF%BC%8C%E9%80%9A%E8%BF%87%E6%B7%BB%E5%8A%A0 -parameters %E8%BF%9B%E8%A1%8C%E7%BC%96%E8%AF%91%EF%BC%8C%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96 Parameter %E7%9A%84%E7%BC%96%E8%AF%91%E5%89%8D%E7%9A%84%E5%90%8D%E5%AD%97%0A         * %E5%90%A6%E5%88%99 %E5%8F%AA%E8%83%BD%E8%8E%B7%E5%8F%96 %E7%BC%96%E8%AF%91%E5%90%8E%E7%9A%84%E5%90%8D%E5%AD%97%0A         */%0A        for (Parameter p : method.getParameters()) %7B%0A            datas.put(p.getName(), arguments%5Bx++%5D);%0A        %7D%0A%0A%0A        /**%0A         * %E4%BF%9D%E8%AF%81%E5%9C%A8java8%E6%B2%A1%E6%9C%89%E6%B7%BB%E5%8A%A0 -parameters %E7%9A%84%E6%97%B6%E5%80%99%EF%BC%8C%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E6%B3%A8%E8%A7%A3%E7%9A%84%E6%96%B9%E5%BC%8F%E8%8E%B7%E5%8F%96%E5%8F%82%E6%95%B0%EF%BC%8C%E4%BF%9D%E8%AF%81%E5%85%BC%E5%AE%B9%E3%80%82%0A         * %E5%90%8C%E6%97%B6%EF%BC%8C%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%BF%87%E6%B3%A8%E8%A7%A3%E7%9A%84%E6%96%B9%E5%BC%8F%E8%A6%86%E7%9B%96 %E9%BB%98%E8%AE%A4%E5%90%8D%E7%A7%B0%E3%80%82%0A         */%0A
         Anno
@@ -1764,59 +1764,8 @@
 ();%0A
-        Map%3CString, Object%3E datas = new HashMap();%0A
     

add none Named annotation support for @Cacheable @CacheEvit @CachePut