toString

I add after the {. Now when I do it, nothing comes out.
The template validates. Here is my template:
public String toString() {
#if ( $members.size() > 0 )
#set ( $i = 0 )
return "$classname{[$Revision$]" +
#foreach( $member in $members )
#if ( $i == 0 )
"##
#else
", ##
#end
#if ( $member.objectArray )
$member.name=" + ($member.accessor == null ? null :
Arrays.asList($member.accessor)) +
#elseif ( $member.string )
$member.name='" + $member.accessor + "'" +
#else
$member.name=" + $member.accessor +
#end
#set ( $i = $i + 1 )
#end
"}";
#else
return "$classname{}";
#end
}

Also, I see that the template now outputs every item on it's own line.
How can I the property name and it's value on the same line?

Here is what comes out:
public String toString() {
return "recordType{[$Revision$]" +
"code='" +
code +
"'" +
", description='" +
description +
"'" +
"}";
}


What I want is:
public String toString() {
return "recordType{[$Revision$]" +
"code='" + code + "'" +
", description='" + description + "'" +
"}";
}

--
Norris Shelton
Sun Certified Java Programmer

评论操作 固定链接

FYI, the that is in the toString method was added manually.

Norris Shelton
Sun Certified Java Programmer




Norris Shelton wrote:

I add after the {. Now when I do it, nothing comes out.
The template validates. Here is my template:
public String toString() {
#if ( $members.size() > 0 )
#set ( $i = 0 )
return "$classname{[$Revision$]" +
#foreach( $member in $members )
#if ( $i == 0 )
"##
#else
", ##
#end
#if ( $member.objectArray )
$member.name=" + ($member.accessor == null ? null :
Arrays.asList($member.accessor)) +
#elseif ( $member.string )
$member.name='" + $member.accessor + "'" +
#else
$member.name=" + $member.accessor +
#end
#set ( $i = $i + 1 )
#end
"}";
#else
return "$classname{}";
#end
}

>

Also, I see that the template now outputs every item on it's own
line. How can I the property name and it's value on the same line?

>

Here is what comes out:
public String toString() {
return "recordType{[$Revision$]" +
"code='" +
code +
"'" +
", description='" +
description +
"'" +
"}";
}

>
>

What I want is:
public String toString() {
return "recordType{[$Revision$]" +
"code='" + code + "'" +
", description='" + description + "'" +
"}";
}

>

0
评论操作 固定链接

Also, I tried to add javadoc to the template. In doing so, I tried to
use $classname. It was not evaluated.

/**

  • Displays the current state of the $classname object.

  • @return a string representation of the $classname object.

*/
public String toString() {

It came out exactly.

Norris Shelton
Sun Certified Java Programmer




Norris Shelton wrote:

I add after the {. Now when I do it, nothing comes out.
The template validates. Here is my template:
public String toString() {
#if ( $members.size() > 0 )
#set ( $i = 0 )
return "$classname{[$Revision$]" +
#foreach( $member in $members )
#if ( $i == 0 )
"##
#else
", ##
#end
#if ( $member.objectArray )
$member.name=" + ($member.accessor == null ? null :
Arrays.asList($member.accessor)) +
#elseif ( $member.string )
$member.name='" + $member.accessor + "'" +
#else
$member.name=" + $member.accessor +
#end
#set ( $i = $i + 1 )
#end
"}";
#else
return "$classname{}";
#end
}

>

Also, I see that the template now outputs every item on it's own
line. How can I the property name and it's value on the same line?

>

Here is what comes out:
public String toString() {
return "recordType{[$Revision$]" +
"code='" +
code +
"'" +
", description='" +
description +
"'" +
"}";
}

>
>

What I want is:
public String toString() {
return "recordType{[$Revision$]" +
"code='" + code + "'" +
", description='" + description + "'" +
"}";
}

>

0
评论操作 固定链接

Argh. It appears to be working now.

Norris Shelton
Sun Certified Java Programmer




Norris Shelton wrote:

FYI, the that is in the toString method was added manually.

>

Norris Shelton
Sun Certified Java Programmer

>
>
>
>

Norris Shelton wrote:

>
>> I add after the {. Now when I do it, nothing comes
>> out. The template validates. Here is my template:
>> public String toString() {
>> #if ( $members.size() > 0 )
>> #set ( $i = 0 )
>> return "$classname{[$Revision$]" +
>> #foreach( $member in $members )
>> #if ( $i == 0 )
>> "##
>> #else
>> ", ##
>> #end
>> #if ( $member.objectArray )
>> $member.name=" + ($member.accessor == null ? null :
>> Arrays.asList($member.accessor)) +
>> #elseif ( $member.string )
>> $member.name='" + $member.accessor + "'" +
>> #else
>> $member.name=" + $member.accessor +
>> #end
>> #set ( $i = $i + 1 )
>> #end
>> "}";
>> #else
>> return "$classname{}";
>> #end
>> }
>>
>> Also, I see that the template now outputs every item on it's own
>> line. How can I the property name and it's value on the same line?
>>
>> Here is what comes out:
>> public String toString() {
>> return "recordType{[$Revision$]" +
>> "code='" +
>> code +
>> "'" +
>> ", description='" +
>> description +
>> "'" +
>> "}";
>> }
>>
>>
>> What I want is:
>> public String toString() {
>> return "recordType{[$Revision$]" +
>> "code='" + code + "'" +
>> ", description='" + description + "'" +
>> "}";
>> }
>>

0
评论操作 固定链接

Glad you got it sorted somehow?

Any idea why? Did you restart IDEA?


Yes any text in javadoc is not evaluated using Velocity. It is copied excatly as you typed it. This is a new feature I will add to my TODO list to get fixed within this week.

There is a footy game tonight so I gotta see Greece vs. Denmark.

/Claus

0
评论操作 固定链接

I may have had to restart IJ. This usually works immediately. I would
say ignore it unless it's seen again by someone.

Norris Shelton
Sun Certified Java Programmer




Claus Ibsen wrote:

>Glad you got it sorted somehow?
>
>Any idea why? Did you restart IDEA?
>
>
>Yes any text in javadoc is not evaluated using Velocity. It is copied excatly as you typed it. This is a new feature I will add to my TODO list to get fixed within this week.
>
>There is a footy game tonight so I gotta see Greece vs. Denmark.
>
>/Claus

>

0
评论操作 固定链接

Restart:
I can image there could be a potential problem with the fact that the active template is stored by IDEA and the others are stored as files. And keeping the active template 100% up-to-date.

I will do some more testing in this matter when I have time adding your javadoc request.

0
评论操作 固定链接

BTW: Is that a cvs tag that is expanded when it's comitted?

I haven't seen this idea of using it in the toString() before. It's a good idea.

/Claus

0
评论操作 固定链接

Yes, it's expanded to something along the lines of "$Revision: 1.12 $"

Norris Shelton
Sun Certified Java Programmer




Claus Ibsen wrote:

>BTW: Is that a cvs tag that is expanded when it's comitted?
>
>I haven't seen this idea of using it in the toString() before. It's a good idea.
>
>/Claus

>

0
评论操作 固定链接

About javadoc.

As it is now the plugin always keeps any existing javadoc. That could be the cause why you coldn't update the javadoc. To force a javadoc update you can manually delete any existing javadoc.

I am now reworking this and adding veloicty macro to javadoc also so you can use $classname in javadoc.

I will change the behaviour of the plugin to replace any existing javadoc when generating code.

However if there is already a javadoc comment and the template does not have javadoc then the existing javadoc will be preserved. This can be used in situations where you manually add a javadoc comment, maybe this toString is a bit speical.

I am working on it now and will hopefully release a new plugin this weekend.

0
评论操作 固定链接

Just released v3.11 with this feature.

0

请先登录再写评论。