Eclipse - auto generate class Javadoc using class name manipulation

I want to generate Javadoc every creation of new file with class name as words, meaning separated by space before each uppercase, for example

When creating class it will create java docs as:

 * New Java Class 
public class NewJavaClass 

2 answers

  • answered 2018-07-12 07:29 Nitin Bisht

    Try this:

    1. Go to Window > Preferences.
    2. Type code templates on the left top search box.
    3. Go to Java Code Templates.

    enter image description here

    1. On the right side select Code > New Java files then click Edit.
    2. Now You can paste the code that you want while creating new java file. Don't forget to save. Now you can check by creating new java file.

  • answered 2018-07-12 15:14 kapex

    Code templates are limited to simple variable substitution. Some of variables do accept arguments to manipulate the output in certain ways (e.g. currentDate can be configured with a date format pattern) but none of the built-in variables allow you to do complex string manipulation. You most certainly need a plugin to achieve what you want.

    You should look for plugins that let you define more complex class templates. After a quick search I found the FastCode Eclipse plugin which looks like it allows you to create custom templates in some template language. The screenshots look quite dated though and the website doesn't say Eclipse versions are supported.

    You can also write a plugin yourself. It should be possible to provide some simple custom variables for templates. Or write a plugin that provides a file creation wizard which gives you complete control over the generated class. Another option would be to write a plugin that extends the editor with custom content assist (code completion) to generate code or documentation in existing files.