Removing empy comment blocks

Eclipse can automate a lot of stuff for you. One thig is did for me was automating the serialVersionId generation for all the serializable classes in my tree.
They look like this:

     private static final long serialVersionUID = -9031744976450947933L;

However, it put an empty block comment in on top of them, something I didn’t notice until I had mixed in this commit with another. So, I want to remove those empty comment blocks.


for JAVAFILE in `find . -name \*.java`
     sed -n '1h;1!H;${;g;s! */\*\*\n *\* *\n *\*/ *\n!!g;p;}' \
         < $JAVAFILE > $
     mv $ $JAVAFILE

Thanks to this article for how to do the multiline search and replace.

One thought on “Removing empy comment blocks

  1. If you want to identify comments with regexes, you really need to use the regex as a tokenizer. I.e., it identifies and extracts the first thing in the string, whether that thing be a string literal, a comment, or a block of stuff that is neither string literal nor comment. Then you grab the remainder of the string and pull the next token off the beginning.

Leave a Reply

Your email address will not be published. Required fields are marked *