Package net.bytebuddy.asm
Class ModifierAdjustment
- java.lang.Object
-
- net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
-
- net.bytebuddy.asm.ModifierAdjustment
-
- All Implemented Interfaces:
AsmVisitorWrapper
public class ModifierAdjustment extends AsmVisitorWrapper.AbstractBase
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ModifierAdjustment.Adjustment<T>
A description of a conditional adjustment.protected static class
ModifierAdjustment.ModifierAdjustingClassVisitor
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
-
Fields inherited from interface net.bytebuddy.asm.AsmVisitorWrapper
NO_FLAGS
-
-
Constructor Summary
Constructors Modifier Constructor Description ModifierAdjustment()
Creates a new modifier adjustment that does not adjust any modifiers.protected
ModifierAdjustment(java.util.List<ModifierAdjustment.Adjustment<TypeDescription>> typeAdjustments, java.util.List<ModifierAdjustment.Adjustment<FieldDescription.InDefinedShape>> fieldAdjustments, java.util.List<ModifierAdjustment.Adjustment<MethodDescription>> methodAdjustments)
Creates a new modifier adjustment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ModifierAdjustment
withConstructorModifiers(java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)
Adjusts any constructor's modifiers.ModifierAdjustment
withConstructorModifiers(ModifierContributor.ForMethod... modifierContributor)
Adjusts any constructor's modifiers.ModifierAdjustment
withConstructorModifiers(ElementMatcher<? super MethodDescription> matcher, java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)
Adjusts a constructor's modifiers if it fulfills the supplied matcher.ModifierAdjustment
withConstructorModifiers(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor)
Adjusts a constructor's modifiers if it fulfills the supplied matcher.ModifierAdjustment
withFieldModifiers(java.util.List<? extends ModifierContributor.ForField> modifierContributors)
Adjusts any field's modifiers.ModifierAdjustment
withFieldModifiers(ModifierContributor.ForField... modifierContributor)
Adjusts any field's modifiers.ModifierAdjustment
withFieldModifiers(ElementMatcher<? super FieldDescription.InDefinedShape> matcher, java.util.List<? extends ModifierContributor.ForField> modifierContributors)
Adjusts a field's modifiers if it fulfills the supplied matcher.ModifierAdjustment
withFieldModifiers(ElementMatcher<? super FieldDescription.InDefinedShape> matcher, ModifierContributor.ForField... modifierContributor)
Adjusts a field's modifiers if it fulfills the supplied matcher.ModifierAdjustment
withInvokableModifiers(java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)
Adjusts any method's or constructor's modifiers.ModifierAdjustment
withInvokableModifiers(ModifierContributor.ForMethod... modifierContributor)
Adjusts any method's or constructor's modifiers.ModifierAdjustment
withInvokableModifiers(ElementMatcher<? super MethodDescription> matcher, java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)
Adjusts a method's or constructor's modifiers if it fulfills the supplied matcher.ModifierAdjustment
withInvokableModifiers(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor)
Adjusts a method's or constructor's modifiers if it fulfills the supplied matcher.ModifierAdjustment
withMethodModifiers(java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)
Adjusts any method's modifiers.ModifierAdjustment
withMethodModifiers(ModifierContributor.ForMethod... modifierContributor)
Adjusts any method's modifiers.ModifierAdjustment
withMethodModifiers(ElementMatcher<? super MethodDescription> matcher, java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)
Adjusts a method's modifiers if it fulfills the supplied matcher.ModifierAdjustment
withMethodModifiers(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor)
Adjusts a method's modifiers if it fulfills the supplied matcher.ModifierAdjustment
withTypeModifiers(java.util.List<? extends ModifierContributor.ForType> modifierContributors)
Adjusts any instrumented type's modifiers.ModifierAdjustment
withTypeModifiers(ModifierContributor.ForType... modifierContributor)
Adjusts any instrumented type's modifiers.ModifierAdjustment
withTypeModifiers(ElementMatcher<? super TypeDescription> matcher, java.util.List<? extends ModifierContributor.ForType> modifierContributors)
Adjusts an instrumented type's modifiers if it matches the supplied matcher.ModifierAdjustment
withTypeModifiers(ElementMatcher<? super TypeDescription> matcher, ModifierContributor.ForType... modifierContributor)
Adjusts an instrumented type's modifiers if it matches the supplied matcher.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
.-
Methods inherited from class net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
mergeReader, mergeWriter
-
-
-
-
Constructor Detail
-
ModifierAdjustment
public ModifierAdjustment()
Creates a new modifier adjustment that does not adjust any modifiers.
-
ModifierAdjustment
protected ModifierAdjustment(java.util.List<ModifierAdjustment.Adjustment<TypeDescription>> typeAdjustments, java.util.List<ModifierAdjustment.Adjustment<FieldDescription.InDefinedShape>> fieldAdjustments, java.util.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 Detail
-
withTypeModifiers
public ModifierAdjustment withTypeModifiers(ModifierContributor.ForType... modifierContributor)
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(java.util.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, java.util.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
public ModifierAdjustment withFieldModifiers(ModifierContributor.ForField... modifierContributor)
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(java.util.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, java.util.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
public ModifierAdjustment withMethodModifiers(ModifierContributor.ForMethod... modifierContributor)
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(java.util.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, java.util.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(java.util.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, java.util.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(java.util.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, java.util.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)
Description copied from interface:AsmVisitorWrapper
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.
-
-