Class MemberSubstitution.WithoutSpecification
- Direct Known Subclasses:
MemberSubstitution.WithoutSpecification.ForMatchedByteCodeElement
,MemberSubstitution.WithoutSpecification.ForMatchedField
,MemberSubstitution.WithoutSpecification.ForMatchedMethod
- Enclosing class:
MemberSubstitution
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Describes a member substitution that requires a specification for how to replace a byte code element.static class
Describes a member substitution that requires a specification for how to replace a field.static class
Describes a member substitution that requires a specification for how to replace a method or constructor. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final MethodGraph.Compiler
The method graph compiler to use.protected final MemberSubstitution.Replacement.Factory
The replacement factory to use for creating substitutions.protected final boolean
true
if the method processing should be strict where an exception is raised if a member cannot be found.protected final MemberSubstitution.TypePoolResolver
The type pool resolver to use. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WithoutSpecification
(MethodGraph.Compiler methodGraphCompiler, MemberSubstitution.TypePoolResolver typePoolResolver, boolean strict, MemberSubstitution.Replacement.Factory replacementFactory) Creates a new member substitution that requires a specification for how to perform a substitution. -
Method Summary
Modifier and TypeMethodDescriptionreplaceWith
(Field field) Replaces any interaction with a matched byte code element by an interaction with the specified field.replaceWith
(Method method) Replaces any interaction with a matched byte code element by an invocation of the specified method.abstract MemberSubstitution
Replaces any interaction with the supplied substitution.replaceWith
(FieldDescription fieldDescription) Replaces any interaction with a matched byte code element by an interaction with the specified field.replaceWith
(MethodDescription methodDescription) Replaces any interaction with a matched byte code element by an invocation of the specified method.replaceWithChain
(List<? extends MemberSubstitution.Substitution.Chain.Step.Factory> steps) Replaces the matched byte code elements with a chain of substitutions that can operate on the same values as the substituted element.Replaces the matched byte code elements with a chain of substitutions that can operate on the same values as the substituted element.replaceWithConstant
(Object value) Replaces any interaction with a matched byte code element with the provided compile-time constant.replaceWithField
(ElementMatcher<? super FieldDescription> matcher) Replaces any interaction with a matched byte code element with a non-static field access on the first parameter of the matched element.Replaces any interaction with a matched byte code element with an invocation of the instrumented method.replaceWithMethod
(ElementMatcher<? super MethodDescription> matcher) Replaces any interaction with a matched byte code element with a non-static method access on the first parameter of the matched element.replaceWithMethod
(ElementMatcher<? super MethodDescription> matcher, MethodGraph.Compiler methodGraphCompiler) Replaces any interaction with a matched byte code element with a non-static method access on the first parameter of the matched element.stub()
Subs any interaction with a matched byte code element.
-
Field Details
-
methodGraphCompiler
The method graph compiler to use. -
typePoolResolver
The type pool resolver to use. -
strict
protected final boolean stricttrue
if the method processing should be strict where an exception is raised if a member cannot be found. -
replacementFactory
The replacement factory to use for creating substitutions.
-
-
Constructor Details
-
WithoutSpecification
protected WithoutSpecification(MethodGraph.Compiler methodGraphCompiler, MemberSubstitution.TypePoolResolver typePoolResolver, boolean strict, MemberSubstitution.Replacement.Factory replacementFactory) 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.replacementFactory
- The replacement factory to use for creating substitutions.
-
-
Method Details
-
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.
-
replaceWithConstant
Replaces any interaction with a matched byte code element with the provided compile-time constant.- Parameters:
value
- The compile-time constant to set.- Returns:
- A member substitution that replaces any interaction with the supplied compile-time constant.
-
replaceWith
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
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.
-
replaceWithField
Replaces any interaction with a matched byte code element with a non-static field access on the first parameter of the matched element. When matching a non-static field access or method invocation, the substituted field is located on the same receiver type as the original access. For static access, the first argument is used as a receiver.- Parameters:
matcher
- A matcher for locating a field on the original interaction's receiver type.- Returns:
- A member substitution that replaces any matched byte code element with an access of the matched field.
-
replaceWith
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
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.
-
replaceWithMethod
Replaces any interaction with a matched byte code element with a non-static method access on the first parameter of the matched element. When matching a non-static field access or method invocation, the substituted method is located on the same receiver type as the original access. For static access, the first argument is used as a receiver.- Parameters:
matcher
- A matcher for locating a method on the original interaction's receiver type.- Returns:
- A member substitution that replaces any matched byte code element with an access of the matched method.
-
replaceWithMethod
public MemberSubstitution replaceWithMethod(ElementMatcher<? super MethodDescription> matcher, MethodGraph.Compiler methodGraphCompiler) Replaces any interaction with a matched byte code element with a non-static method access on the first parameter of the matched element. When matching a non-static field access or method invocation, the substituted method is located on the same receiver type as the original access. For static access, the first argument is used as a receiver.- Parameters:
matcher
- A matcher for locating a method on the original interaction's receiver type.methodGraphCompiler
- The method graph compiler to use for locating a method.- Returns:
- A member substitution that replaces any matched byte code element with an access of the matched method.
-
replaceWithInstrumentedMethod
Replaces any interaction with a matched byte code element with an invocation of the instrumented method. This can cause an infinite recursive call if the arguments to the method are not altered.- Returns:
- A member substitution that replaces any matched byte code element with an invocation of the instrumented method.
-
replaceWithChain
public MemberSubstitution replaceWithChain(MemberSubstitution.Substitution.Chain.Step.Factory... step) Replaces the matched byte code elements with a chain of substitutions that can operate on the same values as the substituted element. This is a shortcut for creating a substitution chain with a default assigner.- Parameters:
step
- The steps to apply for a substitution.- Returns:
- A member substitution that replaces any matched byte code element with the provided substitution chain.
-
replaceWithChain
public MemberSubstitution replaceWithChain(List<? extends MemberSubstitution.Substitution.Chain.Step.Factory> steps) Replaces the matched byte code elements with a chain of substitutions that can operate on the same values as the substituted element. This is a shortcut for creating a substitution chain with a default assigner.- Parameters:
steps
- The steps to apply for a substitution.- Returns:
- A member substitution that replaces any matched byte code element with the provided substitution chain.
-
replaceWith
Replaces any interaction with the supplied substitution.- Parameters:
factory
- The substitution factory to use for creating the applied substitution.- Returns:
- A member substitution that replaces any matched byte code element with the supplied substitution.
-