Skip to content

Instantly share code, notes, and snippets.

@CalebWhiting
Created December 30, 2016 21:09
Show Gist options
  • Save CalebWhiting/fb4e5d7582bf2d6a6449a8225f1e07ee to your computer and use it in GitHub Desktop.
Save CalebWhiting/fb4e5d7582bf2d6a6449a8225f1e07ee to your computer and use it in GitHub Desktop.
Template for IntelliJ IDEA to generate toString methods with String.format
public java.lang.String toString() {
return String.format(##
"$classname [ ##
#set ($i = 0)
#foreach ($member in $members)
#if ($i != 0)
, ##
#end
#if ($member.numeric)
$member.name=%d##
#else
$member.name=%s##
#end
#set ($i = $i + 1)
#end
]",##
#set ($i = 0)
#foreach ($member in $members)
#if ($i != 0)
, ##
#end
#if ($member.objectArray)
java.util.Arrays.toString($member.accessor)
#elseif ( $member.primitiveArray && $java_version >= 5)
java.util.Arrays.toString($member.accessor)##
#elseif ($member.string)
$member.accessor ##
#else
$member.accessor ##
#end
#set ($i = $i + 1)
#end
);
}
@muwednesday
Copy link

what does "##" mean at the end of the line ?

@CalebWhiting
Copy link
Author

what does "##" mean at the end of the line ?

If I remember correctly, it was so that a new line was not added after each statement because the parser would skip comments and therefore the new line too (this was 4 years ago).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment