java.lang.Object
org.eclipse.xtext.xbase.lib.util.ToStringBuilder
Helps with the construction of good
Object.toString()
representations.
You can customize the output using the builder-style methods singleLine()
skipNulls()
and hideFieldNames()
.
You can either directly list fields to include via add(String, Object)
and add(Object)
or you can let the builder do it automatically using reflection, either including the fields declared in this class or including all superclasses.
The builder will automatically handle cycles in the object tree. It also pretty prints arrays and Iterables.
This class is not thread safe.- Since:
- 2.7
-
Constructor Summary
ConstructorDescriptionToStringBuilder
(Object instance) Creates a new ToStringBuilder for the given object. -
Method Summary
Modifier and TypeMethodDescriptionAdds all fields declared in the object's class and its superclasses to the output.Adds all fields declared directly in the object's class to the outputField names will not be included in the output.Fields are printed on a single line, separated by commas instead of newlinesFields with null values will be excluded from the outputtoString()
By default, Iterables, Arrays and multiline Strings are pretty-printed.
-
Constructor Details
-
ToStringBuilder
Creates a new ToStringBuilder for the given object. If you don't use reflection, then this instance is only used for obtaining its classes' simple name.- Parameters:
instance
- the object to convert to a String
-
-
Method Details
-
singleLine
Fields are printed on a single line, separated by commas instead of newlines- Returns:
- this
-
skipNulls
Fields with null values will be excluded from the output- Returns:
- this
-
hideFieldNames
Field names will not be included in the output. Useful for small classes.- Returns:
- this
-
verbatimValues
By default, Iterables, Arrays and multiline Strings are pretty-printed. Switching to their normal representation makes the toString method significantly faster.- Returns:
- this
- Since:
- 2.9
-
addDeclaredFields
Adds all fields declared directly in the object's class to the output- Returns:
- this
-
addAllFields
Adds all fields declared in the object's class and its superclasses to the output.- Returns:
- this
-
addField
@GwtIncompatible("Class.getDeclaredField(String)") public ToStringBuilder addField(String fieldName) - Parameters:
fieldName
- the name of the field to add to the output using reflection- Returns:
- this
-
add
- Parameters:
value
- the value to add to the outputfieldName
- the field name to list the value under- Returns:
- this
-
add
- Parameters:
value
- the value to add to the output without a field name- Returns:
- this
-
toString
-