Package net.bytebuddy.implementation
Class ToStringMethod
- java.lang.Object
-
- net.bytebuddy.implementation.ToStringMethod
-
- All Implemented Interfaces:
InstrumentedType.Prepareable,Implementation
@Enhance public class ToStringMethod extends java.lang.Object implements Implementation
An implementation ofObject.toString()that concatenates theStringrepresentation of all fields that are declared by a class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classToStringMethod.AppenderAn appender to implementToStringMethod.static interfaceToStringMethod.PrefixResolverA prefix resolver is responsible for providing a value that is prepended to aObject.toString()implementation.protected static classToStringMethod.ValueConsumerA 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
Fields Modifier and Type Field Description private java.lang.StringdefinerA token that is added between a field's name and its value.private java.lang.StringendA token that is added after the last field value.private ElementMatcher.Junction<? super FieldDescription.InDefinedShape>ignoredA filter that determines what fields to ignore.private ToStringMethod.PrefixResolverprefixResolverA resolver for the prefix of aStringrepresentation.private java.lang.StringseparatorA token that is added between two field values.private java.lang.StringstartA token that is added between the prefix and the first field value.private static MethodDescription.InDefinedShapeSTRING_BUILDER_CONSTRUCTORTheStringBuilder(String)constructor.private static MethodDescription.InDefinedShapeTO_STRINGTheStringBuilder.toString()method.
-
Constructor Summary
Constructors Modifier Constructor Description protectedToStringMethod(ToStringMethod.PrefixResolver prefixResolver)Creates a newtoStringimplementation.privateToStringMethod(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 newtoStringimplementation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ToStringMethod.Appenderappender(Implementation.Target implementationTarget)Creates a byte code appender that determines the implementation of the instrumented type's methods.static ToStringMethodprefixedBy(java.lang.String prefix)Creates aObject.toString()implementation that is prefixed by the supplied string.static ToStringMethodprefixedBy(ToStringMethod.PrefixResolver prefixResolver)Creates aObject.toString()implementation that is prefixed by the string that is supplied by the given prefix resolver.static ToStringMethodprefixedByCanonicalClassName()Creates aObject.toString()implementation that is prefixed by the canonical class name of the instrumented type.static ToStringMethodprefixedByFullyQualifiedClassName()Creates aObject.toString()implementation that is prefixed by the fully qualified class name of the instrumented type.static ToStringMethodprefixedBySimpleClassName()Creates aObject.toString()implementation that is prefixed by the simple class name of the instrumented type.InstrumentedTypeprepare(InstrumentedType instrumentedType)Prepares a given instrumented type.ToStringMethodwithIgnoredFields(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.ImplementationwithTokens(java.lang.String start, java.lang.String end, java.lang.String separator, java.lang.String definer)Changes the tokens used for theObject.toString()implementation.
-
-
-
Field Detail
-
STRING_BUILDER_CONSTRUCTOR
private static final MethodDescription.InDefinedShape STRING_BUILDER_CONSTRUCTOR
TheStringBuilder(String)constructor.
-
TO_STRING
private static final MethodDescription.InDefinedShape TO_STRING
TheStringBuilder.toString()method.
-
prefixResolver
private final ToStringMethod.PrefixResolver prefixResolver
A resolver for the prefix of aStringrepresentation.
-
start
private final java.lang.String start
A token that is added between the prefix and the first field value.
-
end
private final java.lang.String end
A token that is added after the last field value.
-
separator
private final java.lang.String separator
A token that is added between two field values.
-
definer
private final java.lang.String definer
A token that is added between a field's name and its value.
-
ignored
private final ElementMatcher.Junction<? super FieldDescription.InDefinedShape> ignored
A filter that determines what fields to ignore.
-
-
Constructor Detail
-
ToStringMethod
protected ToStringMethod(ToStringMethod.PrefixResolver prefixResolver)
Creates a newtoStringimplementation.- Parameters:
prefixResolver- A resolver for the prefix of aStringrepresentation.
-
ToStringMethod
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 newtoStringimplementation.- Parameters:
prefixResolver- A resolver for the prefix of aStringrepresentation.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 Detail
-
prefixedByFullyQualifiedClassName
public static ToStringMethod 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
public static ToStringMethod 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
public static ToStringMethod 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
public static ToStringMethod prefixedBy(java.lang.String prefix)
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
public static ToStringMethod prefixedBy(ToStringMethod.PrefixResolver prefixResolver)
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
public Implementation withTokens(java.lang.String start, java.lang.String end, java.lang.String separator, java.lang.String definer)
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
public InstrumentedType prepare(InstrumentedType instrumentedType)
Prepares a given instrumented type.- Specified by:
preparein interfaceInstrumentedType.Prepareable- Parameters:
instrumentedType- The instrumented type in its current form.- Returns:
- The prepared instrumented type.
-
appender
public ToStringMethod.Appender appender(Implementation.Target implementationTarget)
Creates a byte code appender that determines the implementation of the instrumented type's methods.- Specified by:
appenderin 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).
-
-