sed works on one line at a time. Use perl instead:
perl -0777 -pe 's,\s*/\*[*\s]*\*/\s*, ,gs'
That will convert an empty comment and all the spaces around it to a single space (needed, otherwise
int/* */i would be turned into
inti otherwise for instance). Now, that means that if you have consecutive empty comments, you'll have consecutive white spaces, so you may want to change it to:
perl -0777 -pe 's,\s*(?:/\*[*\s]*\*/\s*)+, ,gs'
Now, to preserve spacing, it depends what you want to do, and how the comments are laid out. If the comments may be everywhere and you want to preserve indenting after a comment, but still want to condense unnecessary space, you could try:
perl -0777 -pe 's,(\s*)(?:\s*/\*[*\s]*\*/)+(\s*\n|\s*),"$1$2"=~/\n/?"\n":" ",ges'
That is, if there were newlines around the comments, replace with a newline (and the original indentation after a newline after the comments) or a space otherwise.
This is possible with perl because perl regexp alternation operator contrary to other regexp engine, don't try to find the longest match but look at each part of the alternation in turn until one matches.
Now, if you want to ignore empty comments that may occur inside strings (like
"/***/"), it becomes a bit trickier especially when you have to take into account escaped double quotes or double quotes inside single quotes. But, once again the perl alternation regexp operator comes to the rescue:
perl -0777 -pe 's,(\s*)(?:\s*/\*[*\s]*\*/)+(\s*\n|\s*)|(/\*.*?\*/|//.*?\n|"(?:\\.|.)*?"|'\''(?:\\.)?.*?'\''|.[^"/'\'']*),"$3"or"$1$2"=~/\n/?"\n":" ",ges'
The idea is that that regexp matches the whole file, but in different alternatives of that big alternation that works a bit like a tokeniser.
Basically, it walks through the file and splits it into tokens. The text is considered as a sequence of tokens that are either the empty comments we're looking, ore double quoted strings, or single-quoted characters (with possibly escapes like
'\033'), or anything else.
Tokens that are the empty comments we're looking for are replaced with space or newline as above, anything else is replaced with itself. So it should now be able to process inputs like
/* comments with " unmatched quotes ' */ /* */
f('"', "/***/" /***/, "\"", "/****/")
correctly. Now, not being familiar with the
java syntax, I suppose there might be corner cases where that doesn't work, so a java expert would be able to improve it (for instance, in C, you'd need to account for trigraphs or backslashes can be used to escape newlines, so it would miss a
/* that has been broken in the middle as
/\<LF>*, it might be the same in java, so you could improve that code to take that into account).