0

It's possible to override the user name via eclipse.ini, which I've done:

-Duser.name=My Name

This goes well with customised code templates. For Java these reside in Window -> Preferences -> Java -> Code Style -> Code Templates.

Below is a custom template I use for the Files and Types templates:

/**
 * 
 * @author ${user} */

The intended output of this is:

/**
 * 
 * @author My Name */

Unfortunately eclipse insists on inserting a newline after ${user}, resulting in:

/**
 * 
 * @author My Name
 */

Does anyone know how to prevent this newline insertion?

Sincere thanks.

KomodoDave
  • 7,239
  • 10
  • 60
  • 92
  • Are you sure it is the variable substitution that causes newline? Have you tried with a literal value? – John Watts Aug 30 '12 at 11:49
  • I haven't assumed it's the variable substitution, am merely describing the exact situation. Will test now.. – KomodoDave Aug 30 '12 at 11:57
  • It occurs with a literal string too. – KomodoDave Aug 30 '12 at 11:58
  • That's non-standard format, it goes against the Java convention for JavaDoc comments. – E-Riz Aug 30 '12 at 13:23
  • @E-Riz Thanks for the info but I'm more than happy to go against convention when it makes logical sense. In this case it wastes less space and looks neater to write the comment my way, and is for an internal enterprise solution so there aren't OSS concerns to consider. – KomodoDave Aug 30 '12 at 14:02
  • ..of course this is my personal opinion, I'm not looking for agreement, this question should be thought of as relating to Eclipse template behaviour rather than relating to Java/Sun/Oracle conventions. – KomodoDave Aug 30 '12 at 15:08

1 Answers1

2

I think the template is working but Javadoc formatting settings are causing the difference. See Window -> Preferences -> Java -> Formatter. Click Edit. Under the Comments tab, in the Javadoc comment settings group, uncheck /** and */ on separate lines. Is there any particular reason you want to deviate from block comment examples in the Sun Code Conventions?

John Watts
  • 8,717
  • 1
  • 31
  • 35
  • @John Thank you for the answer, sadly this doesn't fix the problem. See my comment responding to E-Riz in OP for your convention question. – KomodoDave Aug 30 '12 at 14:11
  • @John Just to clarify - it's clear from viewing the live template in Formatter that this _appears_ to fix the problem, but in fact when you return to the editor the behaviour is the same. Thank you for the clear instructions though, I appreciate your effort. – KomodoDave Aug 30 '12 at 15:09
  • @KomodoDave I think it fixes a closely related problem which I thought was yours. If you add a class-level comment to an existing class, it will not be formatted the way you want. But if you create a new class, and select "Generate comments" I think it does exactly what you want. That was my test case. There may be a different setting that controls how comments you type are formatted. I didn't find it, though. – John Watts Aug 30 '12 at 15:15
  • You can also play with the related setting in `Java -> Editor -> Typing`. In the `Automatically close` group, check or uncheck `Javadoc and comment regions` or `Add Javadoc tags`. You can get eclipse to stop adding anything to these comments and to stop closing them entirely. But you can't get it to auto-close them and/or add the javadoc tags while still respecting the formatting option I referred to in this answer. – John Watts Aug 30 '12 at 15:22