@HashCodeAndEqualsPlugin.Enhance public class ToStringMethod extends java.lang.Object implements Implementation
Object.toString()
that concatenates the String
representation of all fields that are declared by a class.Modifier and Type | Class and Description |
---|---|
protected static class |
ToStringMethod.Appender
An appender to implement
ToStringMethod . |
static interface |
ToStringMethod.PrefixResolver
A prefix resolver is responsible for providing a value that is prepended to a
Object.toString() implementation. |
protected static class |
ToStringMethod.ValueConsumer
A value consumer that is responsible for adding a field value to the string creating
StringBuilder . |
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
definer
A token that is added between a field's name and its value.
|
private java.lang.String |
end
A token that is added after the last field value.
|
private ElementMatcher.Junction<? super FieldDescription.InDefinedShape> |
ignored
A filter that determines what fields to ignore.
|
private ToStringMethod.PrefixResolver |
prefixResolver
A resolver for the prefix of a
String representation. |
private java.lang.String |
separator
A token that is added between two field values.
|
private java.lang.String |
start
A token that is added between the prefix and the first field value.
|
private static MethodDescription.InDefinedShape |
STRING_BUILDER_CONSTRUCTOR
The
StringBuilder.StringBuilder(String) constructor. |
private static MethodDescription.InDefinedShape |
TO_STRING
The
StringBuilder.toString() method. |
Modifier | Constructor and Description |
---|---|
protected |
ToStringMethod(ToStringMethod.PrefixResolver prefixResolver)
Creates a new
toString implementation. |
private |
ToStringMethod(ToStringMethod.PrefixResolver prefixResolver,
java.lang.String start,
java.lang.String end,
java.lang.String separator,
java.lang.String definer,
ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored)
Creates a new
toString implementation. |
Modifier and Type | Method and Description |
---|---|
ToStringMethod.Appender |
appender(Implementation.Target implementationTarget)
Creates a byte code appender that determines the implementation of the instrumented type's methods.
|
static ToStringMethod |
prefixedBy(java.lang.String prefix)
Creates a
Object.toString() implementation that is prefixed by the supplied string. |
static ToStringMethod |
prefixedBy(ToStringMethod.PrefixResolver prefixResolver)
Creates a
Object.toString() implementation that is prefixed by the string that is supplied by the given prefix resolver. |
static ToStringMethod |
prefixedByCanonicalClassName()
Creates a
Object.toString() implementation that is prefixed by the canonical class name of the instrumented type. |
static ToStringMethod |
prefixedByFullyQualifiedClassName()
Creates a
Object.toString() implementation that is prefixed by the fully qualified class name of the instrumented type. |
static ToStringMethod |
prefixedBySimpleClassName()
Creates a
Object.toString() implementation that is prefixed by the simple class name of the instrumented type. |
InstrumentedType |
prepare(InstrumentedType instrumentedType)
Prepares a given instrumented type.
|
ToStringMethod |
withIgnoredFields(ElementMatcher<? super FieldDescription.InDefinedShape> ignored)
Returns a new version of this toString method implementation that ignores the specified fields additionally to any
previously specified fields.
|
Implementation |
withTokens(java.lang.String start,
java.lang.String end,
java.lang.String separator,
java.lang.String definer)
Changes the tokens used for the
Object.toString() implementation. |
private static final MethodDescription.InDefinedShape STRING_BUILDER_CONSTRUCTOR
StringBuilder.StringBuilder(String)
constructor.private static final MethodDescription.InDefinedShape TO_STRING
StringBuilder.toString()
method.private final ToStringMethod.PrefixResolver prefixResolver
String
representation.private final java.lang.String start
private final java.lang.String end
private final java.lang.String separator
private final java.lang.String definer
private final ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored
protected ToStringMethod(ToStringMethod.PrefixResolver prefixResolver)
toString
implementation.prefixResolver
- A resolver for the prefix of a String
representation.private ToStringMethod(ToStringMethod.PrefixResolver prefixResolver, java.lang.String start, java.lang.String end, java.lang.String separator, java.lang.String definer, ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored)
toString
implementation.prefixResolver
- A resolver for the prefix of a String
representation.start
- A token that is added between the prefix and the first field value.end
- A token that is added after the last field value.separator
- A token that is added between two field values.definer
- A token that is added between a field's name and its value.ignored
- A filter that determines what fields to ignore.public static ToStringMethod prefixedByFullyQualifiedClassName()
Object.toString()
implementation that is prefixed by the fully qualified class name of the instrumented type.Object.toString()
implementation that is prefixed by the fully qualified class name of the instrumented type.public static ToStringMethod prefixedByCanonicalClassName()
Object.toString()
implementation that is prefixed by the canonical class name of the instrumented type.Object.toString()
implementation that is prefixed by the canonical class name of the instrumented type.public static ToStringMethod prefixedBySimpleClassName()
Object.toString()
implementation that is prefixed by the simple class name of the instrumented type.Object.toString()
implementation that is prefixed by the simple class name of the instrumented type.public static ToStringMethod prefixedBy(java.lang.String prefix)
Object.toString()
implementation that is prefixed by the supplied string.prefix
- The prefix to use.Object.toString()
implementation that is prefixed by the supplied string.public static ToStringMethod prefixedBy(ToStringMethod.PrefixResolver prefixResolver)
Object.toString()
implementation that is prefixed by the string that is supplied by the given prefix resolver.prefixResolver
- The prefix resolver to use.Object.toString()
implementation that is prefixed by the string that is supplied by the given prefix resolver.public ToStringMethod withIgnoredFields(ElementMatcher<? super FieldDescription.InDefinedShape> ignored)
ignored
- A matcher to specify any fields that should be ignored.public Implementation withTokens(java.lang.String start, java.lang.String end, java.lang.String separator, java.lang.String definer)
Object.toString()
implementation.start
- A token that is added between the prefix and the first field value.end
- A token that is added after the last field value.separator
- A token that is added between two field values.definer
- A token that is added between two field values.public InstrumentedType prepare(InstrumentedType instrumentedType)
prepare
in interface InstrumentedType.Prepareable
instrumentedType
- The instrumented type in its current form.public ToStringMethod.Appender appender(Implementation.Target implementationTarget)
appender
in interface Implementation
implementationTarget
- The target of the current implementation.InstrumentedType.Prepareable.prepare(InstrumentedType)
.