Enum ConstructorStrategy.Default
- java.lang.Object
-
- java.lang.Enum<ConstructorStrategy.Default>
-
- net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy.Default
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<ConstructorStrategy.Default>
,ConstructorStrategy
- Enclosing interface:
- ConstructorStrategy
public static enum ConstructorStrategy.Default extends java.lang.Enum<ConstructorStrategy.Default> implements ConstructorStrategy
Default implementations of constructor strategies. Any such strategy offers to additionally apply anMethodAttributeAppender.Factory
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ConstructorStrategy.Default.WithMethodAttributeAppenderFactory
A wrapper for a default constructor strategy which additionally applies a method attribute appender factory.-
Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy
ConstructorStrategy.Default, ConstructorStrategy.ForDefaultConstructor
-
-
Enum Constant Summary
Enum Constants Enum Constant Description DEFAULT_CONSTRUCTOR
This strategy is adding a default constructor that calls it's super types default constructor.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.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.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.NO_CONSTRUCTORS
This strategy is adding no constructors such that the instrumented type will by default not have any.
-
Constructor Summary
Constructors Modifier Constructor Description private
Default()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.util.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.java.util.List<MethodDescription.Token>
extractConstructors(TypeDescription instrumentedType)
Extracts constructors for a given super type.MethodRegistry
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
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static ConstructorStrategy.Default[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.ConstructorStrategy
with(MethodAttributeAppender.Factory methodAttributeAppenderFactory)
Returns a constructor strategy that supplies the supplied method attribute appender factory.ConstructorStrategy
withInheritedAnnotations()
Applies this constructor strategy while retaining any of the base constructor's annotations.
-
-
-
Enum Constant Detail
-
NO_CONSTRUCTORS
public static final ConstructorStrategy.Default 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
public static final ConstructorStrategy.Default DEFAULT_CONSTRUCTOR
This strategy is adding a default constructor that calls it's 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
public static final ConstructorStrategy.Default 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
public static final ConstructorStrategy.Default 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
public static final ConstructorStrategy.Default 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
.
-
-
Method Detail
-
values
public static ConstructorStrategy.Default[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ConstructorStrategy.Default c : ConstructorStrategy.Default.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ConstructorStrategy.Default valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
extractConstructors
public java.util.List<MethodDescription.Token> extractConstructors(TypeDescription instrumentedType)
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 java.util.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
public MethodRegistry 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.- 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
public ConstructorStrategy with(MethodAttributeAppender.Factory methodAttributeAppenderFactory)
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
public ConstructorStrategy 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.
-
-