Package net.bytebuddy.asm
Class ModifierAdjustment
java.lang.Object
net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
net.bytebuddy.asm.ModifierAdjustment
- All Implemented Interfaces:
AsmVisitorWrapper
A visitor wrapper that adjusts the modifiers of the instrumented type or its members.
Important: The removal of the method is not reflected in the created DynamicType
's
type description of the instrumented type. The modifier changes are neither visible to element matchers during an instrumentation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
A description of a conditional adjustment.protected static class
A class visitor that enforces a collection of modifier adjustments.Nested classes/interfaces inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
AsmVisitorWrapper.AbstractBase, AsmVisitorWrapper.Compound, AsmVisitorWrapper.ForDeclaredFields, AsmVisitorWrapper.ForDeclaredMethods, AsmVisitorWrapper.NoOp
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<ModifierAdjustment.Adjustment<FieldDescription.InDefinedShape>>
A list of adjustments to apply to the instrumented type's declared fields.private final List<ModifierAdjustment.Adjustment<MethodDescription>>
A list of adjustments to apply to the instrumented type's methods.private final List<ModifierAdjustment.Adjustment<TypeDescription>>
A list of adjustments to apply to the instrumented type.Fields inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
NO_FLAGS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new modifier adjustment that does not adjust any modifiers.protected
ModifierAdjustment
(List<ModifierAdjustment.Adjustment<TypeDescription>> typeAdjustments, List<ModifierAdjustment.Adjustment<FieldDescription.InDefinedShape>> fieldAdjustments, List<ModifierAdjustment.Adjustment<MethodDescription>> methodAdjustments) Creates a new modifier adjustment. -
Method Summary
Modifier and TypeMethodDescriptionwithConstructorModifiers
(List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts any constructor's modifiers.withConstructorModifiers
(ModifierContributor.ForMethod... modifierContributor) Adjusts any constructor's modifiers.withConstructorModifiers
(ElementMatcher<? super MethodDescription> matcher, List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts a constructor's modifiers if it fulfills the supplied matcher.withConstructorModifiers
(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor) Adjusts a constructor's modifiers if it fulfills the supplied matcher.withFieldModifiers
(List<? extends ModifierContributor.ForField> modifierContributors) Adjusts any field's modifiers.withFieldModifiers
(ModifierContributor.ForField... modifierContributor) Adjusts any field's modifiers.withFieldModifiers
(ElementMatcher<? super FieldDescription.InDefinedShape> matcher, List<? extends ModifierContributor.ForField> modifierContributors) Adjusts a field's modifiers if it fulfills the supplied matcher.withFieldModifiers
(ElementMatcher<? super FieldDescription.InDefinedShape> matcher, ModifierContributor.ForField... modifierContributor) Adjusts a field's modifiers if it fulfills the supplied matcher.withInvokableModifiers
(List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts any method's or constructor's modifiers.withInvokableModifiers
(ModifierContributor.ForMethod... modifierContributor) Adjusts any method's or constructor's modifiers.withInvokableModifiers
(ElementMatcher<? super MethodDescription> matcher, List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts a method's or constructor's modifiers if it fulfills the supplied matcher.withInvokableModifiers
(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor) Adjusts a method's or constructor's modifiers if it fulfills the supplied matcher.withMethodModifiers
(List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts any method's modifiers.withMethodModifiers
(ModifierContributor.ForMethod... modifierContributor) Adjusts any method's modifiers.withMethodModifiers
(ElementMatcher<? super MethodDescription> matcher, List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts a method's modifiers if it fulfills the supplied matcher.withMethodModifiers
(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor) Adjusts a method's modifiers if it fulfills the supplied matcher.withTypeModifiers
(List<? extends ModifierContributor.ForType> modifierContributors) Adjusts any instrumented type's modifiers.withTypeModifiers
(ModifierContributor.ForType... modifierContributor) Adjusts any instrumented type's modifiers.withTypeModifiers
(ElementMatcher<? super TypeDescription> matcher, List<? extends ModifierContributor.ForType> modifierContributors) Adjusts an instrumented type's modifiers if it matches the supplied matcher.withTypeModifiers
(ElementMatcher<? super TypeDescription> matcher, ModifierContributor.ForType... modifierContributor) Adjusts an instrumented type's modifiers if it matches the supplied matcher.wrap
(TypeDescription instrumentedType, org.objectweb.asm.ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags) Applies aClassVisitorWrapper
to the creation of aDynamicType
.Methods inherited from class net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
mergeReader, mergeWriter
-
Field Details
-
typeAdjustments
A list of adjustments to apply to the instrumented type. -
fieldAdjustments
A list of adjustments to apply to the instrumented type's declared fields. -
methodAdjustments
A list of adjustments to apply to the instrumented type's methods.
-
-
Constructor Details
-
ModifierAdjustment
public ModifierAdjustment()Creates a new modifier adjustment that does not adjust any modifiers. -
ModifierAdjustment
protected ModifierAdjustment(List<ModifierAdjustment.Adjustment<TypeDescription>> typeAdjustments, List<ModifierAdjustment.Adjustment<FieldDescription.InDefinedShape>> fieldAdjustments, List<ModifierAdjustment.Adjustment<MethodDescription>> methodAdjustments) Creates a new modifier adjustment.- Parameters:
typeAdjustments
- A list of adjustments to apply to the instrumented type.fieldAdjustments
- A list of adjustments to apply to the instrumented type's declared fields.methodAdjustments
- A list of adjustments to apply to the instrumented type's methods.
-
-
Method Details
-
withTypeModifiers
Adjusts any instrumented type's modifiers.- Parameters:
modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withTypeModifiers
public ModifierAdjustment withTypeModifiers(List<? extends ModifierContributor.ForType> modifierContributors) Adjusts any instrumented type's modifiers.- Parameters:
modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withTypeModifiers
public ModifierAdjustment withTypeModifiers(ElementMatcher<? super TypeDescription> matcher, ModifierContributor.ForType... modifierContributor) Adjusts an instrumented type's modifiers if it matches the supplied matcher.- Parameters:
matcher
- The matcher that determines a type's eligibility.modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withTypeModifiers
public ModifierAdjustment withTypeModifiers(ElementMatcher<? super TypeDescription> matcher, List<? extends ModifierContributor.ForType> modifierContributors) Adjusts an instrumented type's modifiers if it matches the supplied matcher.- Parameters:
matcher
- The matcher that determines a type's eligibility.modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withFieldModifiers
Adjusts any field's modifiers.- Parameters:
modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withFieldModifiers
public ModifierAdjustment withFieldModifiers(List<? extends ModifierContributor.ForField> modifierContributors) Adjusts any field's modifiers.- Parameters:
modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withFieldModifiers
public ModifierAdjustment withFieldModifiers(ElementMatcher<? super FieldDescription.InDefinedShape> matcher, ModifierContributor.ForField... modifierContributor) Adjusts a field's modifiers if it fulfills the supplied matcher.- Parameters:
matcher
- The matcher that determines if a field's modifiers should be adjusted.modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withFieldModifiers
public ModifierAdjustment withFieldModifiers(ElementMatcher<? super FieldDescription.InDefinedShape> matcher, List<? extends ModifierContributor.ForField> modifierContributors) Adjusts a field's modifiers if it fulfills the supplied matcher.- Parameters:
matcher
- The matcher that determines if a field's modifiers should be adjusted.modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withMethodModifiers
Adjusts any method's modifiers.- Parameters:
modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withMethodModifiers
public ModifierAdjustment withMethodModifiers(List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts any method's modifiers.- Parameters:
modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withMethodModifiers
public ModifierAdjustment withMethodModifiers(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor) Adjusts a method's modifiers if it fulfills the supplied matcher.- Parameters:
matcher
- The matcher that determines if a method's modifiers should be adjusted.modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withMethodModifiers
public ModifierAdjustment withMethodModifiers(ElementMatcher<? super MethodDescription> matcher, List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts a method's modifiers if it fulfills the supplied matcher.- Parameters:
matcher
- The matcher that determines if a method's modifiers should be adjusted.modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withConstructorModifiers
public ModifierAdjustment withConstructorModifiers(ModifierContributor.ForMethod... modifierContributor) Adjusts any constructor's modifiers.- Parameters:
modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withConstructorModifiers
public ModifierAdjustment withConstructorModifiers(List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts any constructor's modifiers.- Parameters:
modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withConstructorModifiers
public ModifierAdjustment withConstructorModifiers(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor) Adjusts a constructor's modifiers if it fulfills the supplied matcher.- Parameters:
matcher
- The matcher that determines if a constructor's modifiers should be adjusted.modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withConstructorModifiers
public ModifierAdjustment withConstructorModifiers(ElementMatcher<? super MethodDescription> matcher, List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts a constructor's modifiers if it fulfills the supplied matcher.- Parameters:
matcher
- The matcher that determines if a constructor's modifiers should be adjusted.modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withInvokableModifiers
public ModifierAdjustment withInvokableModifiers(ModifierContributor.ForMethod... modifierContributor) Adjusts any method's or constructor's modifiers.- Parameters:
modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withInvokableModifiers
public ModifierAdjustment withInvokableModifiers(List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts any method's or constructor's modifiers.- Parameters:
modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withInvokableModifiers
public ModifierAdjustment withInvokableModifiers(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor) Adjusts a method's or constructor's modifiers if it fulfills the supplied matcher.- Parameters:
matcher
- The matcher that determines if a method's or constructor's modifiers should be adjusted.modifierContributor
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
withInvokableModifiers
public ModifierAdjustment withInvokableModifiers(ElementMatcher<? super MethodDescription> matcher, List<? extends ModifierContributor.ForMethod> modifierContributors) Adjusts a method's or constructor's modifiers if it fulfills the supplied matcher.- Parameters:
matcher
- The matcher that determines if a method's or constructor's modifiers should be adjusted.modifierContributors
- The modifier contributors to enforce.- Returns:
- A new modifier adjustment that enforces the given modifier contributors and any previous adjustments.
-
wrap
public ModifierAdjustment.ModifierAdjustingClassVisitor wrap(TypeDescription instrumentedType, org.objectweb.asm.ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags) Applies aClassVisitorWrapper
to the creation of aDynamicType
.- Parameters:
instrumentedType
- The instrumented type.classVisitor
- AClassVisitor
to become the new primary class visitor to which the createdDynamicType
is written to.implementationContext
- The implementation context of the current instrumentation.typePool
- The type pool that was provided for the class creation.fields
- The instrumented type's fields.methods
- The instrumented type's methods non-ignored declared and virtually inherited methods.writerFlags
- The ASMClassWriter
flags to consider.readerFlags
- The ASMClassReader
flags to consider.- Returns:
- A new
ClassVisitor
that usually delegates to theClassVisitor
delivered in the argument.
-