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 2023-08-03 19:46  zno2  阅读(16)  评论(0编辑  收藏  举报

导航