1

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 
8
  • Please check this link: stackoverflow.com/questions/4468669/… Commented Jul 12, 2018 at 6:34
  • 1
    Ahem, why do you want to do that? So that you have to remember to update these words each time you refactor your classes and rename some of them? Seriously: comments should document the things that aren't obvious. The name of the class is right there, what advantage do you have from "wording" it into the javadoc?! Commented Jul 12, 2018 at 7:00
  • 1
    @GhostCat you may be right, but I want to manipulate class name in other ways, as if class name end with DAO enter similar text with TODO comment Commented Jul 12, 2018 at 8:32
  • 1
    I see. For the record: i think with intellij, you should be able to do such think, but for eclipse, I only know about their "templates", and I am not aware of any "dynamic" features around templates.IntelliJ allows you to run specific code when generating something, no idea about eclipse. Commented Jul 12, 2018 at 9:03
  • 1
    @user7294900 Yes. But it is also good convention to use comments for meaningful things. Repeating information that can be found a bit further down in source code is not meaningful. Generating comments once from names is, as said, breaking as soon as you refactor names. Therefore it will sooner or later lead to misinformation, aka: comments lying to the reader. Commented Jul 16, 2018 at 6:49

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

10 Comments

@user7294900 try this /** * New Java Class * ${file_name} * */ Here file_name will automatically set the file name here in comment section
@user7294900 check my updated answer with updated image and let me know whether It worked for you.
I meant to manipulate ${file_name} variable to change dynamically the value with space between upper case characters
@user7294900 You update your question with sample example what you want exactly then I will be able to help you. Because I did not get what do you mean by uppercase character here.
He wants to generate that first line based on the class name. So when the class is named "FooBar", the javadoc should say /** Foo Bar ... at least that is what I understand.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.