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

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

问题描述

是否有任何工具/Eclipse 插件可以删除文件中的所有 JavaDoc 注释?

运行该工具后,正常(非 JavaDoc)注释应该是完整的.

解决方案

试试这个正则表达式在 eclipse/sed/你最喜欢的支持正则表达式的编辑器中搜索替换.

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

  • ?s 将输入视为单行
  • 一个起始字符串**
  • 零个或多个
    • */的负前瞻
    • 空格或非空格字符
  • 尾随字符串*/

编辑

要解决字符串包含 javadoc 的情况,请使用此正则表达式

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

并用第一个捕获组替换它

<代码>/1

那么如果你说这不应该匹配

///** */

或更复杂的情况

我建议,使用像 antlr 这样的解析器工具来使用

<小时>

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

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天全站免登陆