248

Can I use shortcut keys in Android studio to generate javadoc comments?

If not, what is the easiest way to generate javadoc comments?

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
qinxianyuzou
  • 2,514
  • 2
  • 13
  • 8
  • This question is 50/50. You ar eeither looking for single javadoc blocks of generating javadoc throughout the document. Which is it? – basickarl Jun 04 '15 at 16:24
  • 1
    ALTR + ENTER show the view you can generate the comment of already declared methods. – Zala Janaksinh Jan 01 '16 at 05:34
  • May be you should add a Live template(Android studio - setting - editor - Live Templates - add)for it. In the template text field add the following text. /** * $comment$ */ – Johnett Mathew Aug 10 '17 at 11:28

19 Answers19

434

I can't find any shortcut to generate javadoc comments. But if you type /** before the method declaration and press Enter, the javadoc comment block will be generated automatically.

Read this for more information.

DouO
  • 4,914
  • 1
  • 20
  • 29
  • 7
    It's a shame that this doesn't also work to generate javadoc comments for classes, fields, etc. It would be even nicer if it generated javadoc from a customizable template. – Ted Hopp Jan 30 '15 at 21:40
  • 28
    of course it has shortcut: position on method/constructor name and press alt+enter, choose generate javadoc from menu – Ewoks Aug 09 '16 at 13:55
  • refer [this](https://tips.androidhive.info/2015/04/how-to-auto-generate-comments-for-your-android-functions-android-studio/) more about above solution – Pritesh Vishwakarma Jan 29 '19 at 09:24
  • 1
    @Ewoks [Doesn't work](https://i.imgur.com/Fnuwk0K.png) for me. – AndreKR Nov 04 '22 at 18:29
124

To generatae comments type /** key before the method declaration and press Enter. It will generage javadoc comment.

Example:

/**
* @param a
* @param b
*/

public void add(int a, int b) {
    //code here
}

For more information check the link https://www.jetbrains.com/idea/features/javadoc.html

Johnny Five
  • 987
  • 1
  • 14
  • 29
Amey Haldankar
  • 2,223
  • 1
  • 24
  • 22
45

Here is an example of a JavaDoc comment from Oracle:

/**
 * Returns an Image object that can then be painted on the screen. 
 * The url argument must specify an absolute {@link URL}. The name
 * argument is a specifier that is relative to the url argument. 
 * <p>
 * This method always returns immediately, whether or not the 
 * image exists. When this applet attempts to draw the image on
 * the screen, the data will be loaded. The graphics primitives 
 * that draw the image will incrementally paint on the screen. 
 *
 * @param  url  an absolute URL giving the base location of the image
 * @param  name the location of the image, relative to the url argument
 * @return      the image at the specified URL
 * @see         Image
 */
 public Image getImage(URL url, String name) {
        try {
            return getImage(new URL(url, name));
        } catch (MalformedURLException e) {
            return null;
        }
 }

The basic format can be auto generated in either of the following ways:

  • Position the cursor above the method and type /** + Enter
  • Position the cursor on the method name and press Alt + Enter > click Add JavaDoc enter image description here
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
18

You can install JavaDoc plugin from Settings->Plugin->Browse repositories.

get plugin documentation from the below link

JavaDoc plugin document

enter image description here

darwin
  • 1,524
  • 1
  • 22
  • 32
12

Javadoc comments can be automatically appended by using your IDE's autocomplete feature. Try typing /** and hitting Enter to generate a sample Javadoc comment.

 /**
 *
 * @param action          The action to execute.
 * @param args            The exec() arguments.
 * @param callbackContext The callback context used when calling back into JavaScript.
 * @return
 * @throws JSONException
 */
user7401478
  • 1,372
  • 1
  • 8
  • 25
Kuldeep Kumar
  • 754
  • 1
  • 7
  • 12
10

You can use eclipse style of JavaDoc comment generation through "Fix doc comment". Open "Preference" -> "Keymap" and assign "Fix doc comment" action to a key that you want.

Kohei Mikami
  • 2,850
  • 24
  • 21
9

Here we can some something like this. And instead of using any shortcut we can write "default" comments at class/ package /project level. And modify as per requirement

   *** Install JavaDoc Plugin ***



     1.Press shift twice and  Go to Plugins.
     2. search for JavaDocs plugin
     3. Install it. 
     4. Restart Android Studio.
     5. Now, rightclick on Java file/package and goto 
        JavaDocs >> create javadocs for all elements
        It will  generate all default comments.

Advantage is that, you can create comment block for all the methods at a time.

Mr.India
  • 674
  • 2
  • 9
  • 19
5

In Android Studio you don't need the plug in. On A Mac just open Android Studio -> click Android Studio in the top bar -> click Prefrences -> find File and Code Templates in the list -> select includes -> build it and will be persistent in all your project

Robert Warren
  • 53
  • 1
  • 3
3
  • Another way to add java docs comment is press : Ctrl + Shift + A >> show a popup >> type : Add javadocs >> Enter .

  • Ctrl + Shirt + A: Command look-up (autocomplete command name)

enter image description here

huu duy
  • 2,049
  • 21
  • 31
3

Add Javadoc

  • /** + return
  • set cursor inside method name -> ⌥ Option + return -> Add Javadoc
yoAlex5
  • 29,217
  • 8
  • 193
  • 205
2

Simply select (i.e. click) the method name, then use the key combo Alt+Enter, select "Add JavaDoc"

This assumes that you have not already added comments above the method, else the "Add JavaDoc" option will not appear.

Jim Robbins
  • 116
  • 4
2

In Android studio we have few ways to auto-generated comments:

  • Method I:

By typing /** and Then pressing Enter you can generate next comment line and it will auto-generate the params, etc. but when you need the hotkey for this check out method II on below.

  • **Method II: **

1 - Goto topMenu

2 - File > Settings

3 - Select Keymap from settings

4 - On the top right search bar search for "Fix Doc"

5 - Select the "fix doc comment" from the results and double-click on it

6 - Select Add keyboard shortcut from the opened drop down after double-click

7 - Press the shortcut keys on the keyboard

8 - Goto your code and where you want to add some comment press the shortcut key

9 - Enjoy!

Noir
  • 198
  • 1
  • 7
1

Just select the Eclipse version of the keycap in the Keymap settings. An Eclipse Keymap is included in Android Studio.

Brill Pappin
  • 4,692
  • 1
  • 36
  • 36
1

i recommendated Dokka for geneate javadoc with comment and more

Yudi karma
  • 324
  • 3
  • 15
0

I'm not sure I completely understand the question, but a list of keyboard short cuts can be found here - Hope this helps!

laminatefish
  • 5,197
  • 5
  • 38
  • 70
  • 2
    In eclipse to add javadoc comments press Alt + shift + j, but in AndroidStudio but I don't know how to do – qinxianyuzou Jun 25 '13 at 16:32
  • If I recall, that shortcut only worked if you had the 'jautodoc' plugin installed and enabled. – Matt Dec 04 '13 at 19:05
0

Android Studio -> Preferences -> Editor -> Intentions -> Java -> Declaration -> Enable "Add JavaDoc"

And, While selecting Methods to Implement (Ctrl/Cmd + i), on the left bottom, you should be seeing checkbox to enable Copy JavaDoc.

Mahi
  • 472
  • 5
  • 7
0

Because almost of us use Kotlin, you can generate JavaDoc (KDoc) using plugins. In Android Studio open Settings (press Ctrl+Alt+S), select Plugins and find kdoc. I downloaded KDoc-er, but you can choose any of them. Then restart Android Studio.

Find any class/method, type /**, press Enter. You will get a short description like:

/**
 * User data
 *
 * @property name
 * @property avatar
 * @property gender
 * @constructor Create empty User data
 */
class UserData(...

enter image description here

CoolMind
  • 26,736
  • 15
  • 188
  • 224
-1

to generate javadoc comment use /** Your docs */

jay
  • 15
  • 3
  • This has already been mentioned *and explained in detail* in the other answers. *When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers.* – Eric Aya Oct 16 '21 at 20:45
-5

ALT+SHIFT+G will create the auto generated comments for your method (place the cursor at starting position of your method).

James Skemp
  • 8,018
  • 9
  • 64
  • 107
Dinesh IT
  • 87
  • 2
  • public void hideKeyboard() u should place the cursor in front of public and try it or please check whether u installed the java doc in your studio. – Dinesh IT Mar 23 '15 at 06:17
  • It is not working for me either. Maybe, it is working in some special keymap. The keymap can be configured in Preferences > Keymap. Or the keymap has been edited. – Oliver Kranz Sep 17 '15 at 08:12