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
@GwtCompatible
public class ToStringHelper
extends 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(Field field, Object obj, org.eclipse.xtext.xbase.lib.util.ToStringHelper.IndentationAwareStringBuilder sb)
          Appends the fields and its value to the given string builder.
protected  List<Field> getAllDeclaredFields(Class<?> clazz)
          Computes a list of all declared fields of the given class and its super classes.
protected  void internalToString(Object object, org.eclipse.xtext.xbase.lib.util.ToStringHelper.IndentationAwareStringBuilder sb)
          Append the field value object the the given string builder.
 String toString(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 String toString(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(Field field,
                        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(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 List<Field> getAllDeclaredFields(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.


Copyright © 2013. All Rights Reserved.