使用 IntelliJ 删除源文件注释? [英] Remove source file comments using IntelliJ?

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

问题描述

IntelliJ 中是否有插件或工具可以去除源 .java 文件中的所有注释?我已经阅读了可以执行此操作的 ANT 任务.. 希望在 IDE 中做同样的事情.或者,TextPad 插件也可以工作..

Is there a plugin or tool in IntelliJ that will strip all comments out of your source .java files? I've read about an ANT task that can do this.. was looking to do the same from within the IDE. Alternatively a TextPad plugin would work as well..

推荐答案

您可以在正则表达式模式下使用替换"(如果要删除多个文件中的注释,则可以使用在路径中替换")然后使用这个要查找的文本"字段中的正则表达式:

You can use the "Replace" (or "Replace in Path" if you want to remove comments in multiple files) in the regular expression mode and then use this regular expression in the "Text to find" field:

(/*([^*]|[
]|(*+([^*/]|[
])))**+/|[ 	]*//.*)

并用空字符串替换它.然后按全部"将此替换应用于整个文件或所有选定的文件.这将从您的文件中删除所有块注释和行注释.如果您只想删除块注释,请改用此正则表达式:

and replace it with an empty string. Then press "All" to apply this replacement to the entire file or all the selected files. This will remove all block comments and line comments from your file. If you want only block comments to be removed, use this regex instead:

(/*([^*]|[
]|(*+([^*/]|[
])))**+/)

如果你只想删除行注释,你可以使用这个正则表达式:

And if you want to just remove line comments, you can use this regex:

([ 	]*//.*)

但是,我应该警告说,这只适用于 %99.99 次.您可能在文件中定义了一个字符串变量,例如:

However, I should warn that this works only %99.99 of times. You might have a string variable defined in your file like:

String myStr = "/** I am not a comment */";

这个正则表达式将把它变成:

This regex will turn this to:

String myStr = "";

希望这会有所帮助.

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

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