toString plugin recommendation if not already available...

I looked over the settings and didn't see this an option..

What I'd love is an option when the toString method is generated that it also appends a super.toString() to the end (obviously if the class is a subclass).

It's not a big deal to manually add this to the end of the line, but it becomes annoying when you are chaning properties frequently and having the toString overwrite your previous one.

5 comments
Comment actions Permalink

I agree. I have been doing this manually.

Rick wrote:

I looked over the settings and didn't see this an option..

>

What I'd love is an option when the toString method is generated that it also appends a super.toString() to the end (obviously if the class is a subclass).

>

It's not a big deal to manually add this to the end of the line, but it becomes annoying when you are chaning properties frequently and having the toString overwrite your previous one.

0
Comment actions Permalink

This used to be in one of the templates but disappeared in one of the versions. I think some velocity magic could bring it back if you override the built in templates.

0
Comment actions Permalink

Yes I think it can be done entirely in the velocity template.

Basically you have several methods on the context you can use in a if branch.
You'll have to lookup the plugin documentation (blue link in settings).

I had a computer crash and is now only on a new computer that I'll have to setup before I can look into it.

Something the like:

#if ($hasSuperClass())
+ super.toString()
#end


But I'll look into this when I am upgrading the plugin in this weekend. One of the new eap builds broke it.

/Claus, author of the plugin

0
Comment actions Permalink

Okay I got it working with the super.toString(). IDEA changed the plugin central so I'll have to wait for them to confirm me as the author before I can upload a new version.

I'll post the template that has super.toString() support here:

 0 )
#set ( $i = 0 )
    return "$classname{" +
#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
   #if ( $class.hasSuper )
   "} " + super.toString();
   #else
   '}';
   #end
#else
   #if ( $class.hasSuper )
   return "$classname{} " + super.toString();
   #else
   return "$classname{}";
   #end
#end
}
]]>

0
Comment actions Permalink

Works great! Thanks a lot.

0

Please sign in to leave a comment.