0

Eclipse has a feature to generate a constructor for a class from fields of that class. However, the option to automatically add Javadoc is insufficient, as it would be easily possible to insert the comment of the fields for the parameters. I would like to automate this, but don't know how.

Example:

I have this class:

class Animal {
    /**
     * the number of legs of the animal. This influences many features of the animal, such as its ability to stand, to run, and to not fall over and starve to death. Must not be negative unless the animal is marked as Lovecraftian.
     */
    int numberOfLegs;
}

When I use the shortcut of Eclipse to generate a constructor from fields, it creates this:

/**
 * @param numberOfLegs
 */
public Animal(int numberOfLegs) {
    this.numberOfLegs = numberOfLegs;
}

This is because the Javadoc that is generated automatically is defined as this:

/**
 * ${tags}
 */

What I would like to have instead is this:

/**
 * @param numberOfLegs the number of legs of the animal. This influences many features of the animal, such as its ability to stand, to run, and to not fall over and starve to death. Must not be negative unless the animal is marked as Lovecraftian.
 */

or alternatively this:

/**
 * @param numberOfLegs {@link numberOfLegs}
 */

Is there a way to automate this with eclipse natively? If not, is there a plugin that can do it?

Florian Dietz
  • 877
  • 9
  • 20
  • how is eclipse supposed to know what the description is, that is a little optimistic is it not? –  Apr 10 '16 at 22:09
  • There is already a very good answer [here](http://stackoverflow.com/a/15002022/1692706) – Debosmit Ray Apr 10 '16 at 22:10
  • Your link has to do with generating HTML from existing Javadoc. As far as I can tell, this has nothing to do with my question. – Florian Dietz Apr 10 '16 at 22:41
  • @JarrodRoberson please reread my question. I do not claim that eclipse should generate a sensible comment automatically, only that it creates a link and/or copies an existing comment to another location. – Florian Dietz Apr 10 '16 at 22:43
  • *If not, is there a plugin that can do it?*, regardless this is also **off topic: asking for recommendations for offsite resource** –  Apr 10 '16 at 23:20

0 Answers0