Permalink
Browse files

[swift-generator] Generate toString() for structs and exceptions

  • Loading branch information...
1 parent f72656f commit 9b7f848d90061517dcf6279accda84ea55890a98 @andrewcox andrewcox committed Mar 19, 2013
Showing with 16 additions and 0 deletions.
  1. +16 −0 swift-generator/src/main/resources/templates/java/common.st
@@ -31,12 +31,15 @@ struct(context, tweaks) ::= <<
package <context.javaPackage>;
import com.facebook.swift.codec.*;
+import com.google.common.base.*;
import java.util.*;
@ThriftStruct("<context.name>")
public class <context.javaName>
{
<_structbody(context)>
+
+ <_toString(context)>
}<\n>
>>
@@ -149,3 +152,16 @@ _exceptionElement(exception) ::= <<
@ThriftException(type=<exception.type>.class, id=<exception.id>)
>>
+_toString(context) ::= <<
+@Override
+public String toString()
+{
+ return Objects.toStringHelper(this)
+ <context.fields : { field |<_toStringField(field)>}; separator="\n">
+ .toString();
+}
+>>
+
+_toStringField(field) ::= <<
+.add("<field.javaName>", <field.javaName>)
+>>

0 comments on commit 9b7f848

Please sign in to comment.