Search code examples
javaeclipsejavadoc

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 NewJavaClass.java it will create java docs as:

/**
 * New Java Class 
 *
/*
public class NewJavaClass 

Solution

  • 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 which 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.