Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there any tool / Eclipse plugin that can remove all JavaDoc comments in a file?

The normal (non-JavaDoc) comments should be intact after running the tool.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
206 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this regex to search replace either in eclipse / sed / your favorite editor that has regex support.

/**(?s:(?!*/).)**/
  • ?s treat input as single line
  • a starting string **
  • zero or more
    • negative lookahead for */
    • space or non space char
  • a trailing string */

Edit

To tackle cases where strings containing javadoc, use this regex

((?<!\)"([^"]|(?<=\)")*")|(/**(?s:(?!*/).)**/)

and replace it with first capture group

/1

Then if you say this shouldn't match

///** */

or more complex cases

I suggest, using a parser tool like antlr to parse using java grammar for tokens like comments and strings and remove elements that you don't want


Sometime I find my own regex answers cryptic !!

So here is some visual feedback

((?!\)"([^"]|(?=\)")*")|(/**(?:(?!*/).)**/)

Regular expression visualization

Debuggex Demo


/**(?:(?!*/).)**/

Regular expression visualization

Debuggex Demo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...