Commit eacca5ca authored by j4cbo's avatar j4cbo

Merge pull request #132 from PSPDFKit-labs/peter/java-toString

Adds `toString()` for the Java generator
parents d28adb4d bf859255
...@@ -340,6 +340,21 @@ class JavaGenerator(spec: Spec) extends Generator(spec) { ...@@ -340,6 +340,21 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
} }
w.wl
w.wl("@Override")
w.w("public String toString()").braced {
w.w(s"return ").nestedN(2) {
w.wl(s""""${self}{" +""")
for (i <- 0 to r.fields.length-1) {
val name = idJava.field(r.fields(i).ident)
val comma = if (i > 0) """"," + """ else ""
w.wl(s"""${comma}"${name}=" + ${name} +""")
}
}
w.wl(s""""}";""")
}
w.wl
if (r.derivingTypes.contains(DerivingType.Ord)) { if (r.derivingTypes.contains(DerivingType.Ord)) {
def primitiveCompare(ident: Ident) { def primitiveCompare(ident: Ident) {
w.wl(s"if (this.${idJava.field(ident)} < other.${idJava.field(ident)}) {").nested { w.wl(s"if (this.${idJava.field(ident)} < other.${idJava.field(ident)}) {").nested {
......
...@@ -173,4 +173,25 @@ public final class AssortedPrimitives { ...@@ -173,4 +173,25 @@ public final class AssortedPrimitives {
hashCode = hashCode * 31 + (mOFsixtyfour == null ? 0 : mOFsixtyfour.hashCode()); hashCode = hashCode * 31 + (mOFsixtyfour == null ? 0 : mOFsixtyfour.hashCode());
return hashCode; return hashCode;
} }
@Override
public String toString() {
return "AssortedPrimitives{" +
"mB=" + mB +
"," + "mEight=" + mEight +
"," + "mSixteen=" + mSixteen +
"," + "mThirtytwo=" + mThirtytwo +
"," + "mSixtyfour=" + mSixtyfour +
"," + "mFthirtytwo=" + mFthirtytwo +
"," + "mFsixtyfour=" + mFsixtyfour +
"," + "mOB=" + mOB +
"," + "mOEight=" + mOEight +
"," + "mOSixteen=" + mOSixteen +
"," + "mOThirtytwo=" + mOThirtytwo +
"," + "mOSixtyfour=" + mOSixtyfour +
"," + "mOFthirtytwo=" + mOFthirtytwo +
"," + "mOFsixtyfour=" + mOFsixtyfour +
"}";
}
} }
...@@ -38,4 +38,14 @@ public final class ClientReturnedRecord { ...@@ -38,4 +38,14 @@ public final class ClientReturnedRecord {
public String getMisc() { public String getMisc() {
return mMisc; return mMisc;
} }
@Override
public String toString() {
return "ClientReturnedRecord{" +
"mRecordId=" + mRecordId +
"," + "mContent=" + mContent +
"," + "mMisc=" + mMisc +
"}";
}
} }
...@@ -60,4 +60,13 @@ public final class Constants { ...@@ -60,4 +60,13 @@ public final class Constants {
public String getSomeString() { public String getSomeString() {
return mSomeString; return mSomeString;
} }
@Override
public String toString() {
return "Constants{" +
"mSomeInteger=" + mSomeInteger +
"," + "mSomeString=" + mSomeString +
"}";
}
} }
...@@ -38,6 +38,14 @@ public final class DateRecord implements Comparable<DateRecord> { ...@@ -38,6 +38,14 @@ public final class DateRecord implements Comparable<DateRecord> {
return hashCode; return hashCode;
} }
@Override
public String toString() {
return "DateRecord{" +
"mCreatedAt=" + mCreatedAt +
"}";
}
@Override @Override
public int compareTo(@Nonnull DateRecord other) { public int compareTo(@Nonnull DateRecord other) {
int tempResult; int tempResult;
......
...@@ -17,4 +17,11 @@ public final class EmptyRecord { ...@@ -17,4 +17,11 @@ public final class EmptyRecord {
public EmptyRecord( public EmptyRecord(
) { ) {
} }
@Override
public String toString() {
return "EmptyRecord{" +
"}";
}
} }
...@@ -45,6 +45,15 @@ public final class ExternRecordWithDerivings implements Comparable<ExternRecordW ...@@ -45,6 +45,15 @@ public final class ExternRecordWithDerivings implements Comparable<ExternRecordW
return hashCode; return hashCode;
} }
@Override
public String toString() {
return "ExternRecordWithDerivings{" +
"mMember=" + mMember +
"," + "mE=" + mE +
"}";
}
@Override @Override
public int compareTo(ExternRecordWithDerivings other) { public int compareTo(ExternRecordWithDerivings other) {
int tempResult; int tempResult;
......
...@@ -21,4 +21,12 @@ public final class MapDateRecord { ...@@ -21,4 +21,12 @@ public final class MapDateRecord {
public HashMap<String, java.util.Date> getDatesById() { public HashMap<String, java.util.Date> getDatesById() {
return mDatesById; return mDatesById;
} }
@Override
public String toString() {
return "MapDateRecord{" +
"mDatesById=" + mDatesById +
"}";
}
} }
...@@ -22,4 +22,12 @@ public final class MapListRecord { ...@@ -22,4 +22,12 @@ public final class MapListRecord {
public ArrayList<HashMap<String, Long>> getMapList() { public ArrayList<HashMap<String, Long>> getMapList() {
return mMapList; return mMapList;
} }
@Override
public String toString() {
return "MapListRecord{" +
"mMapList=" + mMapList +
"}";
}
} }
...@@ -30,4 +30,13 @@ public final class MapRecord { ...@@ -30,4 +30,13 @@ public final class MapRecord {
public HashMap<Integer, Integer> getImap() { public HashMap<Integer, Integer> getImap() {
return mImap; return mImap;
} }
@Override
public String toString() {
return "MapRecord{" +
"mMap=" + mMap +
"," + "mImap=" + mImap +
"}";
}
} }
...@@ -22,4 +22,12 @@ public final class NestedCollection { ...@@ -22,4 +22,12 @@ public final class NestedCollection {
public ArrayList<HashSet<String>> getSetList() { public ArrayList<HashSet<String>> getSetList() {
return mSetList; return mSetList;
} }
@Override
public String toString() {
return "NestedCollection{" +
"mSetList=" + mSetList +
"}";
}
} }
...@@ -21,4 +21,12 @@ public final class PrimitiveList { ...@@ -21,4 +21,12 @@ public final class PrimitiveList {
public ArrayList<Long> getList() { public ArrayList<Long> getList() {
return mList; return mList;
} }
@Override
public String toString() {
return "PrimitiveList{" +
"mList=" + mList +
"}";
}
} }
...@@ -48,6 +48,15 @@ public final class RecordWithDerivings implements Comparable<RecordWithDerivings ...@@ -48,6 +48,15 @@ public final class RecordWithDerivings implements Comparable<RecordWithDerivings
return hashCode; return hashCode;
} }
@Override
public String toString() {
return "RecordWithDerivings{" +
"mKey1=" + mKey1 +
"," + "mKey2=" + mKey2 +
"}";
}
@Override @Override
public int compareTo(@Nonnull RecordWithDerivings other) { public int compareTo(@Nonnull RecordWithDerivings other) {
int tempResult; int tempResult;
......
...@@ -38,6 +38,14 @@ public final class RecordWithDurationAndDerivings implements Comparable<RecordWi ...@@ -38,6 +38,14 @@ public final class RecordWithDurationAndDerivings implements Comparable<RecordWi
return hashCode; return hashCode;
} }
@Override
public String toString() {
return "RecordWithDurationAndDerivings{" +
"mDt=" + mDt +
"}";
}
@Override @Override
public int compareTo(@Nonnull RecordWithDurationAndDerivings other) { public int compareTo(@Nonnull RecordWithDurationAndDerivings other) {
int tempResult; int tempResult;
......
...@@ -48,6 +48,15 @@ public final class RecordWithNestedDerivings implements Comparable<RecordWithNes ...@@ -48,6 +48,15 @@ public final class RecordWithNestedDerivings implements Comparable<RecordWithNes
return hashCode; return hashCode;
} }
@Override
public String toString() {
return "RecordWithNestedDerivings{" +
"mKey=" + mKey +
"," + "mRec=" + mRec +
"}";
}
@Override @Override
public int compareTo(@Nonnull RecordWithNestedDerivings other) { public int compareTo(@Nonnull RecordWithNestedDerivings other) {
int tempResult; int tempResult;
......
...@@ -30,4 +30,13 @@ public final class SetRecord { ...@@ -30,4 +30,13 @@ public final class SetRecord {
public HashSet<Integer> getIset() { public HashSet<Integer> getIset() {
return mIset; return mIset;
} }
@Override
public String toString() {
return "SetRecord{" +
"mSet=" + mSet +
"," + "mIset=" + mIset +
"}";
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment