Anonymous Human
Anonymous Human

Reputation: 1948

Intellij IDEA how to auto-generate non-javadoc comment block?

In Eclipse, when adding javadoc comment blocks to the methods of an implementation class(of some interface) whose interface is in the same project, I can type /* (a slash followed by an asterisk) and then press enter and that immediately generates a non-javadoc comment atop that method which references the javadoc of the interface that that class implements using the @see annotation. How can I achieve this behavior in Intellij IDEA?

Upvotes: 1

Views: 2052

Answers (1)

Uddhav P. Gautam
Uddhav P. Gautam

Reputation: 7626

You have to write /** and press ENTER key

For the complete implementation:

Add below code above your method in interface. @link is your equivalent to @see.

 /**
         * {@inheritDoc}
         * This printHello method is .......... you write explanation here
         * {@link com.example.uddhav.memoryuse.MyInterface}
* I provided absolute reference of MyInterface here 
         */
        public void printHello(String str); /* your method */

On your class, which implements interface, you do right click > generate > override methods > check "copy javadoc".

Example:

Interface

    public interface MyInterface {
    /**
     * {@inheritDoc}
     * {@link com.example.uddhav.memoryuse.MyInterface}  
     * This printHello method is ..........
     */
    public void printHello(String str);

    /**
     * {@inheritDoc}
     * This printUddhav method is ..........
     */

    public void printUddhav(String strr);

    public void printGautam(String strr);

}

Class:

public class MainActivity extends AppCompatActivity implements MyInterface{
/* right click > generate > override methods > copy JavaDoc */
/* you are done */

/* I generated these below */

 /**
     * {@inheritDoc}
     * {@link MyInterface}
     * This printHello method is ..........
     *
     * @param str
     */
    @Override
    public void printHello(String str) {

    }

    /**
     * {@inheritDoc}
     * This printUddhav method is ..........
     *
     * @param strr
     */
    @Override
    public void printUddhav(String strr) {

    }

    @Override
    public void printGautam(String strr) {

    }

Click on myInterface, you will be redirected to your method on the interface.

Upvotes: 2

Related Questions