Class MemberSubstitution.WithoutSpecification
- java.lang.Object
-
- net.bytebuddy.asm.MemberSubstitution.WithoutSpecification
-
- Direct Known Subclasses:
MemberSubstitution.WithoutSpecification.ForMatchedByteCodeElement
,MemberSubstitution.WithoutSpecification.ForMatchedField
,MemberSubstitution.WithoutSpecification.ForMatchedMethod
- Enclosing class:
- MemberSubstitution
public abstract static class MemberSubstitution.WithoutSpecification extends java.lang.Object
A member substitution that lacks a specification for how to substitute the matched members references within a method body.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
MemberSubstitution.WithoutSpecification.ForMatchedByteCodeElement
Describes a member substitution that requires a specification for how to replace a byte code element.static class
MemberSubstitution.WithoutSpecification.ForMatchedField
Describes a member substitution that requires a specification for how to replace a field.static class
MemberSubstitution.WithoutSpecification.ForMatchedMethod
Describes a member substitution that requires a specification for how to replace a method or constructor.
-
Field Summary
Fields Modifier and Type Field Description protected MethodGraph.Compiler
methodGraphCompiler
The method graph compiler to use.protected boolean
strict
true
if the method processing should be strict where an exception is raised if a member cannot be found.protected MemberSubstitution.Substitution
substitution
The substitution to apply.protected MemberSubstitution.TypePoolResolver
typePoolResolver
The type pool resolver to use.
-
Constructor Summary
Constructors Modifier Constructor Description protected
WithoutSpecification(MethodGraph.Compiler methodGraphCompiler, MemberSubstitution.TypePoolResolver typePoolResolver, boolean strict, MemberSubstitution.Substitution substitution)
Creates a new member substitution that requires a specification for how to perform a substitution.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract MemberSubstitution.Substitution
doReplaceWith(FieldDescription fieldDescription)
Creates a substitution for replacing the byte code elements matched by this instance with an access of the specified field.protected abstract MemberSubstitution.Substitution
doReplaceWith(MethodDescription methodDescription)
Creates a substitution for replacing the byte code elements matched by this instance with an invocation of the specified method.protected abstract MemberSubstitution.Substitution
doStub()
Applies the stubbing for this instance.MemberSubstitution
replaceWith(java.lang.reflect.Field field)
Replaces any interaction with a matched byte code element by an interaction with the specified field.MemberSubstitution
replaceWith(java.lang.reflect.Method method)
Replaces any interaction with a matched byte code element by an invocation of the specified method.MemberSubstitution
replaceWith(FieldDescription fieldDescription)
Replaces any interaction with a matched byte code element by an interaction with the specified field.MemberSubstitution
replaceWith(MethodDescription methodDescription)
Replaces any interaction with a matched byte code element by an invocation of the specified method.MemberSubstitution
stub()
Subs any interaction with a matched byte code element.
-
-
-
Field Detail
-
methodGraphCompiler
protected final MethodGraph.Compiler methodGraphCompiler
The method graph compiler to use.
-
typePoolResolver
protected final MemberSubstitution.TypePoolResolver typePoolResolver
The type pool resolver to use.
-
strict
protected final boolean strict
true
if the method processing should be strict where an exception is raised if a member cannot be found.
-
substitution
protected final MemberSubstitution.Substitution substitution
The substitution to apply.
-
-
Constructor Detail
-
WithoutSpecification
protected WithoutSpecification(MethodGraph.Compiler methodGraphCompiler, MemberSubstitution.TypePoolResolver typePoolResolver, boolean strict, MemberSubstitution.Substitution substitution)
Creates a new member substitution that requires a specification for how to perform a substitution.- Parameters:
methodGraphCompiler
- The method graph compiler to use.typePoolResolver
- The type pool resolver to use.strict
-true
if the method processing should be strict where an exception is raised if a member cannot be found.substitution
- The substitution to apply.
-
-
Method Detail
-
stub
public MemberSubstitution stub()
Subs any interaction with a matched byte code element. Any value read from the element will be replaced with the stubbed value's default, i.e.null
for reference types and the specific0
value for primitive types. Any written value will simply be discarded.- Returns:
- A member substitution that stubs any interaction with a matched byte code element.
-
doStub
protected abstract MemberSubstitution.Substitution doStub()
Applies the stubbing for this instance.- Returns:
- A suitable substitution.
-
replaceWith
public MemberSubstitution replaceWith(java.lang.reflect.Field field)
Replaces any interaction with a matched byte code element by an interaction with the specified field. If a field is replacing a method or constructor invocation, it is treated as if it was a field getter or setter respectively.
A replacement can only be applied if the field is compatible to the original byte code element, i.e. consumes an instance of the declaring type if it is not
static
as an argument and consumes or produces an instance of the field's type.- Parameters:
field
- The field to access instead of interacting with any of the matched byte code elements.- Returns:
- A member substitution that replaces any matched byte code element with an access of the specified field.
-
replaceWith
public MemberSubstitution replaceWith(FieldDescription fieldDescription)
Replaces any interaction with a matched byte code element by an interaction with the specified field. If a field is replacing a method or constructor invocation, it is treated as if it was a field getter or setter respectively.
A replacement can only be applied if the field is compatible to the original byte code element, i.e. consumes an instance of the declaring type if it is not
static
as an argument and consumes or produces an instance of the field's type.- Parameters:
fieldDescription
- The field to access instead of interacting with any of the matched byte code elements.- Returns:
- A member substitution that replaces any matched byte code element with an access of the specified field.
-
doReplaceWith
protected abstract MemberSubstitution.Substitution doReplaceWith(FieldDescription fieldDescription)
Creates a substitution for replacing the byte code elements matched by this instance with an access of the specified field.- Parameters:
fieldDescription
- The field to access.- Returns:
- A suitable substitution.
-
replaceWith
public MemberSubstitution replaceWith(java.lang.reflect.Method method)
Replaces any interaction with a matched byte code element by an invocation of the specified method. If a method is replacing a field access, it is treated as if it was replacing an invocation of the field's getter or setter respectively.
A replacement can only be applied if the method is compatible to the original byte code element, i.e. consumes compatible arguments and returns a compatible value. If the method is not
static
, it is treated as ifthis
was an implicit first argument.- Parameters:
method
- The method to invoke instead of interacting with any of the matched byte code elements.- Returns:
- A member substitution that replaces any matched byte code element with an invocation of the specified method.
-
replaceWith
public MemberSubstitution replaceWith(MethodDescription methodDescription)
Replaces any interaction with a matched byte code element by an invocation of the specified method. If a method is replacing a field access, it is treated as if it was replacing an invocation of the field's getter or setter respectively.
A replacement can only be applied if the method is compatible to the original byte code element, i.e. consumes compatible arguments and returns a compatible value. If the method is not
static
, it is treated as ifthis
was an implicit first argument.Important: It is not allowed to specify a constructor or the static type initializer as a replacement.
- Parameters:
methodDescription
- The method to invoke instead of interacting with any of the matched byte code elements.- Returns:
- A member substitution that replaces any matched byte code element with an invocation of the specified method.
-
doReplaceWith
protected abstract MemberSubstitution.Substitution doReplaceWith(MethodDescription methodDescription)
Creates a substitution for replacing the byte code elements matched by this instance with an invocation of the specified method.- Parameters:
methodDescription
- The method to invoke.- Returns:
- A suitable substitution.
-
-