All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.gotoeasy.framework.spring.aop.enhance.generate.Src13ThrowingCreater Maven / Gradle / Ivy

Go to download

基于JavaCompiler的继承方式AOP实现,在性能优良的基础上,提供更多的简易性,2.x.x版本集成使用Spring容器

The newest version!
package top.gotoeasy.framework.spring.aop.enhance.generate;

import java.lang.reflect.Method;
import java.util.List;

import top.gotoeasy.framework.spring.aop.annotation.Throwing;
import top.gotoeasy.framework.spring.aop.util.AopUtil;
import top.gotoeasy.framework.spring.aop.util.StringUtil;

/**
 * Throwing拦截代码块生成类
 * 
 * @since 2018/01
 * @author 青松
 */
public class Src13ThrowingCreater {

    private static final String TAB2 = "        ";

    private DataBuilderVars dataBuilderVars;
    private AopMethodArgsMapping aopMethodArgsMapping;

    /**
     * 构造方法
     * 
     * @param dataBuilderVars 公用变量
     */
    public Src13ThrowingCreater(DataBuilderVars dataBuilderVars) {
        this.dataBuilderVars = dataBuilderVars;
        aopMethodArgsMapping = new AopMethodArgsMapping(dataBuilderVars);
    }

    /**
     * Throwing拦截代码块生成
     * 
     * @param method 方法
     * @return Throwing拦截代码块
     */
    public StringBuilder getThrowingSrc(Method method) {
        // ----------------------------------
        // --------------------------------------------------
        // {varAopObj}.{aopMethodName}(this, {varMethod}, {parameterNames})
        // ----------------------------------
        // --------------------------------------------------
        StringBuilder buf = new StringBuilder();
        List list = dataBuilderVars.methodThrowingSrcInfoMap.get(method);
        if (list == null) {
            return buf;
        }

        list.sort((info1, info2) -> info1.aopOrder - info2.aopOrder);
        for (DataMethodSrcInfo info : list) {
            // 前5个参数判断类型自动入参
            StringBuilder sbAopMethodParams = aopMethodArgsMapping.mappingArgs(info.method, info.aopMethod,
                    Throwing.class, info.varMethod, "null", "ex", true);

            buf.append(TAB2).append(info.varAopObj).append(".").append(info.aopMethodName).append("(")
                    .append(sbAopMethodParams);
            String parameterNames = AopUtil.getParameterNames(method, info.aopMethod);
            if (StringUtil.hasText(parameterNames)) {
                if (sbAopMethodParams.length() > 0) {
                    buf.append(", ");
                }
                buf.append(parameterNames);
            }
            buf.append(");\n");
        }
        return buf;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy