Package net.bytebuddy.implementation
Class ToStringMethod
java.lang.Object
net.bytebuddy.implementation.ToStringMethod
- All Implemented Interfaces:
InstrumentedType.Prepareable
,Implementation
An implementation of
Object.toString()
that concatenates the String
representation of all fields that are declared by a class.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
An appender to implementToStringMethod
.static interface
A prefix resolver is responsible for providing a value that is prepended to aObject.toString()
implementation.protected static enum
A value consumer that is responsible for adding a field value to the string creatingStringBuilder
.Nested classes/interfaces inherited from interface net.bytebuddy.implementation.Implementation
Implementation.Composable, Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.scaffold.InstrumentedType.Prepareable
InstrumentedType.Prepareable.NoOp
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String
A token that is added between a field's name and its value.private final String
A token that is added after the last field value.private final ElementMatcher.Junction<? super FieldDescription.InDefinedShape>
A filter that determines what fields to ignore.private final ToStringMethod.PrefixResolver
A resolver for the prefix of aString
representation.private final String
A token that is added between two field values.private final String
A token that is added between the prefix and the first field value.private static final MethodDescription.InDefinedShape
TheStringBuilder(String)
constructor.private static final MethodDescription.InDefinedShape
TheStringBuilder.toString()
method. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ToStringMethod
(ToStringMethod.PrefixResolver prefixResolver) Creates a newtoString
implementation.private
ToStringMethod
(ToStringMethod.PrefixResolver prefixResolver, String start, String end, String separator, String definer, ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored) Creates a newtoString
implementation. -
Method Summary
Modifier and TypeMethodDescriptionappender
(Implementation.Target implementationTarget) Creates a byte code appender that determines the implementation of the instrumented type's methods.static ToStringMethod
prefixedBy
(String prefix) Creates aObject.toString()
implementation that is prefixed by the supplied string.static ToStringMethod
prefixedBy
(ToStringMethod.PrefixResolver prefixResolver) Creates aObject.toString()
implementation that is prefixed by the string that is supplied by the given prefix resolver.static ToStringMethod
Creates aObject.toString()
implementation that is prefixed by the canonical class name of the instrumented type.static ToStringMethod
Creates aObject.toString()
implementation that is prefixed by the fully qualified class name of the instrumented type.static ToStringMethod
Creates aObject.toString()
implementation that is prefixed by the simple class name of the instrumented type.prepare
(InstrumentedType instrumentedType) Prepares a given instrumented type.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.withTokens
(String start, String end, String separator, String definer) Changes the tokens used for theObject.toString()
implementation.
-
Field Details
-
STRING_BUILDER_CONSTRUCTOR
TheStringBuilder(String)
constructor. -
TO_STRING
TheStringBuilder.toString()
method. -
prefixResolver
A resolver for the prefix of aString
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.
-
-
Constructor Details
-
ToStringMethod
Creates a newtoString
implementation.- Parameters:
prefixResolver
- A resolver for the prefix of aString
representation.
-
ToStringMethod
private ToStringMethod(ToStringMethod.PrefixResolver prefixResolver, String start, String end, String separator, String definer, ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored) Creates a newtoString
implementation.- Parameters:
prefixResolver
- A resolver for the prefix of aString
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.
-
-
Method Details
-
prefixedByFullyQualifiedClassName
Creates aObject.toString()
implementation that is prefixed by the fully qualified class name of the instrumented type.- Returns:
- A
Object.toString()
implementation that is prefixed by the fully qualified class name of the instrumented type.
-
prefixedByCanonicalClassName
Creates aObject.toString()
implementation that is prefixed by the canonical class name of the instrumented type.- Returns:
- A
Object.toString()
implementation that is prefixed by the canonical class name of the instrumented type.
-
prefixedBySimpleClassName
Creates aObject.toString()
implementation that is prefixed by the simple class name of the instrumented type.- Returns:
- A
Object.toString()
implementation that is prefixed by the simple class name of the instrumented type.
-
prefixedBy
Creates aObject.toString()
implementation that is prefixed by the supplied string.- Parameters:
prefix
- The prefix to use.- Returns:
- A
Object.toString()
implementation that is prefixed by the supplied string.
-
prefixedBy
Creates aObject.toString()
implementation that is prefixed by the string that is supplied by the given prefix resolver.- Parameters:
prefixResolver
- The prefix resolver to use.- Returns:
- A
Object.toString()
implementation that is prefixed by the string that is supplied by the given prefix resolver.
-
withIgnoredFields
public 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.- Parameters:
ignored
- A matcher to specify any fields that should be ignored.- Returns:
- A new version of this toString method implementation that also ignores any fields matched by the provided matcher.
-
withTokens
Changes the tokens used for theObject.toString()
implementation.- Parameters:
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.- Returns:
- A new instance of this implementation that uses the supplied tokens.
-
prepare
Prepares a given instrumented type.- Specified by:
prepare
in interfaceInstrumentedType.Prepareable
- Parameters:
instrumentedType
- The instrumented type in its current form.- Returns:
- The prepared instrumented type.
-
appender
Creates a byte code appender that determines the implementation of the instrumented type's methods.- Specified by:
appender
in interfaceImplementation
- Parameters:
implementationTarget
- The target of the current implementation.- Returns:
- A byte code appender for implementing methods delegated to this implementation. This byte code appender
is also responsible for handling methods that were added by this implementation on the call to
InstrumentedType.Prepareable.prepare(InstrumentedType)
.
-