How do I change the Javadocs template generated in Eclipse? - java

I dislike the default Javadocs generated for me when I create a Class or methods, especially the #author variable, which is the current system username on my windows box.
I would like to change it. Is this possible?

Check Preferences / Java / Code Style / Code Template
Section Comment / Type
You can replace the author tag by whatever value you need and it will have an effect on new generated classes.
However, if the template is fine, but the value referenced buy the author tag is not, see this SO question:
${user} uses the value of the user.name environment variable; therefore, you can pass -Duser.name=My Name in eclipse.ini to override it.
Or, if you prefer, you can modify the shortcut to point to:
C:/java/eclipse/eclipse.exe -vmargs -Duser.name="cleverUserNameToUseInSourceCode"
MacOs: Aram Kocharyan mentions the eclipse.ini is in Eclipse.app/Contents/MacOS/ if you right click and go Show Package Content.
ZendStudio: rofflox comments the file is named ZendStudio.ini and is found in Applications/Zend Studio.app/Contents/MacOS/.

Look at Window -> Preferences -> Java -> Editor -> Templates.

Spring Tool Suite (popular Eclipse customization for Spring development) uses STS.ini. On Windows I found it in the same dir as an app launch executable.

To use a Git username and email you can use the variables ${name:git_config(user.name)} and
${email:git_config(user.email)}.

You should consider using JAutodoc, which is a very useful plugin for Eclipse. The parametrization is way more advanced than the standard Eclipse generation.

Related

Eclipse plugin dev: how to add default VM arguments by code?

While developing some plugins based on Eclipse, I need to add some default VM arguments when user right click-> "run as" -> "java application" or "spring boot app", is there any open api I can call or any extension point?
Just like the snapshot below, the argument "-Daaa=bbb" is added by default.
Any help is appreciated.
You need to write your own plugin and need to replicate/extend Java launch configuration
(of type Java application) from JDT and add -vm argument programmatically.
But there is one more easy way: Try LcDsl.
LcDsl provides a way of defining Eclipse launch configurations in a textual way. The file extension used is '.lc' It provides some obvious and some non-obvious advantages over the Eclipse launch configuration solution.
For more info look here and check demo videos. Also there was a discussion going on to include this plugin in JDT itself, see this bug entry.
A typical Java launch configuration looks like this:
java configuration LcJavaMain {
project com.wamas.test;
main-class com.wamas.test.JavaMain;
memory min=64m max=256m;
vm-argument '-Dmy.arg=value';
argument 'cmdArg';
}

How can I change #author tag configuration in eclipse in such a way that it takes the name I have specified?

I'm using Eclipse Indigo for Java.
I used to write comments over the methods.
In that whenever I use #author tag, it automatically takes the username of the system who is currently logged in.
My question is : How can I change this #author tag configuration in such a way that it takes the name I have specified.
I have gone through the following link:
How to change the value of ${user} variable used in Eclipse templates
But it suggests to change the value of classpath variable $user.
I don't want to do that. I want to change comment template through configuration.
There are several ways of accomplishing this. Open up Eclipse Preferences, type in Templates as your Filter, then select Java->Code Style->Code Templates. In the Code Templates widget, expand the Comments widget:
Looking through the expanded selection, you can see that there are templates defined for Types and Methods, amongst others. Select whichever template you want to edit, then click 'Edit'. You can now change the template as you see fit, for example by adding #author ${user} or whatever else to it:
Click 'Ok' out of all the dialogs to complete and save.
In the eclipse directory there is a file named: "eclipse.ini" open the file and add following line:
-Duser.name=desired name
after the "-vmargs" line
Project->Properties->Java Code Style->Code Template->
There is link Configure workspace setting
Select Comment->Types
Edit your name or whatever you want.
You can go to the Windows/Preference. Type int "Template" in the search box and go to Java/Code Style/Code Templates. The area you are searching is in the "Comments" part.

Auto-generate Javadoc comments in Eclipse?

Is it possible to auto-generate Javadoc comments for each method in one class in Eclipse (Indigo)?
There may be a better approach, but if you expand the class in Package Explorer, select the methods you would to document, then right-click and select "Source -> Generate Element Comment" that will add comments for all the selected methods.
The other choice might be to double click on the name of the method, then ALT+Shift+J shortcut.
There also exist external tools for javadoc generation, for example JAutodoc eclipse plugin. It is possible to customize it's templates to suit your expectation.
In Eclipse you have possiblity to create java doc template, and then just what need to do is type java-dock block /** above the element you want to document.
In case when the code is generate, the templates also generate the java-doc.
All this and even more you will be able to configure in Window -> Preferences, Java -> Code Style -> Code Templates -> Comments

Getting documention to appear in intellitext window using eclispe and java

When using the standard api, for example the collections library, the predictive text options windows also shows the comments on class/methods.
however when I do the same style comments on my own code - the open project I am working on (code completion works correctly, just no comments appear), and then reference it later. These comments are not displayed. I get the correct code completion options, just none of the associated comments/documentation. They are not in jar, they are source files, that are built using maven into a war file.
Is there a setting I need to enable in eclipse, or do I need to set up javadoc or something ?
How embarassing, you to have to specify double asterix at the begininng of comment to create a javdoc comment
/**
* read the documentation before asking questions on stackoverlow
*/
If the class is part of a jar you need to associate the javadoc jar or path. You can right click on the jar in eclipse and specify the path in the properties dialog.

Intellij generate javadoc for methods and classes

Is it possible to set up Intellij to generate javadoc for methods and classes, automatically, with #author and #since date? I had this feature in Eclipse.
I know that the files have templates and also I can manually semi-automatically add javadoc to selected method/class. But I want the generation to be automatic for every generated method/class/enum/interface/field etc.
This is useful for e.g. "extract method", "override/implement", "create getter/setter" etc. This would save hundreds of manual actions.
I'm using IntelliJ Idea 9.0 BETA Community Edition, #IC-90.96.
For IntelliJ 12:
Position caret above a method name, type /** and press Enter to let
IntelliJ IDEA automatically generate JavaDoc stubs for this method.
See here
For newer versions of IntelliJ (2018+), you can use this solution:
Typing /** + then pressing Enter above a method signature will create Javadoc stubs for you.
It's not possible at the moment. You may want to Vote for IDEABKL-1787.
for generate javadoc in intellij Idea go to Tools->Generate JavaDoc (4th option) click it and give path to save your Document
Now there is a new plugin available for that.
It works great, you can generate javadoc with alt+insert.
It's called "javaDoc", it's available directly in the plugin section.
The documentation is here : https://github.com/setial/intellij-javadocs/wiki
I have given up on hoping that IntelliJ will be able to do this.
I now open my project in Eclipse, go to the desired files and invoke JAutoDoc.
There is JavaDoc Sync Plugin 8. http://plugins.intellij.net/plugin/?idea&id=3403
Generates javadoc for all methods in class. Works in Idea 10.
Actually it's now possible, you can simply go to "Settings/Editor/File and Code Templates".
There, you can edit the template which is used to create classes, enums, interfaces etc.
My Intellij version is 2019.2.3 and on linux.
An easy option is to access Find Action menu (Macs: Cmd+Shift+A | Win: Ctrl+Shift+A) and type any part of the Generate JavaDoc action.
Once you found and clicked on that , an option menu for generation of JavaDocs is opened , containing a wide range of options and scopes.
Reference -> https://www.jetbrains.com/help/idea/mastering-keyboard-shortcuts.html

Categories