Yes, almost, if you disregard a carriage return.
Go to Window -> Preferences -> Java -> Code Style - Code Templates
This is on Eclipse Indigo - it might be different in other versions.
Now in the "Configure generated code..." panel on the right, open up the "Code" branch and select and edit the "New Java files" entry.
In the Edit dialog, in the Pattern text box, you see the following:
${filecomment}
${package_declaration}
${typecomment}
${type_declaration}
which you need to modify to this:
${filecomment}
${package_declaration}
${typecomment}
${type_declaration}//end of ${type_name}
and then save and close. Try creating a new class and you'll see it comes out like this:
package com.nomadsoft.cortex.application;
public class AdamsClass {
}
//end of AdamsClass
Unfortunately you can't get rid of the carriage return that puts the comment you want on the next line down. It is hard-coded within Eclipse.
Depending on how much effort you want to go to, you have a choice of how to get the comment on the same line as the end-bracket:
(Option 1) you could edit the template files in the JDT jar:
eclipse\plugins\org.eclipse.jdt.ui_*.jar
open up templates/default-codetemplates.xml and find the "newtype" template in the xml, and replace the "${type_declaration}" with
public class ${type_name} \{
\} // end of ${type_name}
(Option 2) write a complete plugin to do this. I'd love to have the time to do that. Maybe you do. See enter link description here
Thanks @Adam! These are excellent solutions, very interesting... I am using Eclipse Indigo, so I will be able to experiment with this. I feel somewhat scared to mess with the JDT jar, but I will definitely look at it -- the edit you are suggesting does seem minimal though. And I don't have time to write a plugin, but that would be an awesome project! However,
Mechanical snail
here is suggesting a plugin that seems to do this stuff as well. – Ian Campbell – 2012-09-12T19:58:12.083Any idea though on how to generate a similar comment for the end of the main method? (as in "
// end of main method
") – Ian Campbell – 2012-09-12T19:58:30.6301I thought there might be a solution to it, because if you look at Preferences -> Java -> Templates, there is a "main", but the two frameworks aren't linked - the code generation framework doesn't use the hotkey template framework. So if you create your main method as part of the class file generation, then no, you can't do it. But you can edit the hotkey template and use "main ctrl-space" to insert it after you've created the class. – Adam – 2012-09-14T09:21:15.377