@SuppressWarnings({"unused", "UnusedAssignment"}) @Advice.OnMethodExit private static void enter(@Advice.This Object self, @Advice.Argument(0) Object other, @Advice.Return(readOnly = false) boolean equals, @Advice.Enter boolean skipped) { if (skipped) { equals = self == other; } } }
/** * {@inheritDoc} */ public MemberSubstitution replaceWith(Substitution.Factory substitutionFactory) { return new MemberSubstitution(methodGraphCompiler, typePoolResolver, strict, new Replacement.Factory.Compound( this.replacementFactory, Replacement.ForElementMatchers.Factory.ofField(matcher, matchRead, matchWrite, substitutionFactory))); } }
/** * {@inheritDoc} */ public MemberSubstitution replaceWith(Substitution.Factory substitutionFactory) { return new MemberSubstitution(methodGraphCompiler, typePoolResolver, strict, new Replacement.Factory.Compound( this.replacementFactory, Replacement.ForElementMatchers.Factory.ofMethod(matcher, includeVirtualCalls, includeSuperCalls, substitutionFactory))); } }
@SuppressWarnings({"unused", "UnusedAssignment"}) @Advice.OnMethodExit private static void exit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object returned, @Advice.Enter Callable<?> mocked) throws Throwable { if (mocked != null) { returned = mocked.call(); } }
/** * Binds the supplied annotation to the supplied type constant. * * @param type The type of the annotation being bound. * @param value The type constant to bind. * @param <T> The annotation type. * @return A new builder for an advice that considers the supplied annotation type during binding. */ public <T extends Annotation> WithCustomMapping bind(Class<T> type, TypeDescription value) { return bind(new OffsetMapping.ForStackManipulation.Factory<T>(type, value)); }
/** * Binds the supplied annotation to the supplied parameter's argument. The binding is declared read-only and * applies static typing. * * @param type The type of the annotation being bound. * @param parameterDescription The parameter for which to bind an argument. * @param <T> The annotation type. * @return A new builder for an advice that considers the supplied annotation type during binding. */ public <T extends Annotation> WithCustomMapping bind(Class<T> type, ParameterDescription parameterDescription) { return bind(new OffsetMapping.ForArgument.Resolved.Factory<T>(type, parameterDescription)); }
/** * Binds the supplied annotation to a type constant of the supplied value. Constants can be strings, method handles, method types * and any primitive or the value {@code null}. * * @param type The type of the annotation being bound. * @param value The value to bind to the annotation. * @param <T> The annotation type. * @return A new builder for an advice that considers the supplied annotation type during binding. */ public <T extends Annotation> WithCustomMapping bind(Class<T> type, Object value) { return bind(OffsetMapping.ForStackManipulation.Factory.of(type, value)); }
/** * Binds the supplied annotation to the annotation's property of the specified name. * * @param type The type of the annotation being bound. * @param property The name of the annotation property to be bound. * @param <T> The annotation type. * @return A new builder for an advice that considers the supplied annotation during binding. */ public <T extends Annotation> WithCustomMapping bindProperty(Class<T> type, String property) { return bind(OffsetMapping.ForStackManipulation.OfAnnotationProperty.of(type, property)); }
/** * Binds the supplied annotation to the annotation's property of the specified name. * * @param type The type of the annotation being bound. * @param offsetMapping The offset mapping being bound. * @param <T> The annotation type. * @return A new builder for an advice that considers the supplied annotation during binding. */ public <T extends Annotation> WithCustomMapping bind(Class<T> type, OffsetMapping offsetMapping) { return bind(new OffsetMapping.Factory.Simple<T>(type, offsetMapping)); }
/** * {@inheritDoc} */ public MemberSubstitution replaceWith(Substitution.Factory substitutionFactory) { return new MemberSubstitution(methodGraphCompiler, typePoolResolver, strict, new Replacement.Factory.Compound( this.replacementFactory, Replacement.ForElementMatchers.Factory.of(matcher, substitutionFactory))); } }
/** * {@inheritDoc} */ public Dispatcher.Resolved.ForMethodEnter asMethodEnter(List<? extends OffsetMapping.Factory<?>> userFactories, ClassReader classReader, Unresolved methodExit) { return Resolved.ForMethodEnter.of(adviceMethod, userFactories, methodExit.getAdviceType(), methodExit.isAlive()); }
/** * {@inheritDoc} */ public Substitution make(TypeDescription instrumentedType, MethodDescription instrumentedMethod, TypePool typePool) { return new ForMethodInvocation(instrumentedType, new MethodResolver.Simple(methodDescription)); } }
/** * {@inheritDoc} */ public Substitution make(TypeDescription instrumentedType, MethodDescription instrumentedMethod, TypePool typePool) { return new ForMethodInvocation(instrumentedType, new MethodResolver.Matching(instrumentedType, methodGraphCompiler, matcher)); } }
/** * {@inheritDoc} */ public Binding bind(FieldDescription.InDefinedShape fieldDescription, boolean writeAccess) { for (Replacement replacement : replacements) { Binding binding = replacement.bind(fieldDescription, writeAccess); if (binding.isBound()) { return binding; } } return Binding.Unresolved.INSTANCE; }
/** * 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. * * @param matcher A matcher for locating a field on the original interaction's receiver type. * @return A member substitution that replaces any matched byte code element with an access of the matched field. */ public MemberSubstitution replaceWithField(ElementMatcher<? super FieldDescription> matcher) { return replaceWith(new Substitution.ForFieldAccess.OfMatchedField(matcher)); }
/** * {@inheritDoc} */ public Substitution make(TypeDescription instrumentedType, MethodDescription instrumentedMethod, TypePool typePool) { return new ForFieldAccess(instrumentedType, new FieldResolver.ForElementMatcher(instrumentedType, matcher)); } }
@SuppressWarnings({"unused", "UnusedAssignment"}) @Advice.OnMethodExit private static void enter(@Advice.This Object self, @Advice.Return(readOnly = false) int hashCode, @Advice.Enter boolean skipped) { if (skipped) { hashCode = System.identityHashCode(self); } } }
/** * Binds the supplied annotation to the supplied enumeration constant. * * @param type The type of the annotation being bound. * @param value The enumeration constant to bind. * @param <T> The annotation type. * @return A new builder for an advice that considers the supplied annotation type during binding. */ public <T extends Annotation> WithCustomMapping bind(Class<T> type, EnumerationDescription value) { return bind(new OffsetMapping.ForStackManipulation.Factory<T>(type, value)); }
/** * {@inheritDoc} */ public Substitution make(TypeDescription instrumentedType, MethodDescription instrumentedMethod, TypePool typePool) { return new ForMethodInvocation(instrumentedType, new MethodResolver.Simple(instrumentedMethod)); } }
/** * Binds the supplied annotation to the annotation's property of the specified name. * * @param type The type of the annotation being bound. * @param stackManipulation The stack manipulation loading the bound value. * @param targetType The type of the loaded value. * @param <T> The annotation type. * @return A new builder for an advice that considers the supplied annotation during binding. */ public <T extends Annotation> WithCustomMapping bind(Class<T> type, StackManipulation stackManipulation, TypeDescription.Generic targetType) { return bind(new OffsetMapping.ForStackManipulation.Factory<T>(type, stackManipulation, targetType)); }