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

14,435

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.

Share:
14,435
krossovochkin
Author by

krossovochkin

My name is Vasya. I'm Android developer. Responsible dolt.

Updated on June 04, 2022

Comments

  • krossovochkin
    krossovochkin almost 2 years

    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