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

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

问题描述

IntelliJ中是否有插件或工具会将所有注释从源.java文件中删除?我已阅读了有关可执行此操作的 ANT任务 ..希望在IDE中做同样的事情。

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..

推荐答案

您可以使用替换(或在路径中替换if您要在多个文件中删除注释),然后在文本查找字段中使用此正则表达式:

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:

(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/|[ \t]*//.*)

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

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:

(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)

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

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

([ \t]*//.*)

,我应该警告,这只工作%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 = "";

:D

希望这有帮助。

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

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