Enum Class ConstructorStrategy.Default
java.lang.Object
java.lang.Enum<ConstructorStrategy.Default>
net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy.Default
- All Implemented Interfaces:
Serializable
,Comparable<ConstructorStrategy.Default>
,Constable
,ConstructorStrategy
- Enclosing interface:
- ConstructorStrategy
public static enum ConstructorStrategy.Default
extends Enum<ConstructorStrategy.Default>
implements ConstructorStrategy
Default implementations of constructor strategies. Any such strategy offers to additionally apply an
MethodAttributeAppender.Factory
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A wrapper for a default constructor strategy which additionally applies a method attribute appender factory.Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy
ConstructorStrategy.Default, ConstructorStrategy.ForDefaultConstructor
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThis strategy is adding a default constructor that calls its super types default constructor.This strategy is adding all constructors of the instrumented type's super class where each constructor is directly invoking its signature-equivalent super class constructor.This strategy is adding all constructors of the instrumented type's super class where each constructor is directly invoking its signature-equivalent super class constructor.This strategy is adding all constructors of the instrumented type's super class where each constructor is directly invoking its signature-equivalent super class constructor.This strategy is adding no constructors such that the instrumented type will by default not have any. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract List<MethodDescription.Token>
doExtractConstructors
(TypeDescription instrumentedType) Extracts the relevant method tokens of the instrumented type's constructors.protected abstract MethodRegistry
doInject
(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) Applies the actual injection with a method attribute appender factory supplied.extractConstructors
(TypeDescription instrumentedType) Extracts constructors for a given super type.inject
(TypeDescription instrumentedType, MethodRegistry methodRegistry) Returns a method registry that is capable of creating byte code for the constructors that were provided by theConstructorStrategy.extractConstructors(TypeDescription)
method of this instance.protected int
resolveModifier
(int modifiers) Resolves a constructor's modifiers.static ConstructorStrategy.Default
Returns the enum constant of this class with the specified name.static ConstructorStrategy.Default[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.with
(MethodAttributeAppender.Factory methodAttributeAppenderFactory) Returns a constructor strategy that supplies the supplied method attribute appender factory.Applies this constructor strategy while retaining any of the base constructor's annotations.
-
Enum Constant Details
-
NO_CONSTRUCTORS
This strategy is adding no constructors such that the instrumented type will by default not have any. This is legal by Java byte code requirements. However, if no constructor is added manually if this strategy is applied, the type is not constructable without using JVM non-public functionality. -
DEFAULT_CONSTRUCTOR
This strategy is adding a default constructor that calls its super types default constructor. If no such constructor is defined by the super class, anIllegalArgumentException
is thrown. Note that the default constructor needs to be visible to its sub type for this strategy to work. The declared default constructor of the created class is declared public and without annotations. -
IMITATE_SUPER_CLASS
This strategy is adding all constructors of the instrumented type's super class where each constructor is directly invoking its signature-equivalent super class constructor. Only constructors that are visible to the instrumented type are added, i.e. package-private constructors are only added if the super type is defined in the same package as the instrumented type and private constructors are always skipped. -
IMITATE_SUPER_CLASS_PUBLIC
This strategy is adding all constructors of the instrumented type's super class where each constructor is directly invoking its signature-equivalent super class constructor. Onlypublic
constructors are added. -
IMITATE_SUPER_CLASS_OPENING
This strategy is adding all constructors of the instrumented type's super class where each constructor is directly invoking its signature-equivalent super class constructor. A constructor is added for any constructor of the super class that is invokable and is declared aspublic
.
-
-
Constructor Details
-
Default
private Default()
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
extractConstructors
Extracts constructors for a given super type. The extracted constructor signatures will then be imitated by the created dynamic type.- Specified by:
extractConstructors
in interfaceConstructorStrategy
- Parameters:
instrumentedType
- The type for which the constructors should be created.- Returns:
- A list of tokens that describe the constructors that are to be implemented.
-
resolveModifier
protected int resolveModifier(int modifiers) Resolves a constructor's modifiers.- Parameters:
modifiers
- The actual constructor's modifiers.- Returns:
- The resolved modifiers.
-
doExtractConstructors
protected abstract List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) Extracts the relevant method tokens of the instrumented type's constructors.- Parameters:
instrumentedType
- The type for which to extract the constructors.- Returns:
- A list of relevant method tokens.
-
inject
Returns a method registry that is capable of creating byte code for the constructors that were provided by theConstructorStrategy.extractConstructors(TypeDescription)
method of this instance.- Specified by:
inject
in interfaceConstructorStrategy
- Parameters:
instrumentedType
- The instrumented type.methodRegistry
- The original method registry.- Returns:
- A method registry that is capable of providing byte code for the constructors that were added by this strategy.
-
doInject
protected abstract MethodRegistry doInject(MethodRegistry methodRegistry, MethodAttributeAppender.Factory methodAttributeAppenderFactory) Applies the actual injection with a method attribute appender factory supplied.- Parameters:
methodRegistry
- The method registry into which to inject the constructors.methodAttributeAppenderFactory
- The method attribute appender to use.- Returns:
- The resulting method registry.
-
with
Returns a constructor strategy that supplies the supplied method attribute appender factory.- Parameters:
methodAttributeAppenderFactory
- The method attribute appender factory to use.- Returns:
- A copy of this constructor strategy with the method attribute appender factory applied.
-
withInheritedAnnotations
Applies this constructor strategy while retaining any of the base constructor's annotations.- Returns:
- A copy of this constructor strategy which retains any of the base constructor's annotations.
-