org.eclipse.xtext.xbase.lib.util
Class ToStringHelper

java.lang.Object
  extended by org.eclipse.xtext.xbase.lib.util.ToStringHelper
Direct Known Subclasses:
ToStringHelper

@Beta
public class ToStringHelper
extends java.lang.Object

A helper class to assist construction of proper Object.toString() implementation for value objects.

Since:
2.3
Author:
Sven Efftinge - Initial contribution and API

Constructor Summary
ToStringHelper()
           
 
Method Summary
protected  void addField(java.lang.reflect.Field field, java.lang.Object obj, org.eclipse.xtext.xbase.lib.util.ToStringHelper.IndentationAwareStringBuilder sb)
          Appends the fields and its value to the given string builder.
protected  java.util.List<java.lang.reflect.Field> getAllDeclaredFields(java.lang.Class<?> clazz)
          Computes a list of all declared fields of the given class and its super classes.
protected  void internalToString(java.lang.Object object, org.eclipse.xtext.xbase.lib.util.ToStringHelper.IndentationAwareStringBuilder sb)
          Append the field value object the the given string builder.
 java.lang.String toString(java.lang.Object obj)
          Creates a string representation of the given object by listing the internal state of all fields.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToStringHelper

public ToStringHelper()
Method Detail

toString

public java.lang.String toString(java.lang.Object obj)
Creates a string representation of the given object by listing the internal state of all fields.

Parameters:
obj - the object that should be printed.
Returns:
the string representation. Never null.

addField

protected void addField(java.lang.reflect.Field field,
                        java.lang.Object obj,
                        org.eclipse.xtext.xbase.lib.util.ToStringHelper.IndentationAwareStringBuilder sb)
Appends the fields and its value to the given string builder.

Parameters:
field - the field. May be a private field.
obj - the object that owns the field.
sb - the accumulating result.

internalToString

protected void internalToString(java.lang.Object object,
                                org.eclipse.xtext.xbase.lib.util.ToStringHelper.IndentationAwareStringBuilder sb)
Append the field value object the the given string builder.

Parameters:
object - the value. May be null.
sb - the accumulating result.

getAllDeclaredFields

protected java.util.List<java.lang.reflect.Field> getAllDeclaredFields(java.lang.Class<?> clazz)
Computes a list of all declared fields of the given class and its super classes. Fields of super types are appended to the list.

Parameters:
clazz - the clazz whose fields shall be collected.
Returns:
the list of fields. Never null.