@Test public void recursionHandling() { final ToStringHelper helper = new ToStringHelper(); final ToStringHelperTest.OtherClass obj = new ToStringHelperTest.OtherClass(); obj.name = "foo"; obj.other = obj; StringConcatenation _builder = new StringConcatenation(); _builder.append("OtherClass ["); _builder.newLine(); _builder.append(" "); _builder.append("other = "); String _string = obj.toString(); _builder.append(_string, " "); _builder.newLineIfNotEmpty(); _builder.append(" "); _builder.append("name = \"foo\""); _builder.newLine(); _builder.append("]"); Assert.assertEquals( ToStringHelperTest.toUnix(_builder.toString()), helper.toString(obj)); }
public void addDataToString(final MutableClassDeclaration cls) { final Procedure1<MutableMethodDeclaration> _function = new Procedure1<MutableMethodDeclaration>() { @Override public void apply(final MutableMethodDeclaration it) { Util.this.context.setPrimarySourceElement(it, Util.this.context.getPrimarySourceElement(cls)); it.setReturnType(Util.this.context.getString()); it.addAnnotation(Util.this.context.newAnnotationReference(Override.class)); it.addAnnotation(Util.this.context.newAnnotationReference(Pure.class)); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("String result = new "); _builder.append(ToStringHelper.class); _builder.append("().toString(this);"); _builder.newLineIfNotEmpty(); _builder.append("return result;"); _builder.newLine(); } }; it.setBody(_client); } }; cls.addMethod("toString", _function); }
@Test public void testToString() { final ToStringHelper helper = new ToStringHelper(); StringConcatenation _builder = new StringConcatenation(); _builder.append("MyEntity ["); _builder.newLine(); _builder.append(" "); _builder.append("boolProp = true"); _builder.newLine(); _builder.append(" "); _builder.append("intProp = 42"); _builder.newLine(); _builder.append(" "); _builder.append("myList = ArrayList ("); _builder.newLine(); _builder.append(" "); _builder.append("\"foo\","); _builder.newLine(); _builder.append(" "); _builder.append("\"bar\","); _builder.newLine(); _builder.append(" "); _builder.append("\"baz\""); _builder.newLine(); _builder.append(" "); _builder.append(")"); _builder.newLine(); _builder.append(" "); _builder.append("friend = true"); _builder.newLine(); _builder.append(" "); _builder.append("42"); _builder.newLine(); _builder.append(" "); _builder.append("[foo, bar, baz]"); _builder.newLine(); _builder.append(" "); _builder.append("null"); _builder.newLine(); _builder.append(" "); _builder.append("CLASS"); _builder.newLine(); _builder.append(" "); _builder.append("policy = CLASS"); _builder.newLine(); _builder.append("]"); ToStringHelperTest.MyEntity _myEntity = new ToStringHelperTest.MyEntity(); ToStringHelperTest.MyEntity _myEntity_1 = new ToStringHelperTest.MyEntity(_myEntity); Assert.assertEquals( ToStringHelperTest.toUnix(_builder.toString()), helper.toString(_myEntity_1)); }
@Override @Pure public String toString() { String result = new ToStringHelper().toString(this); return result; }
@Override public String toString() { String result = new ToStringHelper().toString(this); return result; }