个人项目-过滤代码工程文件注释

来源:互联网 发布:淘宝订单贷款能用多久 编辑:程序博客网 时间:2024/06/05 04:43
功能介绍:
     对代码工程中的(如java,jsp,c++,xml,html,js,properties,py等类型)文件注释进行过滤删除,以减少代码的占用空间和打包后的大小等。

实例:

package org.slive.project.style;import java.util.ArrayList;import java.util.List;import java.util.Set;import org.slive.project.style.formatter.CommentFilter;import org.slive.project.style.formatter.conf.CommentConfig;import org.slive.project.style.formatter.conf.CommentType;public class TestMain {    public static void main(String[] args) {        String prjPath = "E:/DevPrjs/Git/org.slive.project.style/";        String destPrjPath = "E:/DevPrjs/Git/bak/org.slive.project.style/";        long startTime = System.currentTimeMillis();        System.out.println("测试开始。");        System.out.println("源项目:"  + prjPath);        System.out.println("目标项目:"  + prjPath);        List<CommentConfig> confs = new ArrayList<>();        CommentConfig c0 = new CommentConfig();        // 处理文件类型        c0.setFileTypeSuffix("java");        // 过滤掉"//","/* */"的注释        Set<CommentType> commentFilters = c0.getCommentTypes();        commentFilters.add(new CommentType("//"));        commentFilters.add(new CommentType("/*", "*/"));        confs.add(c0);        CommentConfig c1 = new CommentConfig();        // 处理文件类型        c1.setFileTypeSuffix("xml,html");        // 过滤掉"<!-- -->"的注释        Set<CommentType> commentFilters1 = c1.getCommentTypes();        commentFilters1.add(new CommentType("<!--", "-->"));        confs.add(c1);        CommentConfig c2 = new CommentConfig();        // 处理文件类型        c2.setFileTypeSuffix("properties,sh");        // 过滤掉"#"的注释        Set<CommentType> commentFilters2 = c2.getCommentTypes();        CommentType e = new CommentType("#");        e.setException("#!");        commentFilters2.add(e);        confs.add(c2);        CommentFilter.clearComments(prjPath, destPrjPath, confs);        System.out.println("耗时:" + (System.currentTimeMillis() - startTime) * 0.001 + "s");    }}


源码:https://github.com/Slive/org.slive.project.style

            http://download.csdn.net/detail/lipslive/9602161



0 0
原创粉丝点击