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) {
}
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)) {
def primitiveCompare(ident: Ident) {
w.wl(s"if (this.${idJava.field(ident)} < other.${idJava.field(ident)}) {").nested {
......
......@@ -173,4 +173,25 @@ public final class AssortedPrimitives {
hashCode = hashCode * 31 + (mOFsixtyfour == null ? 0 : mOFsixtyfour.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 {
public String getMisc() {
return mMisc;
}
@Override
public String toString() {
return "ClientReturnedRecord{" +
"mRecordId=" + mRecordId +
"," + "mContent=" + mContent +
"," + "mMisc=" + mMisc +
"}";
}
}
......@@ -60,4 +60,13 @@ public final class Constants {
public String getSomeString() {
return mSomeString;
}
@Override
public String toString() {
return "Constants{" +
"mSomeInteger=" + mSomeInteger +
"," + "mSomeString=" + mSomeString +
"}";
}
}
......@@ -38,6 +38,14 @@ public final class DateRecord implements Comparable<DateRecord> {
return hashCode;
}
@Override
public String toString() {
return "DateRecord{" +
"mCreatedAt=" + mCreatedAt +
"}";
}
@Override
public int compareTo(@Nonnull DateRecord other) {
int tempResult;
......
......@@ -17,4 +17,11 @@ public final class EmptyRecord {
public EmptyRecord(
) {
}
@Override
public String toString() {
return "EmptyRecord{" +
"}";
}
}
......@@ -45,6 +45,15 @@ public final class ExternRecordWithDerivings implements Comparable<ExternRecordW
return hashCode;
}
@Override
public String toString() {
return "ExternRecordWithDerivings{" +
"mMember=" + mMember +
"," + "mE=" + mE +
"}";
}
@Override
public int compareTo(ExternRecordWithDerivings other) {
int tempResult;
......
......@@ -21,4 +21,12 @@ public final class MapDateRecord {
public HashMap<String, java.util.Date> getDatesById() {
return mDatesById;
}
@Override
public String toString() {
return "MapDateRecord{" +
"mDatesById=" + mDatesById +
"}";
}
}
......@@ -22,4 +22,12 @@ public final class MapListRecord {
public ArrayList<HashMap<String, Long>> getMapList() {
return mMapList;
}
@Override
public String toString() {
return "MapListRecord{" +
"mMapList=" + mMapList +
"}";
}
}
......@@ -30,4 +30,13 @@ public final class MapRecord {
public HashMap<Integer, Integer> getImap() {
return mImap;
}
@Override
public String toString() {
return "MapRecord{" +
"mMap=" + mMap +
"," + "mImap=" + mImap +
"}";
}
}
......@@ -22,4 +22,12 @@ public final class NestedCollection {
public ArrayList<HashSet<String>> getSetList() {
return mSetList;
}
@Override
public String toString() {
return "NestedCollection{" +
"mSetList=" + mSetList +
"}";
}
}
......@@ -21,4 +21,12 @@ public final class PrimitiveList {
public ArrayList<Long> getList() {
return mList;
}
@Override
public String toString() {
return "PrimitiveList{" +
"mList=" + mList +
"}";
}
}
......@@ -48,6 +48,15 @@ public final class RecordWithDerivings implements Comparable<RecordWithDerivings
return hashCode;
}
@Override
public String toString() {
return "RecordWithDerivings{" +
"mKey1=" + mKey1 +
"," + "mKey2=" + mKey2 +
"}";
}
@Override
public int compareTo(@Nonnull RecordWithDerivings other) {
int tempResult;
......
......@@ -38,6 +38,14 @@ public final class RecordWithDurationAndDerivings implements Comparable<RecordWi
return hashCode;
}
@Override
public String toString() {
return "RecordWithDurationAndDerivings{" +
"mDt=" + mDt +
"}";
}
@Override
public int compareTo(@Nonnull RecordWithDurationAndDerivings other) {
int tempResult;
......
......@@ -48,6 +48,15 @@ public final class RecordWithNestedDerivings implements Comparable<RecordWithNes
return hashCode;
}
@Override
public String toString() {
return "RecordWithNestedDerivings{" +
"mKey=" + mKey +
"," + "mRec=" + mRec +
"}";
}
@Override
public int compareTo(@Nonnull RecordWithNestedDerivings other) {
int tempResult;
......
......@@ -30,4 +30,13 @@ public final class SetRecord {
public HashSet<Integer> getIset() {
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