DEV Community

loading...

How to get rid of all those non-javadoc comments in your Java project ✨

corradodellorusso profile image Corrado dello Russo ・1 min read

Have you ever met something like this in your legacy code?

/* 
 * (non-Javadoc)
 * @see java.lang.ClassLoader#loadClass(java.lang.String)
 */

If you are a Java programmer from more than one millisecond i guess so. 😇

What is it?

It is the template Eclipse IDE used to generate when overriding a method from a super class. Legend tells it was a workaround for a bug in the JavaDoc generator when inheriting docs from the parent class.

Should i keep these as of today?

Long story short: No.
They're useless for robots and polluting for developers.

Robots

For JavaDoc generators, the only officially supported way to copy docs from a parent is adding following snippet right before the method signature:

/** 
 * {@inheritDoc}
 */

Please notice the double star in the first line.

Developers

As developer i find this kind of boilerplate noisy other than actually meaningless. Writing something about the reason for overriding parent class would be more useful.

How do i clean it?

You can either use a light approach, deleting them every time you find one in your code. But i'd rather take the hardcore 🤘 approach, matching them with a regular expression.

Using your IDE (i've tested it with IntelliJ IDEA and Eclipse) you can use the following regex to replace all the occurrences in path.

(?s)/\*[^*](?:(?!\*/).)*\(non-javadoc\)(?:(?!\*/).)*\*/

Always keep your code clean and readable!

Refs:
StackOverflow

Discussion

pic
Editor guide