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..
+1
A:
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]*//.*)
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
Hope this helps.
Bytecode Ninja
2010-04-10 15:53:40
Good idea.. but that RegEx doesn't seem to work for me..
Marcus
2010-04-11 00:03:57
The first one? I just double checked it in IDEA 9.0.1 and it is working for me.
Bytecode Ninja
2010-04-11 15:08:34
Hmmm.. I'm trying on this http://pastebin.com/u0fQub8j file.. doesn't seem to work. Any ideas? I'm on IntelliJ 8.
Marcus
2010-04-11 16:11:35
Tried again, the second one works nicely.. doesn't get all the comments but most. Still couldn't get the first to work.
Marcus
2010-04-11 19:15:25
Works here... here's the regex copy pasted to a paste bin: http://paste.ly/OD
Bytecode Ninja
2010-04-12 09:41:40