Created
July 29, 2016 13:36
-
-
Save samhendley/d377e938d63d1b50f2bd8c259a5db5d7 to your computer and use it in GitHub Desktop.
Nullable ToString generator for Intellij
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SampleToString { | |
@Override | |
public String toString() { | |
return "KeyManagementState{" + | |
"repId=" + repId + | |
(managementState == null ? "" : ", managementState:" + managementState) + | |
(desiredState == null ? "" : ", desiredState:" + desiredState) + | |
(lastAction == null ? "" : ", lastAction:" + lastAction) + | |
(lastActionResult == null ? "" : ", lastActionResult:" + lastActionResult) + | |
(lastActionTime == null ? "" : ", lastActionTime:" + lastActionTime) + | |
(nextAction == null ? "" : ", nextAction:" + nextAction) + | |
(nextActionTime == null ? "" : ", nextActionTime:" + nextActionTime) + | |
(lastUpdateTime == null ? "" : ", lastUpdateTime:" + lastUpdateTime) + | |
(statusString == null ? "" : ", statusString:" + "'" + statusString + '\'') + | |
(nextRotationTime == null ? "" : ", nextRotationTime:" + nextRotationTime) + | |
", changed=" + changed + '}'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public java.lang.String toString() { | |
#if ( $members.size() > 0 ) | |
#set ( $i = 0 ) | |
return "$classname{" + | |
#foreach( $member in $members ) | |
#if ( $i != 0 ) | |
#set ( $prefix = ", " ) | |
+ | |
#else | |
#set ( $prefix = "" ) | |
#end | |
#if ( $member.object || $member.objectArray || $member.primitiveArray ) | |
($member.accessor == null ? "" : "$prefix$member.name:" + ## | |
#else | |
"$prefix$member.name=" + ## | |
#end | |
#if ( $member.objectArray ) | |
#if ($java_version < 5) | |
($member.accessor == null ? null : java.util.Arrays.asList($member.accessor)) ## | |
#else | |
java.util.Arrays.toString($member.accessor) ## | |
#end | |
#elseif ( $member.primitiveArray && $java_version >= 5) | |
java.util.Arrays.toString($member.accessor) ## | |
#elseif ( $member.string ) | |
"'" + $member.accessor + '\'' ## | |
#else | |
$member.accessor ## | |
#end | |
#if ( $member.object || $member.objectArray || $member.primitiveArray ) | |
) ## | |
#end | |
#set ( $i = $i + 1 ) | |
#end | |
+'}'; | |
#else | |
return "$classname{}"; | |
#end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment