开发者

eclipse add unimplemented methods including javadoc

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 its integer value.
     * 
     * @param x the string to convert
     * @return the integer value of the string
     * 
     * @throw开发者_Go百科s 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 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;
    }

}


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 that 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.


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}
 */
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜