How to remove all comments from the specific file in Android Studio? [duplicate]

大城市里の小女人 提交于 2019-12-20 09:25:03

问题


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

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


回答1:


Try with regex, to replace the match with nothing

This page suggest :

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

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

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.



来源:https://stackoverflow.com/questions/26334680/how-to-remove-all-comments-from-the-specific-file-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!