Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 754
krossovochkin Avatar asked Oct 13 '14 07:10

krossovochkin


People also ask

How do I remove all comments from code?

📝 Usage. Once installed, remove comments in your code by opening the command palette ( Ctrl + Shift + P ), entering "Remove all comments" and pressing enter. Voilà, all the comments are gone 🎉 !


1 Answers

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.

like image 87
dawez Avatar answered Oct 13 '22 09:10

dawez