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.
  • Enum Constant Details

    • 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 its super types default constructor. If no such constructor is defined by the super class, an IllegalArgumentException 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. Only public 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 as public.
  • Constructor Details

    • Default

      private Default()
  • Method Details

    • values

      public static ConstructorStrategy.Default[] 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

      public static ConstructorStrategy.Default valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • extractConstructors

      public 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 interface ConstructorStrategy
      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

      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 the ConstructorStrategy.extractConstructors(TypeDescription) method of this instance.
      Specified by:
      inject in interface ConstructorStrategy
      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.