删除JavaDoc注释的工具? [英] Tool to remove JavaDoc comments?

查看:341
本文介绍了删除JavaDoc注释的工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可以删除文件中所有JavaDoc注释的工具/ Eclipse插件?



正常(非JavaDoc)注释

解决方案

尝试这个正则表达式可以在eclipse / sed /您喜欢的编辑器,具有regex支持。

  / \ * \ *(?s :(? * /)/ 




  • ?s 将输入视为单行

  • 起始字符串 \ **

  • 零或以上

    • 的负面前瞻* /

    • 空格或非空格字符


  • 尾随字符串 * /



修改



包含javadoc的字符串,使用此正则表达式

 ((?<!\\)([^] | ?< = \\) )*)|(/ \ * \ *(S :( ?* \ * /)

并将其替换为第一次捕获组

  / 1 

然后,如果你说这不应该匹配

  /// ** * / 

或更复杂的案例



我建议使用解析器使用






  / \ * \ * (?! \ * /)。)* \ * / 



Debuggex演示


Is there any tool / Eclipse plugin that can remove all JavaDoc comments in a file?

The normal (non-JavaDoc) comments should be intact after running the tool.

解决方案

Try this regex to search replace either in eclipse / sed / your favorite editor that has regex support.

/\*\*(?s:(?!\*/).)*\*/

  • ?s treat input as single line
  • a starting string \**
  • zero or more
    • negative lookahead for */
    • space or non space char
  • a trailing string */

Edit

To tackle cases where strings containing javadoc, use this regex

((?<!\\)"([^"]|(?<=\\)")*")|(/\*\*(?s:(?!\*/).)*\*/)

and replace it with first capture group

/1

Then if you say this shouldn't match

///** */

or more complex cases

I suggest, using a parser tool like antlr to parse using java grammar for tokens like comments and strings and remove elements that you don't want


Sometime I find my own regex answers cryptic !!

So here is some visual feedback

((?!\\)"([^"]|(?=\\)")*")|(/\*\*(?:(?!\*/).)*\*/)

Debuggex Demo


/\*\*(?:(?!\*/).)*\*/

Debuggex Demo

这篇关于删除JavaDoc注释的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆