Eclipse adds unrealized methods including javadoc

When you implement an interface in eclipse, it has a really nice feature that allows you to "add unrealized methods" and will generate method stubs for interface methods.

However, it does not carry documentation on the method from the interface methods, and I was wondering if there is a way to get an eclipse for this.

Here is what I want. Let's say I had this interface:

public interface BaseInterface { /** * This method takes the given string parameter and returns its integer value. * * @param x the string to convert * @return the integer value of the string * * @throws Exception if some error occurs */ int method1(String x); } 

Now I am creating a MyClass class that implements this interface. I want that when I say "Add unrealized methods", I want my code to look like this:

 public class MyClass implements BaseInterface { /** * This method takes the given string parameter and returns its integer value. * * @param x the string to convert * @return the integer value of the string * * @throws Exception if some error occurs */ public int method1(String x) { return 0; } } 
+6
java eclipse code-generation
source share
2 answers

Yup: These methods are generated using the code templates you created.

You need to go to "Window / Preferences → Java / Code style / Code templates"

Then select “Comments / Override Methods” from the list and change the contents to the one you found in “Comments / Methods”:

 /** * ${tags} */ 

You might even consider adding ${see_to_overridden} to a direct link to the original method. However, note that a method without javadoc will automatically inherit its javadoc from its excess, so such a template may generate a less relevant document than the default behavior.

+5
source share

You can achieve this with the JavaDoc annotation. This is not Eclipse specific and will work in all doc creation / creation tools:

 /** * My custom decumentation, and then the original one: * * {@inheritDoc} */ 
0
source share

All Articles