20140225

import java.io.IOException;
import java.lang.reflect.Method;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

/**
 * 检查BIZ层不符合规则的方法
 * @author @author ANDY
 *
 */
public class CheckMethodsInBiz {

    public static void main(String[] args) throws IOException {
        //spring自动加载指定路径规则的文件//在当前工程和jar包
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        Resource[] resources = resolver.getResources("classpath:com/yto/coresystem/module/**/biz/*.class");// com.yto.coresystem.module.hetjoin.biz.impl;
        // System.out.println(resources.length);

        for (Resource res : resources) {
            try {
                //转换成 packageName.className
                String tmpClassName = res.getFile().toString();
                tmpClassName = tmpClassName.substring(tmpClassName.indexOf("com"), tmpClassName.indexOf(".class"));
                tmpClassName = tmpClassName.replace("\\", ".");
                System.out.println(tmpClassName + " ------------------------------ ");

                //反射加载所有的方法
                Class<?> tmpClass = Class.forName(tmpClassName);
                Method[] methods = tmpClass.getMethods();
                for (Method method : methods) {
                    if (method.getName().startsWith("list")
                            || method.getName().startsWith("query")
                            || method.getName().startsWith("search")
                            || method.getName().startsWith("load")
                            || method.getName().startsWith("find")
                            || method.getName().startsWith("get")
                            || method.getName().startsWith("show")
                            || method.getName().startsWith("view")
                            || method.getName().startsWith("export")
                            || method.getName().startsWith("sync")
                            || method.getName().startsWith("add")
                            || method.getName().startsWith("new")
                            || method.getName().startsWith("save")
                            || method.getName().startsWith("remove")
                            || method.getName().startsWith("delete")
                            || method.getName().startsWith("update")
                            || method.getName().startsWith("modify")
                            || method.getName().startsWith("submit")
                            || method.getName().startsWith("audit")
                            || method.getName().startsWith("gen")
                            || method.getName().startsWith("do")
                            || method.getName().startsWith("grant")
                            || method.getName().startsWith("ungrant")
                            || method.getName().startsWith("confirm")
                            || method.getName().startsWith("cancel")
                            || method.getName().startsWith("hedge")
                            || method.getName().startsWith("writeoff")
                            || method.getName().startsWith("create")
                            || method.getName().startsWith("reject")
                            || method.getName().startsWith("execute")
                            || method.getName().startsWith("requiresNew")
                            || method.getName().startsWith("saveOutHouse")
                            || method.getName().startsWith("submitInNoticeDetail")) {
                        //do nothing

                    } else {
                        System.out.println(method.getName());
                    }

                }

            } catch (Exception e) {
            }
        }

    }

}

 

posted @ 2014-02-25 15:50  龙猫爸爸  阅读(129)  评论(0)    收藏  举报