Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
     * 
     * @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 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;
    }

}
like image 442
dcp Avatar asked Apr 08 '10 14:04

dcp


People also ask

How do you add all unimplemented methods in listeners?

Right click(on the Listeners class ) -> go to source-> click on overide/implement methods -> select the check boxes for the ITest listener (make sure all check box inside it should be checked )->click on oK. That's it !!!

How do I get unimplemented methods in eclipse?

Click on the light bulb or press Ctrl+1 (Edit > Quick Fix) to choose between adding the unimplemented methods or making your class abstract. When you add a new method to an interface or an abstract method to an abstract class, Eclipse can generate method stubs in all concrete subclasses at once.

What is unimplemented methods in Java?

Java already has a keyword for unimplemented methods i.e. abstract. Java has the provision where any class can implement any interface, so all the methods declared in interfaces need to be public only.


1 Answers

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.

like image 150
Riduidel Avatar answered Sep 28 '22 16:09

Riduidel