views:

130

answers:

2

When implementing an interface in eclipse, it has a really nice feature that lets you "add unimplemented methods", and it will generate the method stubs for the interface methods.

However, it does not bring along the method documentation from the interface methods, and I was wondering if there was a way to get eclipse to do that.

Here's what I want to happen. Let's say I had an interface like this:

public interface BaseInterface {

    /**
     * This method takes the given string parameter and returns it's 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 create a class called MyClass which implements this interface. What I want to happen is that when I say "Add Unimplemented Methods", I want my code to look like this:

public class MyClass implements BaseInterface {

    /**
     * This method takes the given string parameter and returns it's 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;
    }

}
A: 

You can achieve it by JavaDoc annotation. It is not Eclipse specific and will work in all build/doc generation tools:

/**
 * My custom decumentation, and then the original one:
 * 
 * {@inheritDoc}
 */
jarekrozanski
+2  A: 

Yup : these methods are generated using the code templates you wrote.

You'll have to go in "Window/Preferences -> Java/Code style/Code templates"

Then, in the list, select "Comments/overriding methods" and change the content with the one you found in "Comments/methods" :

/**
 * ${tags}
 */

You can even think about adding an ${see_to_overridden} to have a direct link to original method. However, notice than a method with no javadoc will automatically inherit its javadoc from its overriden one, so such a template may generate less relevant doc than default behaviour.

Riduidel
I tried that, but it didn't work. It didn't generate any doc for the method.
dcp