Package net.bytebuddy.asm
Class ModifierAdjustment
- java.lang.Object
-
- net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
-
- net.bytebuddy.asm.ModifierAdjustment
-
- All Implemented Interfaces:
AsmVisitorWrapper
@Enhance 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. The modifier changes are neither visible to element matchers during an instrumentation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classModifierAdjustment.Adjustment<T>A description of a conditional adjustment.protected static classModifierAdjustment.ModifierAdjustingClassVisitorA 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 Modifier and Type Field Description private java.util.List<ModifierAdjustment.Adjustment<FieldDescription.InDefinedShape>>fieldAdjustmentsA list of adjustments to apply to the instrumented type's declared fields.private java.util.List<ModifierAdjustment.Adjustment<MethodDescription>>methodAdjustmentsA list of adjustments to apply to the instrumented type's methods.private java.util.List<ModifierAdjustment.Adjustment<TypeDescription>>typeAdjustmentsA list of adjustments to apply to the instrumented type.-
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.protectedModifierAdjustment(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 ModifierAdjustmentwithConstructorModifiers(java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)Adjusts any constructor's modifiers.ModifierAdjustmentwithConstructorModifiers(ModifierContributor.ForMethod... modifierContributor)Adjusts any constructor's modifiers.ModifierAdjustmentwithConstructorModifiers(ElementMatcher<? super MethodDescription> matcher, java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)Adjusts a constructor's modifiers if it fulfills the supplied matcher.ModifierAdjustmentwithConstructorModifiers(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor)Adjusts a constructor's modifiers if it fulfills the supplied matcher.ModifierAdjustmentwithFieldModifiers(java.util.List<? extends ModifierContributor.ForField> modifierContributors)Adjusts any field's modifiers.ModifierAdjustmentwithFieldModifiers(ModifierContributor.ForField... modifierContributor)Adjusts any field's modifiers.ModifierAdjustmentwithFieldModifiers(ElementMatcher<? super FieldDescription.InDefinedShape> matcher, java.util.List<? extends ModifierContributor.ForField> modifierContributors)Adjusts a field's modifiers if it fulfills the supplied matcher.ModifierAdjustmentwithFieldModifiers(ElementMatcher<? super FieldDescription.InDefinedShape> matcher, ModifierContributor.ForField... modifierContributor)Adjusts a field's modifiers if it fulfills the supplied matcher.ModifierAdjustmentwithInvokableModifiers(java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)Adjusts any method's or constructor's modifiers.ModifierAdjustmentwithInvokableModifiers(ModifierContributor.ForMethod... modifierContributor)Adjusts any method's or constructor's modifiers.ModifierAdjustmentwithInvokableModifiers(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.ModifierAdjustmentwithInvokableModifiers(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor)Adjusts a method's or constructor's modifiers if it fulfills the supplied matcher.ModifierAdjustmentwithMethodModifiers(java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)Adjusts any method's modifiers.ModifierAdjustmentwithMethodModifiers(ModifierContributor.ForMethod... modifierContributor)Adjusts any method's modifiers.ModifierAdjustmentwithMethodModifiers(ElementMatcher<? super MethodDescription> matcher, java.util.List<? extends ModifierContributor.ForMethod> modifierContributors)Adjusts a method's modifiers if it fulfills the supplied matcher.ModifierAdjustmentwithMethodModifiers(ElementMatcher<? super MethodDescription> matcher, ModifierContributor.ForMethod... modifierContributor)Adjusts a method's modifiers if it fulfills the supplied matcher.ModifierAdjustmentwithTypeModifiers(java.util.List<? extends ModifierContributor.ForType> modifierContributors)Adjusts any instrumented type's modifiers.ModifierAdjustmentwithTypeModifiers(ModifierContributor.ForType... modifierContributor)Adjusts any instrumented type's modifiers.ModifierAdjustmentwithTypeModifiers(ElementMatcher<? super TypeDescription> matcher, java.util.List<? extends ModifierContributor.ForType> modifierContributors)Adjusts an instrumented type's modifiers if it matches the supplied matcher.ModifierAdjustmentwithTypeModifiers(ElementMatcher<? super TypeDescription> matcher, ModifierContributor.ForType... modifierContributor)Adjusts an instrumented type's modifiers if it matches the supplied matcher.ModifierAdjustment.ModifierAdjustingClassVisitorwrap(TypeDescription instrumentedType, org.objectweb.asm.ClassVisitor classVisitor, Implementation.Context implementationContext, TypePool typePool, FieldList<FieldDescription.InDefinedShape> fields, MethodList<?> methods, int writerFlags, int readerFlags)Applies aClassVisitorWrapperto the creation of aDynamicType.-
Methods inherited from class net.bytebuddy.asm.AsmVisitorWrapper.AbstractBase
mergeReader, mergeWriter
-
-
-
-
Field Detail
-
typeAdjustments
private final java.util.List<ModifierAdjustment.Adjustment<TypeDescription>> typeAdjustments
A list of adjustments to apply to the instrumented type.
-
fieldAdjustments
private final java.util.List<ModifierAdjustment.Adjustment<FieldDescription.InDefinedShape>> fieldAdjustments
A list of adjustments to apply to the instrumented type's declared fields.
-
methodAdjustments
private final java.util.List<ModifierAdjustment.Adjustment<MethodDescription>> methodAdjustments
A list of adjustments to apply to the instrumented type's methods.
-
-
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)
Applies aClassVisitorWrapperto the creation of aDynamicType.- Parameters:
instrumentedType- The instrumented type.classVisitor- AClassVisitorto become the new primary class visitor to which the createdDynamicTypeis 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 ASMClassWriterflags to consider.readerFlags- The ASMClassReaderflags to consider.- Returns:
- A new
ClassVisitorthat usually delegates to theClassVisitordelivered in the argument.
-
-