如何从 Android Studio 中的特定文件中删除所有评论? [英] How to remove all comments from the specific file in Android Studio?

查看:36
本文介绍了如何从 Android Studio 中的特定文件中删除所有评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一些大文件,其中注释了很多行.

I have some big files in my project with many lines commented.

通常,当我更改代码中的某些内容时,我会先注释不必要的行,然后在测试后将其删除.
但是有时候最后一个大文件里的注释太多了,很难去掉.
因此,Android Studio 中可能有一些功能可以从注释中清理"文件(当然不包括 javadoc 注释),例如组织导入"以删除文件中未使用的导入.
或者,也许是某种突出显示的注释行,以便我可以轻松查看要删除的内容.

Usually when I change something in my code, I comment unnecessary lines first and after testing remove them.
But sometimes at the end there are too many comments in a big file, and it is hard to remove them.
So, may be there is some function in Android Studio to 'clean up' file from comments (excluding javadoc comments, of course) like 'Organize imports' for removing unused imports in file.
Or, maybe, some kind of highlighting commented lines, so I can easily see what to remove.

你能帮我解决这个问题吗?
任何想法表示赞赏

Can you help me with that?
Any ideas are appreciated

推荐答案

尝试使用正则表达式,将匹配替换为空

Try with regex, to replace the match with nothing

本页建议:

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

也匹配 Javadocs,所以你必须稍微调整一下.您还可以尝试其他变体.

This is also matching the Javadocs, so you would have to tweak it a bit. There are also other variations that you can try.

看看其他 SO 问题.建议使用处理注释并将它们从源中剥离的 ANT 任务.通过这种方式,您可以拥有一个调用 ANT 任务的按钮或键盘快捷键.

Have a look at this other SO question. It is suggesting to use an ANT task that is processing the comments and strip them from the source. In this way you can have a button or keyboard shortcut that is calling the ANT task.

建议在进行大搜索和替换之前在历史记录中放置一个标签,以便稍后您可以比较是否要恢复可能已被删除的任何评论.

As suggestion put a Label in the history before doing big search and replace so later you can compare if want to restore any comments that may have been stripped.

这篇关于如何从 Android Studio 中的特定文件中删除所有评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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