zno2

获取 class doc

 

 

目标识别需要具备的特征:有package,是class,/** ... */  doc文档,只识别单行

复制代码
    
    public static void main(String[] args) {
        System.out.println(getClassDoc(
                "package cn.zno.xxx;\r\n" + 
                "\r\n" + 
                "/**\r\n" + 
                " * 哇啦哇啦\r\n" + 
                " * @author witas\r\n" + 
                " * 创建时间: 2022年12月16日\r\n" + 
                " */\r\n" + 
                "public class FFFFFF {\r\n" + 
                "\r\n" + 
                "}\r\n" + 
                ""));
    }
    

    private static String getClassDoc(String text) {
        Matcher matcher = Pattern.compile("package [\\s\\S]* class ").matcher(text);
        boolean find = matcher.find();
        if (find) {
            String head = matcher.group();
            Matcher m = Pattern.compile("\\/\\*\\*([\\s\\S]*)\\*\\/").matcher(head);
            if (m.find()) {
                String group = m.group(1).trim();
                String[] lines = group.split("\n|\r\n");
                for (String line : lines) {
                    line = line.trim().substring(1);
                    if (line.startsWith("@")) {
                        continue;
                    }
                    line = line.trim();
                    if (line.length() > 0) {
                        return line;
                    }
                }
            }
        }
        return "";
    }
    
复制代码

 

输出:

哇啦哇啦

 

posted on   zno2  阅读(16)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)

导航

统计信息

点击右上角即可分享
微信分享提示