android studio插件 统计代码行数

一直好奇 这个插件如何统计代码行数 注释行数 和空行数的,
下载其jar包,查看源码发现,是这样的
学习下

boolean isInComment = false;
        Integer total = 0;
        Integer blank = 0;
        Integer comment = 0;
        Integer code = 0;

        try {
            BufferedInputStream inputStream = new BufferedInputStream(stream);
            LineNumberReader streamReader = new LineNumberReader(new InputStreamReader(inputStream));

            while(true) {
                while(true) {
                    String line;
                    do {
                        if (!streamReader.ready()) {
                            return new LOCBean(total, blank, comment, code);
                        }

                        line = streamReader.readLine();
                    } while(line == null);

                    total = total + 1;
                    line = line.trim();
                    if (line.length() == 0) {
                        blank = blank + 1;
                    } else if (!line.startsWith("//") && !line.startsWith("#")) {
                        if (isInComment) {
                            comment = comment + 1;
                            if (line.contains("*/") || line.contains("\"\"\"") || line.contains("'''") || line.contains("-->")) {
                                isInComment = false;
                            }
                        } else if (!line.equals("\"\"\"") && !line.equals("'''")) {
                            if ((!line.startsWith("/*") || !line.endsWith("*/")) && (!line.startsWith("\"\"\"") || !line.endsWith("\"\"\"")) && (!line.startsWith("<!--") || !line.endsWith("-->"))) {
                                if (!line.startsWith("/*") && !line.startsWith("\"\"\"") && !line.startsWith("<!--")) {
                                    code = code + 1;
                                } else {
                                    comment = comment + 1;
                                    if (!line.contains("*/") || !line.contains("\"\"\"") || !line.contains("-->")) {
                                        isInComment = true;
                                    }
                                }
                            } else {
                                comment = comment + 1;
                            }
                        } else {
                            comment = comment + 1;
                            isInComment = true;
                        }
                    } else {
                        comment = comment + 1;
                    }
                }
            }
        } catch (IOException var11) {
            var11.printStackTrace();
            return new LOCBean(total, blank, comment, code);
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值