0
我使用eclipse java jdt解析器,它似乎缺少以下功能:提取注释体。提取Java评论正文(不含//,/ *,* /)
下面的代码:
class CommentBodyExtractor extends ASTVisitor {
@Override public boolean visit(BlockComment node) {
final int start = node.getStartPosition();
final int end = start + node.getLength();
final String comment = source.substring(start, end);
System.out.println(comment);
return false;
}
}
上时,下面的代码运行:
/*
* comment_body
*/
返回完整的注释代码,而我所寻找的是代码,将只返回comment_body
。
我可以做简单的字符串操作,比如从字符串的开头删除/*
,从末尾删除*/
,从行开头删除。不过,我想用更优雅的方式(一些图书馆?),你知道吗?
也许[QDox](https://github.com/paul-hammant/qdox)可以提供帮助吗? –
Thanks @LanceJava我以前没有用过这个库,我会试试看。 –
除非每个人都使用评论内容的约定,否则您将无法找到提取您的comment_body的好方法。任何人都可以在多行注释的“左边缘”放置任何文本;你怎么知道什么是评论文本,什么是模板?你可以对此做出假设;期待他们以真实的代码破解。 –